remove unnecessary nesting, remove unused endpoint

This commit is contained in:
Michael Poluektov 2024-08-10 11:58:18 +01:00
parent c8badfe21f
commit 3befadb29f

View File

@ -532,39 +532,42 @@ async def chat_completion_tools_handler(body, user, __event_emitter__, __event_c
task_model_id = get_task_model_id(body["model"]) task_model_id = get_task_model_id(body["model"])
# If tool_ids field is present, call the functions # If tool_ids field is present, call the functions
if "tool_ids" in body: if "tool_ids" not in body:
print(body["tool_ids"]) return body, {}
for tool_id in body["tool_ids"]:
print(tool_id)
try:
response, citation, file_handler = await get_function_call_response(
messages=body["messages"],
files=body.get("files", []),
tool_id=tool_id,
template=app.state.config.TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE,
task_model_id=task_model_id,
user=user,
__event_emitter__=__event_emitter__,
__event_call__=__event_call__,
)
print(file_handler) print(body["tool_ids"])
if isinstance(response, str): for tool_id in body["tool_ids"]:
contexts.append(response) print(tool_id)
try:
response, citation, file_handler = await get_function_call_response(
messages=body["messages"],
files=body.get("files", []),
tool_id=tool_id,
template=app.state.config.TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE,
task_model_id=task_model_id,
user=user,
__event_emitter__=__event_emitter__,
__event_call__=__event_call__,
)
if citation: print(file_handler)
if citations is None: if isinstance(response, str):
citations = [citation] contexts.append(response)
else:
citations.append(citation)
if file_handler: if citation:
skip_files = True if citations is None:
citations = [citation]
else:
citations.append(citation)
except Exception as e: if file_handler:
print(f"Error: {e}") skip_files = True
del body["tool_ids"]
print(f"tool_contexts: {contexts}") except Exception as e:
print(f"Error: {e}")
del body["tool_ids"]
print(f"tool_contexts: {contexts}")
if skip_files: if skip_files:
if "files" in body: if "files" in body:
@ -1610,41 +1613,6 @@ Message: """{{prompt}}"""
return await generate_chat_completions(form_data=payload, user=user) return await generate_chat_completions(form_data=payload, user=user)
@app.post("/api/task/tools/completions")
async def get_tools_function_calling(form_data: dict, user=Depends(get_verified_user)):
print("get_tools_function_calling")
model_id = form_data["model"]
if model_id not in app.state.MODELS:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Model not found",
)
# Check if the user has a custom task model
# If the user has a custom task model, use that model
model_id = get_task_model_id(model_id)
print(model_id)
template = app.state.config.TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE
try:
context, _, _ = await get_function_call_response(
form_data["messages"],
form_data.get("files", []),
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]},
)
################################## ##################################
# #
# Pipelines Endpoints # Pipelines Endpoints