0ptim / JellyChat

🪼 AI chatbot for the DeFiChain ecosystem.
https://defichainwiki.com/jellychat
MIT License
11 stars 2 forks source link

Persisting Chat History #40

Closed 0ptim closed 1 year ago

0ptim commented 1 year ago

ℹ Current state

Currently, we have two separate histories.

These two histories are independent and have no connection. Even if the server still has the history, it will not be visualized on the client.

1. On the client in JS memory.

const [messages, setMessages] = useState([]);

2. On the server in Python memory.

memory = ConversationBufferMemory(
    memory_key="chat_history",
    return_messages=True,
)

⚠️ Problems

🔍 Research

Explore Zep

Explore LangChain History

✨ Solution

I'll implement a custom memory solution to have full control over the flow.

  1. A client can call /history, which will then load the history from db for a specific user. The user_token has to be passed in. If it does not exist yet, a new user is created.
  2. The history is returned to the client.
  3. The client can then, as before, call /user_message or use the socket implementation to start a conversation. No need to pass in the history.
  4. When the input from the client comes in on /user_message, an agent will be created for the user and the memory is filled with the history from the database.

So it is important to understand, that the history the users sees and the memory for the agent are two different things.

See updated process diagram.