Skip to content

Commit

Permalink
Merge pull request #7 from intel/letong/chat_history
Browse files Browse the repository at this point in the history
Support chat history for ChatQnA chat_stream
  • Loading branch information
lvliang-intel authored Mar 21, 2024
2 parents 6163765 + 77efb54 commit 9451e45
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ChatQnA/langchain/docker/qna-app/app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ async def rag_chat(request: Request):
return JSONResponse(status_code=400, content={"message":"Wrong knowledge base id."})

def stream_generator():
chat_response = ""
for text in router.llm_chain.stream({"question": query, "chat_history": router.chat_history}):
# print(f"[rag - chat_stream] text: {text}")
chat_response += text
if text == " ":
yield f"data: @#$\n\n"
continue
Expand All @@ -169,6 +170,9 @@ def stream_generator():
yield f"data: <br/>\n\n"
new_text = text.replace(" ", "@#$")
yield f"data: {new_text}\n\n"
chat_response = chat_response.split("</s>")[0]
print(f"[rag - chat_stream] stream response: {chat_response}")
router.chat_history.extend([HumanMessage(content=query), chat_response])
yield f"data: [DONE]\n\n"

return StreamingResponse(stream_generator(), media_type="text/event-stream")
Expand Down

0 comments on commit 9451e45

Please sign in to comment.