deep-chat
deep-chat copied to clipboard
[Bug] Functions not async
As far as i can see the function_handler param can not accept an async function. This is very limiting because i want to handle function calls by calling async methods and stuff.
Can you please fix this ?
love the tool for the rest though
any updates on this ?
Hey @Eggwise.
If you are referring to the function_handler property used in the OpenAI Functions section, it should be able to handle the async functions.
Could you give me a code example where that does not work please.
Thankyou!
Hi Ovidijus,
An error is shown when the assistant tries to call a function and the function_handler attribute is async.
const getDefaultConnectionConfig = () => ({
openAI: {
key: localStorage.getItem("OPENAI_API_KEY"),
assistant: {
assistant_id: "...",
async function_handler(functionsDetails) { //when this is not async it works just fine
...
}
},
},
});
@OvidijusParsiunas
Hey @Eggwise.
Because the functionsDetails argument is an array, we expect you to return a string array or an array of string Promises (string[] | Promise<string>[]).
So in your example, you can change it to something like this:
async yourAsyncFunction(functionDetails) {
...
}
const getDefaultConnectionConfig = () => ({
openAI: {
key: localStorage.getItem("OPENAI_API_KEY"),
assistant: {
assistant_id: "...",
function_handler: (functionsDetails) => {
return functionsDetails.map((functionDetails) => yourAsyncFunction(functionDetails));
}
},
},
});
Let me know if you have any questions. Thanks!
Hey @Eggwise.
Wanted to give you another update that I have made changes to make your original code work. This is now available in deep-chat-dev and deep-chat-react-dev packages version 9.0.194. These packages behave exactly the same as the core ones except their names are different.
I will notify you when these changes have been moved to the core packages.
Thankyou!
Ovidijus thank you very much for explaining. I see now how it works. Amazing thanks.
And cool that you changed the code to make it work.
Really appreciate your work on this great project!
You can close the issue
(or i will when i have access to eggwise again next week)
@OvidijusParsiunas
Hey @sv-developer.
I will close the issue when the functionality has made it to the core deep-chat and deep-chat-react packages. Thanks!
This doesnt work when you use function handler in chat mode instead of assistant mode though. @OvidijusParsiunas
Hey @Eggwise.
Because the
functionsDetailsargument is an array, we expect you to return astringarray or an array ofstring Promises(string[] | Promise<string>[]).So in your example, you can change it to something like this:
async yourAsyncFunction(functionDetails) { ... } const getDefaultConnectionConfig = () => ({ openAI: { key: localStorage.getItem("OPENAI_API_KEY"), assistant: { assistant_id: "...", function_handler: (functionsDetails) => { return functionsDetails.map((functionDetails) => yourAsyncFunction(functionDetails)); } }, }, });Let me know if you have any questions. Thanks!
This doesnt work when you use function handler in chat mode instead of assistant mode though. @OvidijusParsiunas
Hi @Eggwise.
Thankyou for letting me know about the issue.
I have updated the deep-chat-dev and deep-chat-react-dev packages versions 9.0.221 to allow multiple async funcs. Let me know if you experience any issues with it.
Thanks!
The fix is now available in deep-chat and deep-chat-react packages version 2.1.1!