Код: Выделить всё
llm = ChatOpenAI(temperature=0, model_name=GPT3_MODEL)
< /code>
К тому времени я получил эту резюме истории чата и сохранил его в переменной. После того, как я отправляю свой запрос в LLM, я отправляю его с помощью подсказки, запроса и краткого изложения истории чата, которую я хранил в переменной. Но в словесной области я вижу всю историю чата в подсказке вместо резюме предыдущего чата. < /P>
def __set_chain_memory(self, user_id, conversation_id):
chat_mem = self.chat_memory.get(user_id, conversation_id)
llm = ChatOpenAI(temperature=0, model_name=GPT3_MODEL)
self.chain_memory = ConversationSummaryBufferMemory(
llm=llm,
chat_memory=chat_mem,
memory_key="history",
input_key="query",
return_messages=True,
max_token_limit=1000,
)
self.chain_memory.prune()
< /code>
chain_memory
Код: Выделить всё
def generate_streaming_llm_response(
self,
user_id: str,
conversation_id: str,
user_input,
llm,
prompt: str,
callback_handler: StreamingHandler,
):
self.__set_chain_memory(user_id, conversation_id)
chain = StreamingChain(
llm=llm,
prompt=prompt,
memory=self.chain_memory,
queue_manager=callback_handler.queue_manager,
)
return chain.stream(user_input, callback_handler.queue_id)
< /code>
After I send the summary of chat memory in to the StreamingChain
class StreamingChain(LLMChain):
queue_manager = QueueManager()
def __init__(self, llm, prompt, memory, queue_manager):
super().__init__(llm=llm, prompt=prompt, memory=memory)
self.queue_manager = queue_manager
def stream(self, input, queue_id, **kwargs):
queue = self.queue_manager.get_queue(queue_id)
def task():
try:
self(input)
except Exception as e:
logger.exception(f"Exception caught")
self.queue_manager.close_queue(queue_id)
t = Thread(target=task)
t.start()
try:
while True:
token = queue.get()
if token is None:
break
yield token
finally:
t.join()
self.queue_manager.close_queue(queue_id)
< /code>
I want to send the summary of the previous chat to generate the response from the LLM.
Подробнее здесь: https://stackoverflow.com/questions/784 ... chain-conv