mirror of
https://github.com/open-webui/open-webui
synced 2024-12-29 15:25:29 +00:00
refac
This commit is contained in:
parent
c3e8cd03b2
commit
4c989808d6
@ -601,69 +601,78 @@ async def process_chat_response(request, response, user, events, metadata, tasks
|
|||||||
if message:
|
if message:
|
||||||
messages = get_message_list(message_map, message.get("id"))
|
messages = get_message_list(message_map, message.get("id"))
|
||||||
|
|
||||||
if TASKS.TITLE_GENERATION in tasks:
|
if tasks:
|
||||||
res = await generate_title(
|
if (
|
||||||
request,
|
TASKS.TITLE_GENERATION in tasks
|
||||||
{
|
and tasks[TASKS.TITLE_GENERATION]
|
||||||
"model": message["model"],
|
):
|
||||||
"messages": messages,
|
res = await generate_title(
|
||||||
"chat_id": metadata["chat_id"],
|
request,
|
||||||
},
|
|
||||||
user,
|
|
||||||
)
|
|
||||||
|
|
||||||
if res:
|
|
||||||
title = (
|
|
||||||
res.get("choices", [])[0]
|
|
||||||
.get("message", {})
|
|
||||||
.get("content", message.get("content", "New Chat"))
|
|
||||||
)
|
|
||||||
|
|
||||||
Chats.update_chat_title_by_id(metadata["chat_id"], title)
|
|
||||||
|
|
||||||
await event_emitter(
|
|
||||||
{
|
{
|
||||||
"type": "chat:title",
|
"model": message["model"],
|
||||||
"data": title,
|
"messages": messages,
|
||||||
}
|
"chat_id": metadata["chat_id"],
|
||||||
|
},
|
||||||
|
user,
|
||||||
)
|
)
|
||||||
|
|
||||||
if TASKS.TAGS_GENERATION in tasks:
|
if res:
|
||||||
res = await generate_chat_tags(
|
title = (
|
||||||
request,
|
res.get("choices", [])[0]
|
||||||
{
|
.get("message", {})
|
||||||
"model": message["model"],
|
.get("content", message.get("content", "New Chat"))
|
||||||
"messages": messages,
|
)
|
||||||
"chat_id": metadata["chat_id"],
|
|
||||||
},
|
|
||||||
user,
|
|
||||||
)
|
|
||||||
|
|
||||||
if res:
|
Chats.update_chat_title_by_id(
|
||||||
tags_string = (
|
metadata["chat_id"], title
|
||||||
res.get("choices", [])[0]
|
|
||||||
.get("message", {})
|
|
||||||
.get("content", "")
|
|
||||||
)
|
|
||||||
|
|
||||||
tags_string = tags_string[
|
|
||||||
tags_string.find("{") : tags_string.rfind("}") + 1
|
|
||||||
]
|
|
||||||
|
|
||||||
try:
|
|
||||||
tags = json.loads(tags_string).get("tags", [])
|
|
||||||
Chats.update_chat_tags_by_id(
|
|
||||||
metadata["chat_id"], tags, user
|
|
||||||
)
|
)
|
||||||
|
|
||||||
await event_emitter(
|
await event_emitter(
|
||||||
{
|
{
|
||||||
"type": "chat:tags",
|
"type": "chat:title",
|
||||||
"data": tags,
|
"data": title,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
except Exception as e:
|
|
||||||
print(f"Error: {e}")
|
if (
|
||||||
|
TASKS.TAGS_GENERATION in tasks
|
||||||
|
and tasks[TASKS.TAGS_GENERATION]
|
||||||
|
):
|
||||||
|
res = await generate_chat_tags(
|
||||||
|
request,
|
||||||
|
{
|
||||||
|
"model": message["model"],
|
||||||
|
"messages": messages,
|
||||||
|
"chat_id": metadata["chat_id"],
|
||||||
|
},
|
||||||
|
user,
|
||||||
|
)
|
||||||
|
|
||||||
|
if res:
|
||||||
|
tags_string = (
|
||||||
|
res.get("choices", [])[0]
|
||||||
|
.get("message", {})
|
||||||
|
.get("content", "")
|
||||||
|
)
|
||||||
|
|
||||||
|
tags_string = tags_string[
|
||||||
|
tags_string.find("{") : tags_string.rfind("}") + 1
|
||||||
|
]
|
||||||
|
|
||||||
|
try:
|
||||||
|
tags = json.loads(tags_string).get("tags", [])
|
||||||
|
Chats.update_chat_tags_by_id(
|
||||||
|
metadata["chat_id"], tags, user
|
||||||
|
)
|
||||||
|
|
||||||
|
await event_emitter(
|
||||||
|
{
|
||||||
|
"type": "chat:tags",
|
||||||
|
"data": tags,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error: {e}")
|
||||||
|
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
print("Task was cancelled!")
|
print("Task was cancelled!")
|
||||||
|
Loading…
Reference in New Issue
Block a user