Skip to content

Commit 315b10a

Browse files
committed
Save chat history
1 parent 199f0d3 commit 315b10a

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

services/chatbot/src/chatbot_api.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def get_chat_message_history(session):
6767
database_name=MONGO_DB_NAME,
6868
collection_name="chat_histories",
6969
)
70-
app.logger.debug("Chat message history %s", chat_message_history)
7170
return chat_message_history
7271

7372

@@ -83,7 +82,7 @@ def get_qa_chain(llm, retriever, session):
8382
chatbot_prompt_template = "CrapBot:"
8483
messages = [
8584
("system", system_prompt_template),
86-
MessagesPlaceholder(variable_name="chat_history", optional=True),
85+
MessagesPlaceholder(variable_name="chat_history", optional=False),
8786
("human", human_prompt_template),
8887
("system", chatbot_prompt_template),
8988
]
@@ -103,20 +102,18 @@ def get_qa_chain(llm, retriever, session):
103102
input_key="question",
104103
output_key="answer",
105104
k=6,
105+
ai_prefix="CrapBot",
106106
chat_memory=chat_message_history,
107107
return_messages=True,
108108
),
109109
)
110-
# qa = LLMChain(prompt=PROMPT, llm=llm, retriever= retriever , memory=ConversationBufferWindowMemory(memory_key="chat_history", input_key="question", k=6), verbose = False)
111110
return qa
112111

113112

114113
def qa_answer(model, session, query):
115-
result = model.invoke(
116-
{"question": query}
117-
)
114+
result = model.invoke({"question": query})
115+
app.logger.debug("Model %s", model.__dict__)
118116
app.logger.debug("Result %s", result)
119-
app.logger.debug("Answering question %s", result["answer"])
120117
return result["answer"]
121118

122119

@@ -209,10 +206,6 @@ def ask_bot():
209206
llm = get_llm()
210207
model = get_qa_chain(llm, retriever_l, session)
211208
answer = qa_answer(model, session, question)
212-
app.logger.info("###########################################")
213-
app.logger.info("Attacker Question:: %s", question)
214-
app.logger.info("App Answer:: %s", answer)
215-
app.logger.info("###########################################")
216209
return jsonify({"initialized": "true", "answer": answer}), 200
217210

218211

0 commit comments

Comments
 (0)