Implemented a new multi-scenario dialogue architecture

This commit is contained in:
yhjun1026 2023-05-31 16:26:47 +08:00
parent 06bc4452d4
commit 3a46dfd3c2
4 changed files with 42 additions and 7 deletions

View File

@ -108,8 +108,8 @@ class Conversation:
conv_default = Conversation(
system = None,
roles=("human", "ai"),
messages= (),
offset=2,
messages=[],
offset=0,
sep_style=SeparatorStyle.SINGLE,
sep="###",
)

View File

@ -0,0 +1,33 @@
from typing import List
import json
import os
import datetime
from pilot.memory.chat_history.base import BaseChatHistoryMemory
from pathlib import Path
from pilot.configs.config import Config
from pilot.scene.message import (
OnceConversation,
conversation_from_dict,
conversations_to_dict,
)
CFG = Config()
class MemHistoryMemory(BaseChatHistoryMemory):
histroies_map = {}
def __init__(self, chat_session_id: str):
self.chat_seesion_id = chat_session_id
self.histroies_map.update({chat_session_id: []})
def messages(self) -> List[OnceConversation]:
return self.histroies_map.get(self.chat_seesion_id)
def append(self, once_message: OnceConversation) -> None:
self.histroies_map.get(self.chat_seesion_id).append(once_message)
def clear(self) -> None:
self.histroies_map.pop(self.chat_seesion_id)

View File

@ -23,6 +23,7 @@ from pilot.scene.message import OnceConversation
from pilot.prompts.prompt_new import PromptTemplate
from pilot.memory.chat_history.base import BaseChatHistoryMemory
from pilot.memory.chat_history.file_history import FileHistoryMemory
from pilot.memory.chat_history.mem_history import MemHistoryMemory
from pilot.configs.model_config import LOGDIR, DATASETS_DIR
from pilot.utils import (
@ -61,7 +62,10 @@ class BaseChat(ABC):
self.chat_mode = chat_mode
self.current_user_input: str = current_user_input
self.llm_model = CFG.LLM_MODEL
### TODO
### can configurable storage methods
# self.memory = MemHistoryMemory(chat_session_id)
## TEST
self.memory = FileHistoryMemory(chat_session_id)
### load prompt template
self.prompt_template: PromptTemplate = CFG.prompt_templates[self.chat_mode.value]

View File

@ -14,14 +14,12 @@ PROMPT_SCENE_DEFINE = """You are an AI designed to answer human questions, pleas
_DEFAULT_TEMPLATE = """
You are a SQL expert. Given an input question, first create a syntactically correct {dialect} query to run, then look at the results of the query and return the answer.
Unless the user specifies in his question a specific number of examples he wishes to obtain, always limit your query to at most {top_k} results.
You can order the results by a relevant column to return the most interesting examples in the database.
Never query for all the columns from a specific table, only ask for a the few relevant columns given the question.
If the given table is beyond the scope of use, do not use it forcibly.
Use as few tables as possible when querying.
Pay attention to use only the column names that you can see in the schema description. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table.
"""
PROMPT_SUFFIX = """Only use the following tables:
PROMPT_SUFFIX = """Only use the following tables generate sql:
{table_info}
Question: {input}