From 18965dcdacfc793fc6eeaa72b56b035f38785ba8 Mon Sep 17 00:00:00 2001 From: Michael Poluektov Date: Mon, 19 Aug 2024 11:03:55 +0100 Subject: [PATCH] delete keys if envvars are set --- backend/apps/ollama/main.py | 9 ++++----- backend/main.py | 6 +++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/backend/apps/ollama/main.py b/backend/apps/ollama/main.py index 810a05999..37b72a105 100644 --- a/backend/apps/ollama/main.py +++ b/backend/apps/ollama/main.py @@ -732,11 +732,10 @@ async def generate_chat_completion( ): log.debug(f"{form_data.model_dump_json(exclude_none=True).encode()}=") - payload = { - **form_data.model_dump(exclude_none=True, exclude=["metadata"]), - } - if "metadata" in payload: - del payload["metadata"] + payload = {**form_data.model_dump(exclude_none=True)} + for key in ["metadata", "files", "tool_ids"]: + if key in payload: + del payload[key] model_id = form_data.model model_info = Models.get_model_by_id(model_id) diff --git a/backend/main.py b/backend/main.py index dbe9d30bf..49984e9bc 100644 --- a/backend/main.py +++ b/backend/main.py @@ -453,7 +453,7 @@ async def chat_completion_tools_handler( contexts.append(tool_output) except Exception as e: - print(f"Error: {e}") + log.exception(f"Error: {e}") content = None log.debug(f"tool_contexts: {contexts}") @@ -997,6 +997,10 @@ async def generate_chat_completions(form_data: dict, user=Depends(get_verified_u if model.get("pipe"): return await generate_function_chat_completion(form_data, user=user) + + for key in ["tool_ids", "files"]: + if key in form_data: + del form_data[key] if model["owned_by"] == "ollama": return await generate_ollama_chat_completion(form_data, user=user) else: