это моя функция get_response< /p>
Код: Выделить всё
def get_response(vectorstore, question, chat_history):
prompt_template = """
You are an expert assistant. Based on the context provided below, answer the user's question concisely and clearly. If the context does not provide enough information, let the user know that you do not have sufficient information to answer the question.
Context:
{context}
User's Question:
{question}
Assistant's Answer:
"""
prompt = PromptTemplate(template=prompt_template, input_variables=["context", "chat_history", "question"])
memory = ConversationBufferMemory(
memory_key="chat_history", max_len=50, return_messages=True
)
qa = RetrievalQA.from_chain_type(
llm=self.llm,
chain_type="stuff",
retriever=vectorstore.as_retriever(search_type="similarity", search_kwargs={"k": 3}),
return_source_documents=False,
chain_type_kwargs={"prompt": prompt},
memory=memory
)
answer = qa({"query": question, "chat_history": chat_history})
return answer['result'].strip()
Код: Выделить всё
if 'chat_history' not in request.session:
request.session['chat_history'] = []
chat_history = request.session['chat_history']
assistant = DocumentChatAssistant()
faiss_index = assistant.load_vector_store(selected_file, folder_path) # predefined files
response = assistant.get_response(faiss_index, user_input, chat_history)
chat_history.append((user_input, response))
request.session['chat_history'] = chat_history
Нужно ли мне изменить приглашение, чтобы также предоставить историю в качестве контекста? Или вместо использования извлеченного контроля качества мне следует использовать цепочку разговоров или что-то еще?
Мои требования – получить соответствующую информацию о файле, сохраняя мой предыдущий контроль качества в памяти.
любые рекомендации будут очень полезны.
Подробнее здесь: https://stackoverflow.com/questions/790 ... ain-django