OvidijusParsiunas / deep-chat

Fully customizable AI chatbot component for your website
https://deepchat.dev
MIT License
1.43k stars 218 forks source link

Getting `Please define the function_handler property inside assistant object.` error for openai assistant with functions #119

Closed ivadenis closed 7 months ago

ivadenis commented 7 months ago

I'm getting Please define thefunction_handlerproperty inside assistant object.' error when using function for openai assistant.

const directConnection = {
      openAI: {
        key: '',
        assistant: {
          assistant_id: '',
          function_handler: (functionsDetails) => {
            return functionsDetails.map((fn) => {
              const { name, arguments } = fn;
              return gptfunctions[name](arguments);
            });
          },
          ...(threadId ? { thread_id: threadId, load_thread_history: !!threadId } : {})
        }
      }
    }

<DeepChatMemo
          onComponentRender={onRender}
          onNewMessage={onNewMessage}
          directConnection={directConnection}
        />

I looked at the source code and here https://github.com/OvidijusParsiunas/deep-chat/blob/2584368ff707aae98481d07dccbdc10e0aaac156/component/src/services/openAI/openAIAssistantIO.ts#L40 its doing

JSON.parse(JSON.stringify(deepChat.directConnection)) which removes the function_handler from the config.

OvidijusParsiunas commented 7 months ago

Hi @ivadenis. Wanted to let you know I saw your issue and it's likely a small fix that needs to be made on in the component. I'm currently not by a computer and will take a look at it later tonight.

OvidijusParsiunas commented 7 months ago

Excellent debugging work as that was the code that was causing the problem. The only question I have is - what Deep Chat NPM package are you using and which version? The problematic code line is not out in the main packages and is only available in the dev ones, hence it is quite strange if you are seeing your error in the main packages. Nonetheless, I have deployed a fix to our deep-chat-dev and deep-chat-react-dev packages version 9.0.130. These packages operate exactly the same as the main ones, except their names are different. Let me know if the fix works for you.

ivadenis commented 7 months ago

Thank you! Will check. I was using the prod version, but then switched to dev because it seemed that prod was behind a bit on functionality i needed.

@OvidijusParsiunas how often do you merge dev to prod package?

OvidijusParsiunas commented 7 months ago

Hi @ivadenis. The release frequency depends on multiple factors; such as the amount of features, their complextity/severity, the documentation that needs to be updated and many other smaller things, hence the period between releases can vary. Usually it is an average of every 2-4 weeks.

The next release will take place some-time this week (if nothing new comes up of-course).

OvidijusParsiunas commented 7 months ago

This fix has now been deployed in Deep Chat version 1.4.11.