Код: Выделить всё
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
prompt_chat = ChatPromptTemplate(
messages=[
SystemMessagePromptTemplate.from_template(
"you are a bartender, and you will have a conversation with customers"
),
MessagesPlaceholder(variable_name="chat_history"),
HumanMessagePromptTemplate.from_template("{question}")
]
)
qa = LLMChain(
llm=llm,
prompt=prompt_chat,
verbose=True,
memory=memory
)
t0 = time.time()
done = False
print('若要退出,請輸入 over.')
while not done:
input_chi = input()
if input_chi == 'over':
done = True
else:
t0 = time.time()
output_chi = qa({ "question": input_chi+ 'Q:' })
output_chi = output_chi['text']
print("回答時間:", time.time()-t0)
Подробнее здесь: https://stackoverflow.com/questions/785 ... y-question