Chat completion
Completion
The chat completion can be used to generate a conversational response for a given set of messages with a provided model.
โ To keep a conversational memory for the next chat completion, update the list of messages with the previous question and answer.
Completion with stream
Chat completion with conversational memory
In memory history
To store the messages in memory, use history.MemoryMessages
Bbolt history
Bbolt is an embedded key/value database for Go.
To store the messages in a bbolt bucket, use history.BboltMessages
Note
๐ you will find a complete example in:
- examples/11-chat-conversational-bbolt
- examples/11-chat-conversational-bbolt/begin: start a conversation and save the history
- examples/11-chat-conversational-bbolt/resume: load the messages from the history bucket and resue the conversation
Conversational history: remove messages
In Memory
- Remove a message by id
history.RemoveMessage(id string)
Bbolt Memory
- Remove a message by id
history.RemoveMessage(id string)
Conversational history: handling sessions
In Memory
-
history.SaveMessageWithSession(sessionId string, messagesCounters *map[string]int, message llm.Message)
-
history.RemoveTopMessageOfSession(sessionId string, messagesCounters *map[string]int, conversationLength int)
Bbolt Memory
history.SaveMessageWithSession(sessionId string, messagesCounters *map[string]int, message llm.Message)
history.RemoveTopMessageOfSession(sessionId string, messagesCounters *map[string]int, conversationLength int)