Use a RouterQueryEngine
as a chat
#11907
Replies: 2 comments 4 replies
-
Hey @KirianCaumes, back for more adventures in coding, I see! 🚀 Based on your requirements, it seems like you want to maintain a history of previous messages in your chat system. This can be achieved by using a memory buffer that keeps track of the conversation history. In your current setup, you're using the Here's a simplified example of how you can modify your code to use from llama_index.core.chat_engine.simple import SimpleChatEngine
from llama_index.core.memory import ChatMemoryBuffer
# Initialize memory buffer
memory = ChatMemoryBuffer.from_defaults()
# Initialize chat engine
chat_engine = SimpleChatEngine(llm=Settings.llm, memory=memory)
while True:
question = input("> ")
if question == "exit":
break
response = chat_engine.chat(question)
print(str(response)) In this example, Please note that this is a simplified example and you might need to adjust it according to your project's structure and requirements. For more details on how I hope this helps! If you have any further questions or need more clarification, feel free to ask. Sources
|
Beta Was this translation helpful? Give feedback.
-
Hey @KirianCaumes! I am also checking out on this requirement wherein I need the RouterQueryEngine keep track of the chat history. Or if there is a way to switch between tools within the Chat Engine modes. Let me know if you were able to find any solution on this yet! |
Beta Was this translation helpful? Give feedback.
-
I'm working on project that has a
RouterQueryEngine
based on PDF files and SQLite DB.I have multiple
QueryEngineTool
based on bothBaseQueryEngine
andNLSQLTableQueryEngine
.If I want to ask a question on my
RouterQueryEngine
via thequery
function it works perfectly.But now, I would like to use the same system but as a chat where this chat keep memory of the previous messages.
Is this something possible? How can I achieve it?
I tried multiple things (with
OpenAIAgent
,ChatMemoryBuffer
, and so on), but I'm really stuck on this point 😕Here my (simplified) code bellow:
Beta Was this translation helpful? Give feedback.
All reactions