This commit is contained in:
Timothy J. Baek 2024-06-12 13:34:34 -07:00
parent c6c0bc19d8
commit e82027310d

View File

@ -196,7 +196,11 @@ async def get_function_call_response(messages, tool_id, template, task_model_id,
"stream": False, "stream": False,
} }
payload = filter_pipeline(payload, user) try:
payload = filter_pipeline(payload, user)
except Exception as e:
raise e
model = app.state.MODELS[task_model_id] model = app.state.MODELS[task_model_id]
response = None response = None
@ -326,16 +330,19 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
print(data["tool_ids"]) print(data["tool_ids"])
for tool_id in data["tool_ids"]: for tool_id in data["tool_ids"]:
print(tool_id) print(tool_id)
response = await get_function_call_response( try:
messages=data["messages"], response = await get_function_call_response(
tool_id=tool_id, messages=data["messages"],
template=app.state.config.TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE, tool_id=tool_id,
task_model_id=task_model_id, template=app.state.config.TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE,
user=user, task_model_id=task_model_id,
) user=user,
)
if response: if response:
context += ("\n" if context != "" else "") + response context += ("\n" if context != "" else "") + response
except Exception as e:
print(f"Error: {e}")
del data["tool_ids"] del data["tool_ids"]
print(f"tool_context: {context}") print(f"tool_context: {context}")
@ -767,7 +774,14 @@ async def generate_title(form_data: dict, user=Depends(get_verified_user)):
} }
print(payload) print(payload)
payload = filter_pipeline(payload, user)
try:
payload = filter_pipeline(payload, user)
except Exception as e:
return JSONResponse(
status_code=e.args[0],
content={"detail": e.args[1]},
)
if model["owned_by"] == "ollama": if model["owned_by"] == "ollama":
return await generate_ollama_chat_completion( return await generate_ollama_chat_completion(
@ -824,7 +838,14 @@ async def generate_search_query(form_data: dict, user=Depends(get_verified_user)
} }
print(payload) print(payload)
payload = filter_pipeline(payload, user)
try:
payload = filter_pipeline(payload, user)
except Exception as e:
return JSONResponse(
status_code=e.args[0],
content={"detail": e.args[1]},
)
if model["owned_by"] == "ollama": if model["owned_by"] == "ollama":
return await generate_ollama_chat_completion( return await generate_ollama_chat_completion(
@ -861,9 +882,16 @@ async def get_tools_function_calling(form_data: dict, user=Depends(get_verified_
print(model_id) print(model_id)
template = app.state.config.TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE template = app.state.config.TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE
return await get_function_call_response( try:
form_data["messages"], form_data["tool_id"], template, model_id, user context = await get_function_call_response(
) form_data["messages"], form_data["tool_id"], template, model_id, user
)
return context
except Exception as e:
return JSONResponse(
status_code=e.args[0],
content={"detail": e.args[1]},
)
@app.post("/api/chat/completions") @app.post("/api/chat/completions")