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

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

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

@ -3,7 +3,6 @@ import time
import traceback import traceback
from typing import Optional, Tuple, TypedDict from typing import Optional, Tuple, TypedDict
import sqlalchemy
from api.model.chat_complete.bot_persona import BotPersonaHelper from api.model.chat_complete.bot_persona import BotPersonaHelper
from api.model.chat_complete.conversation import ( from api.model.chat_complete.conversation import (
ConversationChunkHelper, ConversationChunkHelper,
@ -281,7 +280,7 @@ class ChatCompleteService:
message_log = [] message_log = []
if self.conversation_chunk is not None: if self.conversation_chunk is not None:
for message in self.conversation_chunk.message_data: for message in self.conversation_chunk.message_data:
if message["role"] in ["user", "assistant"]: if message.get("role") in ["user", "assistant"]:
message_log.append( message_log.append(
{ {
"role": message["role"], "role": message["role"],
@ -387,7 +386,7 @@ class ChatCompleteService:
return False return False
for i in range(len(self.conversation_chunk.message_data) - 1, -1, -1): 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 self.conversation_chunk.message_data[i]["point_cost"] = point_cost
flag_modified(self.conversation_chunk, "message_data") flag_modified(self.conversation_chunk, "message_data")
await self.conversation_chunk_helper.update(self.conversation_chunk) await self.conversation_chunk_helper.update(self.conversation_chunk)
@ -399,9 +398,11 @@ class ChatCompleteService:
bot_name = Config.get("chatcomplete.bot_name", "ChatComplete", str) bot_name = Config.get("chatcomplete.bot_name", "ChatComplete", str)
for message_data in message_log_list: for message_data in message_log_list:
if message_data["role"] == "summary": if "content" in message_data:
msg_role = message_data.get("role")
if msg_role == "summary":
chat_log.append(message_data["content"]) chat_log.append(message_data["content"])
elif message_data["role"] == "assistant": elif msg_role == "assistant":
chat_log.append( chat_log.append(
f'{bot_name}: {message_data["content"]}' f'{bot_name}: {message_data["content"]}'
) )
@ -426,11 +427,15 @@ class ChatCompleteService:
bot_name = Config.get("chatcomplete.bot_name", "ChatComplete", str) bot_name = Config.get("chatcomplete.bot_name", "ChatComplete", str)
for message_data in message_log_list: for message_data in message_log_list:
if message_data["role"] == "assistant": 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( chat_log.append(
f'{bot_name}: {message_data["content"]}' f'{bot_name}: {message_data["content"]}'
) )
elif message_data["role"] == "user": else:
chat_log.append(f'User: {message_data["content"]}') chat_log.append(f'User: {message_data["content"]}')
chat_log_str = "\n".join(chat_log) 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: async with session.post(self.api_url, data=post_data, proxy=self.request_proxy) as resp:
data = await resp.json() data = await resp.json()
if "error" in data: if "error" in data:
print(data)
raise MediaWikiApiException(data["error"]["info"], data["error"]["code"]) raise MediaWikiApiException(data["error"]["info"], data["error"]["code"])
point_cost = int(data["aitoolboxbot"]["reportusage"]["pointcost"] or 0) point_cost = int(data["aitoolboxbot"]["reportusage"]["pointcost"] or 0)

Loading…
Cancel
Save