Skip to content

Commit

Permalink
FEAT: restore embedder settings if error occurs
Browse files Browse the repository at this point in the history
- embedder.py: if new embedder settings generate an error, the
previous settings are restored, if any

relates to issue #554
  • Loading branch information
kodaline committed Nov 11, 2023
1 parent 44c5a2a commit d51f609
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions core/cat/routes/embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ def upsert_embedder_setting(
}
)

# get selected config if any
selected = crud.get_setting_by_name(name=EMBEDDER_SELECTED_NAME)
if selected is not None:
current_settings = crud.get_setting_by_name(name=selected["value"]["name"])

# create the setting and upsert it
final_setting = crud.upsert_setting_by_name(
models.Setting(name=languageEmbedderName, category=EMBEDDER_CATEGORY, value=payload)
Expand All @@ -129,6 +134,19 @@ def upsert_embedder_setting(
log.error(e)
crud.delete_settings_by_category(category=EMBEDDER_SELECTED_CATEGORY)
crud.delete_settings_by_category(category=EMBEDDER_CATEGORY)

# if a selected config is present, restore it
if selected is not None:
languageEmbedderName = selected["value"]["name"]
crud.upsert_setting_by_name(
models.Setting(name=languageEmbedderName, category=EMBEDDER_CATEGORY, value=current_settings["value"])
)
crud.upsert_setting_by_name(
models.Setting(name=EMBEDDER_SELECTED_NAME, category=EMBEDDER_SELECTED_CATEGORY, value={"name":languageEmbedderName})
)
# reload llm and embedder of the cat
ccat.load_natural_language()

raise HTTPException(
status_code=400,
detail={
Expand Down

0 comments on commit d51f609

Please sign in to comment.