deep-chat icon indicating copy to clipboard operation
deep-chat copied to clipboard

[Bug] Functions not async

Open Eggwise opened this issue 1 year ago • 5 comments

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 ?

Eggwise avatar Sep 07 '24 01:09 Eggwise

love the tool for the rest though

Eggwise avatar Sep 07 '24 01:09 Eggwise

any updates on this ?

Eggwise avatar Sep 28 '24 02:09 Eggwise

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!

OvidijusParsiunas avatar Sep 28 '24 07:09 OvidijusParsiunas

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

Eggwise avatar Oct 01 '24 23:10 Eggwise

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!

OvidijusParsiunas avatar Oct 02 '24 14:10 OvidijusParsiunas

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!

OvidijusParsiunas avatar Oct 08 '24 14:10 OvidijusParsiunas

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!

sv-developer avatar Oct 10 '24 10:10 sv-developer

You can close the issue

(or i will when i have access to eggwise again next week)

@OvidijusParsiunas

sv-developer avatar Oct 10 '24 10:10 sv-developer

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!

OvidijusParsiunas avatar Oct 10 '24 14:10 OvidijusParsiunas

This doesnt work when you use function handler in chat mode instead of assistant mode though. @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!

This doesnt work when you use function handler in chat mode instead of assistant mode though. @OvidijusParsiunas

Eggwise avatar Dec 20 '24 04:12 Eggwise

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!

OvidijusParsiunas avatar Dec 21 '24 09:12 OvidijusParsiunas

The fix is now available in deep-chat and deep-chat-react packages version 2.1.1!

OvidijusParsiunas avatar Jan 08 '25 12:01 OvidijusParsiunas