修复运行中出现的几个错误

master
落雨楓 2 years ago
parent 9abc94fe04
commit 10de406b2d

@ -535,7 +535,7 @@ class ChatComplete:
try:
await ws.send_str("+" + delta_message)
except ConnectionResetError:
on_closed()
await on_closed()
async def on_finished(result: ChatCompleteServiceResponse):
try:
@ -554,7 +554,7 @@ class ChatComplete:
await ws.close()
except ConnectionResetError:
on_closed()
await on_closed()
async def on_error(err: Exception):
try:
@ -570,7 +570,7 @@ class ChatComplete:
await ws.close()
except ConnectionResetError:
on_closed()
await on_closed()
task.on_message.append(on_message)
task.on_finished.append(on_finished)
@ -587,7 +587,7 @@ class ChatComplete:
while True:
current_time = time.time()
if ws.closed or task.is_finished:
on_closed()
await on_closed()
break
if current_time - last_heartbeat >= 15:
@ -595,6 +595,6 @@ class ChatComplete:
await ws.ping('{"event":"ping"}'.encode('utf-8'))
last_heartbeat = current_time
except ConnectionResetError:
on_closed()
await on_closed()
break
await asyncio.sleep(0.1)

@ -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)

@ -286,7 +286,6 @@ class MediaWikiApi:
async with session.post(self.api_url, data=post_data, proxy=self.request_proxy) as resp:
data = await resp.json()
if "error" in data:
print(data)
raise MediaWikiApiException(data["error"]["info"], data["error"]["code"])
point_cost = int(data["aitoolboxbot"]["reportusage"]["pointcost"] or 0)

Loading…
Cancel
Save