OvidijusParsiunas / deep-chat

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

Upgrade to openai assistant v2 #190

Closed lucasdfr closed 2 months ago

lucasdfr commented 4 months ago

OpenAI has recently released assitant v2, the v1 will be deprecated by the end of 2024. See : https://platform.openai.com/docs/assistants/migration

OvidijusParsiunas commented 4 months ago

Hi @lucasdfr. Thankyou for letting me know about this! I will start working on it ASAP!

OvidijusParsiunas commented 4 months ago

The OpenAI Assistants v2 integration is now available in deep-chat-dev and deep-chat-react-dev versions 9.0.174.

The Assistants object now has a new property called files_tool_type which has the following type:

files_tool_type?: FileToolTypes | ((fileNames: string[]) => FileToolTypes);

This uses a new FileToolTypes type:

type FileToolTypes = 'code_interpreter' | 'file_search' | 'images';

This is basically used to define the tool that will be used when the user uploads files. You can also define a function which returns a particular tool type string based on the uploaded files. If files_tool_type is not defined, Deep Chat automatically defaults to using images and simply sends the image to a vision model without using the code_interpreter and file_search tools. It is IMPORTANT to note that when code_interpreter or file_search are defined, you need to make sure they are toggled on in the OpenAI Assistant Playground or in the NewAssistant object.

Example for defining the files_tool_type:

directConnection={{
  openAI: {
    assistant: {
      assistant_id: 'assistant with code interpreter',
      files_tool_type: 'code_interpreter',
    },
    key: 'your-key',
  },
}}

The NewAssistant object has also been updated to reflect the New Assistant Open AI API:

type OpenAINewAssistant = {
  model?: string;
  name?: string;
  description?: string;
  instructions?: string;
  tools?: {
    type: 'code_interpreter' | 'file_search' | 'function';
    function?: {name: string; description?: string; parameters?: object};
  }[];
  tool_resources?: {
    code_interpreter?: {
      file_ids: string[];
    };
    file_search?: {
      vector_store_ids?: string[];
      vector_stores: {file_ids: string[]};
    };
  };
}

Let me know if you experience any issues using this. Thankyou!

OvidijusParsiunas commented 2 months ago

Hi, the functionality mentioned in this issue is now available in Deep Chat version 2.0.0.