lint: fix

This commit is contained in:
csunny
2023-05-25 20:39:04 +08:00
parent 4040e1592a
commit e95696c23d
23 changed files with 277 additions and 173 deletions

View File

@@ -9,12 +9,20 @@ from typing import (
List,
)
from pilot.scene.base_message import BaseMessage, AIMessage, HumanMessage, SystemMessage, ViewMessage, messages_to_dict, messages_from_dict
from pilot.scene.base_message import (
BaseMessage,
AIMessage,
HumanMessage,
SystemMessage,
ViewMessage,
messages_to_dict,
messages_from_dict,
)
class OnceConversation:
"""
All the information of a conversation, the current single service in memory, can expand cache and database support distributed services
All the information of a conversation, the current single service in memory, can expand cache and database support distributed services
"""
def __init__(self):
@@ -26,7 +34,9 @@ class OnceConversation:
def add_user_message(self, message: str) -> None:
"""Add a user message to the store"""
has_message = any(isinstance(instance, HumanMessage) for instance in self.messages)
has_message = any(
isinstance(instance, HumanMessage) for instance in self.messages
)
if has_message:
raise ValueError("Already Have Human message")
self.messages.append(HumanMessage(content=message))
@@ -38,6 +48,7 @@ class OnceConversation:
raise ValueError("Already Have Ai message")
self.messages.append(AIMessage(content=message))
""" """
def add_view_message(self, message: str) -> None:
"""Add an AI message to the store"""
@@ -50,7 +61,7 @@ class OnceConversation:
def set_start_time(self, datatime: datetime):
dt_str = datatime.strftime("%Y-%m-%d %H:%M:%S")
self.start_date = dt_str;
self.start_date = dt_str
def clear(self) -> None:
"""Remove all messages from the store"""
@@ -71,7 +82,7 @@ def _conversation_to_dic(once: OnceConversation) -> dict:
"start_date": start_str,
"cost": once.cost if once.cost else 0,
"tokens": once.tokens if once.tokens else 0,
"messages": messages_to_dict(once.messages)
"messages": messages_to_dict(once.messages),
}
@@ -81,10 +92,10 @@ def conversations_to_dict(conversations: List[OnceConversation]) -> List[dict]:
def conversation_from_dict(once: dict) -> OnceConversation:
conversation = OnceConversation()
conversation.cost = once.get('cost', 0)
conversation.tokens = once.get('tokens', 0)
conversation.start_date = once.get('start_date', '')
conversation.chat_order = int(once.get('chat_order'))
print(once.get('messages'))
conversation.messages = messages_from_dict(once.get('messages', []))
conversation.cost = once.get("cost", 0)
conversation.tokens = once.get("tokens", 0)
conversation.start_date = once.get("start_date", "")
conversation.chat_order = int(once.get("chat_order"))
print(once.get("messages"))
conversation.messages = messages_from_dict(once.get("messages", []))
return conversation