Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving chat history in PostgreSQL #96

Open
rajdeep-ghosh opened this issue Dec 10, 2024 · 2 comments · May be fixed by #98
Open

Saving chat history in PostgreSQL #96

rajdeep-ghosh opened this issue Dec 10, 2024 · 2 comments · May be fixed by #98

Comments

@rajdeep-ghosh
Copy link

Saving chat history in Redis is very simple, but for my use case, I want to save all the chat history in Postgres. How do I do this?

Like in Vercel AI SDK we can call the onStart and onCompletion callbacks on the stream to save data into db

const response = openai.createChatCompletion({
  model: 'gpt-3.5-turbo',
  messages,
  stream: true
});

const stream = OpenAIStream(response, {
  onStart: () => {
    // save user message into db
  },
  onCompletion: () => {
    // save ai message into db
  }
});

As ragChat.chat() or aiUseChatAdapter does not provide any such methods, how can I achieve a similar experience?

Stack: - upstash/rag-chat & vercel ai sdk

@ronal2do
Copy link
Contributor

ronal2do commented Dec 12, 2024

There are many ways to save your data,

I've changed onChunk to create a temp and save those values there than send to a job, but I've moved away of it

The simplest one will be on the client side with onFinish method

  const { messages, append, setMessages } = useChat({
    api: `${baseUrl}api/chat`,
    onFinish: (message: Message) => {
      saveMessageInBackground(message.content);
    },
  });

ronal2do added a commit to ronal2do/rag-chat that referenced this issue Dec 21, 2024
- Implemented an `onFinish` callback.
- Added a new test.
closes upstash#96
@ronal2do
Copy link
Contributor

@rajdeep-ghosh this PR aims to implement onFinish callback
#98
putting @CahidArda on loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants