This commit is contained in:
Timothy Jaeryang Baek 2024-12-24 19:34:56 -07:00
parent e51722348a
commit cd86161f33
2 changed files with 25 additions and 19 deletions

View File

@ -742,8 +742,6 @@ async def process_chat_payload(request, form_data, metadata, user, model):
} }
) )
print(f"form_data, events")
return form_data, events return form_data, events
@ -810,22 +808,36 @@ async def process_chat_response(request, response, user, events, metadata, tasks
try: try:
data = json.loads(data) data = json.loads(data)
value = (
data.get("choices", [])[0].get("delta", {}).get("content")
)
if value: if "selected_model_id" in data:
content = f"{content}{value}"
# Save message in the database
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"],
{ {
"content": content, "selectedModelId": data["selected_model_id"],
}, },
) )
else:
value = (
data.get("choices", [])[0]
.get("delta", {})
.get("content")
)
if value:
content = f"{content}{value}"
# Save message in the database
Chats.upsert_message_to_chat_by_id_and_message_id(
metadata["chat_id"],
metadata["message_id"],
{
"content": content,
},
)
except Exception as e: except Exception as e:
done = "data: [DONE]" in line done = "data: [DONE]" in line
title = Chats.get_chat_title_by_id(metadata["chat_id"]) title = Chats.get_chat_title_by_id(metadata["chat_id"])

View File

@ -1052,7 +1052,7 @@
}; };
const chatCompletionEventHandler = async (data, message, chatId) => { const chatCompletionEventHandler = async (data, message, chatId) => {
const { id, done, choices, sources, selectedModelId, error, usage } = data; const { id, done, choices, sources, selected_model_id, error, usage } = data;
if (error) { if (error) {
await handleOpenAIError(error, message); await handleOpenAIError(error, message);
@ -1060,12 +1060,6 @@
if (sources) { if (sources) {
message.sources = sources; message.sources = sources;
// Only remove status if it was initially set
if (model?.info?.meta?.knowledge ?? false) {
message.statusHistory = message.statusHistory.filter(
(status) => status.action !== 'knowledge_search'
);
}
} }
if (choices) { if (choices) {
@ -1103,8 +1097,8 @@
} }
} }
if (selectedModelId) { if (selected_model_id) {
message.selectedModelId = selectedModelId; message.selectedModelId = selected_model_id;
message.arena = true; message.arena = true;
} }