mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 20:35:19 +00:00
refac
This commit is contained in:
parent
20101579e0
commit
e7d9755d97
1 changed files with 34 additions and 22 deletions
|
|
@ -1321,7 +1321,10 @@ async def get_models(
|
||||||
model_order_dict = {model_id: i for i, model_id in enumerate(model_order_list)}
|
model_order_dict = {model_id: i for i, model_id in enumerate(model_order_list)}
|
||||||
# Sort models by order list priority, with fallback for those not in the list
|
# Sort models by order list priority, with fallback for those not in the list
|
||||||
models.sort(
|
models.sort(
|
||||||
key=lambda x: (model_order_dict.get(x["id"], float("inf")), x.get("name"))
|
key=lambda model: (
|
||||||
|
model_order_dict.get(model.get("id"), float("inf")),
|
||||||
|
model.get("name"),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Filter out models that the user does not have access to
|
# Filter out models that the user does not have access to
|
||||||
|
|
@ -1467,6 +1470,7 @@ async def chat_completion(
|
||||||
log.debug(f"Error processing chat payload: {e}")
|
log.debug(f"Error processing chat payload: {e}")
|
||||||
if metadata.get("chat_id") and metadata.get("message_id"):
|
if metadata.get("chat_id") and metadata.get("message_id"):
|
||||||
# Update the chat message with the error
|
# Update the chat message with the error
|
||||||
|
try:
|
||||||
Chats.upsert_message_to_chat_by_id_and_message_id(
|
Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||||
metadata["chat_id"],
|
metadata["chat_id"],
|
||||||
metadata["message_id"],
|
metadata["message_id"],
|
||||||
|
|
@ -1474,6 +1478,8 @@ async def chat_completion(
|
||||||
"error": {"content": str(e)},
|
"error": {"content": str(e)},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
|
@ -1483,6 +1489,7 @@ async def chat_completion(
|
||||||
try:
|
try:
|
||||||
response = await chat_completion_handler(request, form_data, user)
|
response = await chat_completion_handler(request, form_data, user)
|
||||||
if metadata.get("chat_id") and metadata.get("message_id"):
|
if metadata.get("chat_id") and metadata.get("message_id"):
|
||||||
|
try:
|
||||||
Chats.upsert_message_to_chat_by_id_and_message_id(
|
Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||||
metadata["chat_id"],
|
metadata["chat_id"],
|
||||||
metadata["message_id"],
|
metadata["message_id"],
|
||||||
|
|
@ -1490,6 +1497,8 @@ async def chat_completion(
|
||||||
"model": model_id,
|
"model": model_id,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
return await process_chat_response(
|
return await process_chat_response(
|
||||||
request, response, form_data, user, metadata, model, events, tasks
|
request, response, form_data, user, metadata, model, events, tasks
|
||||||
|
|
@ -1498,6 +1507,7 @@ async def chat_completion(
|
||||||
log.debug(f"Error in chat completion: {e}")
|
log.debug(f"Error in chat completion: {e}")
|
||||||
if metadata.get("chat_id") and metadata.get("message_id"):
|
if metadata.get("chat_id") and metadata.get("message_id"):
|
||||||
# Update the chat message with the error
|
# Update the chat message with the error
|
||||||
|
try:
|
||||||
Chats.upsert_message_to_chat_by_id_and_message_id(
|
Chats.upsert_message_to_chat_by_id_and_message_id(
|
||||||
metadata["chat_id"],
|
metadata["chat_id"],
|
||||||
metadata["message_id"],
|
metadata["message_id"],
|
||||||
|
|
@ -1505,6 +1515,8 @@ async def chat_completion(
|
||||||
"error": {"content": str(e)},
|
"error": {"content": str(e)},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue