|
|
|
@ -3,7 +3,6 @@ import time
|
|
|
|
|
import traceback
|
|
|
|
|
from typing import Optional, Tuple, TypedDict
|
|
|
|
|
|
|
|
|
|
import sqlalchemy
|
|
|
|
|
from api.model.chat_complete.bot_persona import BotPersonaHelper
|
|
|
|
|
from api.model.chat_complete.conversation import (
|
|
|
|
|
ConversationChunkHelper,
|
|
|
|
@ -281,7 +280,7 @@ class ChatCompleteService:
|
|
|
|
|
message_log = []
|
|
|
|
|
if self.conversation_chunk is not None:
|
|
|
|
|
for message in self.conversation_chunk.message_data:
|
|
|
|
|
if message["role"] in ["user", "assistant"]:
|
|
|
|
|
if message.get("role") in ["user", "assistant"]:
|
|
|
|
|
message_log.append(
|
|
|
|
|
{
|
|
|
|
|
"role": message["role"],
|
|
|
|
@ -387,7 +386,7 @@ class ChatCompleteService:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
for i in range(len(self.conversation_chunk.message_data) - 1, -1, -1):
|
|
|
|
|
if self.conversation_chunk.message_data[i]["role"] == "assistant":
|
|
|
|
|
if self.conversation_chunk.message_data[i].get("role") == "assistant":
|
|
|
|
|
self.conversation_chunk.message_data[i]["point_cost"] = point_cost
|
|
|
|
|
flag_modified(self.conversation_chunk, "message_data")
|
|
|
|
|
await self.conversation_chunk_helper.update(self.conversation_chunk)
|
|
|
|
@ -399,14 +398,16 @@ class ChatCompleteService:
|
|
|
|
|
bot_name = Config.get("chatcomplete.bot_name", "ChatComplete", str)
|
|
|
|
|
|
|
|
|
|
for message_data in message_log_list:
|
|
|
|
|
if message_data["role"] == "summary":
|
|
|
|
|
chat_log.append(message_data["content"])
|
|
|
|
|
elif message_data["role"] == "assistant":
|
|
|
|
|
chat_log.append(
|
|
|
|
|
f'{bot_name}: {message_data["content"]}'
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
chat_log.append(f'User: {message_data["content"]}')
|
|
|
|
|
if "content" in message_data:
|
|
|
|
|
msg_role = message_data.get("role")
|
|
|
|
|
if msg_role == "summary":
|
|
|
|
|
chat_log.append(message_data["content"])
|
|
|
|
|
elif msg_role == "assistant":
|
|
|
|
|
chat_log.append(
|
|
|
|
|
f'{bot_name}: {message_data["content"]}'
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
chat_log.append(f'User: {message_data["content"]}')
|
|
|
|
|
|
|
|
|
|
chat_log_str = "\n".join(chat_log)
|
|
|
|
|
|
|
|
|
@ -426,12 +427,16 @@ class ChatCompleteService:
|
|
|
|
|
bot_name = Config.get("chatcomplete.bot_name", "ChatComplete", str)
|
|
|
|
|
|
|
|
|
|
for message_data in message_log_list:
|
|
|
|
|
if message_data["role"] == "assistant":
|
|
|
|
|
chat_log.append(
|
|
|
|
|
f'{bot_name}: {message_data["content"]}'
|
|
|
|
|
)
|
|
|
|
|
elif message_data["role"] == "user":
|
|
|
|
|
chat_log.append(f'User: {message_data["content"]}')
|
|
|
|
|
if "content" in message_data:
|
|
|
|
|
msg_role = message_data.get("role")
|
|
|
|
|
if msg_role == "summary":
|
|
|
|
|
chat_log.append(message_data["content"])
|
|
|
|
|
elif msg_role == "assistant":
|
|
|
|
|
chat_log.append(
|
|
|
|
|
f'{bot_name}: {message_data["content"]}'
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
chat_log.append(f'User: {message_data["content"]}')
|
|
|
|
|
|
|
|
|
|
chat_log_str = "\n".join(chat_log)
|
|
|
|
|
|
|
|
|
|