Closed jackitaliano closed 9 months ago
Hi @jackitaliano. Just so I understand correctly, you want to set the thread_id and automatically start the chat with the previous messages being pre-populated in the chat box?
Hi @jackitaliano. Just so I understand correctly, you want to set the thread_id and automatically start the chat with the previous messages being pre-populated in the chat box?
Hello @OvidijusParsiunas
That would be the ideal solution for me.
The main thing is being able to set the thread_id so the assistant has the context of thread. With the current deep-chat api and docs, it is certainly possible for me to pre-populate the previous messages in the chat box; however, I am not able to give those messages to the Assistant as I'd like to.
In the case where no thread_id is set by the consumer, it would default to it's current functionality.
If you're willing/able to implement both setting the thread_id and pre-populating the chat, that would be even better.
Thanks for the response!
Let me see what I can do. I'll try out a couple of things and give you an update on what's possible. Depending on the complexity of the solution I may need to continue this tomorrow as it is quite late where I live. I'll give you an update as soon as I have something. Thanks!
Let me see what I can do. I'll try out a couple of things and give you an update on what's possible. Depending on the complexity of the solution I may need to continue this tomorrow as it is quite late where I live. I'll give you an update as soon as I have something. Thanks!
Great! No problem at all if you're not able to complete it tonight. Thanks.
Hi. I have updated the assistant interface with two new properties - thread_id
and load_thread_history
. Full interface:
interface OpenAIAssistant {
assistant_id?: string;
thread_id?: string;
load_thread_history?: boolean;
new_assistant?: OpenAINewAssistant;
function_handler?: AssistantFunctionHandler;
}
When thread_id
is set, the conversation will continue using that thread. When load_thread_history
is also set, it will attempt to fetch that thread's history and populate the messages. The reason for using the second property is that devs may want to store messages on their end and use initialMessages instead, or they may not want the extra fetch API call every time the chat loads up, hence they can use it to set their preference.
Example usage:
directConnection = {
openAI: {
assistant: {thread_id: 'thread-id-here', load_thread_history: true},
key: 'api-key-here',
},
}
This is available in deep-chat-dev
and deep-chat-react-dev
packages version 9.0.127
. These packages work exactly the same as the normal ones except their names are different.
Let me know if this works for you and I will promote these changes for the next core package release later this week.
Thanks!
This works great, thank you very much!
For anyone seeing this in the future, this is roughly my first shot implementation: (not exact because contains validation/logic not relevant here):
(svelte)
async function getThread() { return localStorage.getItem('openai-thread-id'); }
async function setThread(thread_id) { localStorage.setItem('openai-thread-id', thread_id); }
let openAIThreadIdSet = false;
{#await getThread() then thread_id}
<deep-chat
onNewMessage = {async function(message) {
...
if (!openAIThreadIdSet && message.message._sessionId && message.message._sessionId != thread_id) {
setThread(message.message._sessionId);
openAIThreadIdSet = true;
}
...
}}
directConnection={{
openAI: {
...
assistant: {
...
thread_id: thread_id,
load_thread_history: thread_id ? true : false,
...
}
}
}}
...
/>
This has now been released in Deep Chat version 1.4.11
. Checkout the updated assistant documentation for more.
Scenario
directConnection
to OpenAI assistantsMy thought for solution
thread_id
inonComponentRender
similar to what can be done forchatElementRef.directConnection.openAI.assistant.assistant_id
initialMessages
. a. If consumer loads message, deepchat would still retainthread_id
set by consumerMy request
onComponentRender
Reason
OpenAI's API doesn't allow adding 'Assistant' messages
initialMessages
oraddMessage
to insert messages into deepchat, but this doesn't give the assistant the messages. The messages will display, but the assistant has no knowledge of them.Use Case
Similar Requests
Save and Retrieve Chat Sessions | Issue #49
In the comments of this request, you mentioned adding a way to load messages, but merely loading messages in the UI is not as useful as loading a thread for the purposes of an assistant.
Example Psuedocode
I'm open to other solutions to this issue if you have any ideas, or maybe I'm missing something that might already solve this (though I feel I have thoroughly searched).
The work you're doing is fantastic, thank you very much!