Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAIAssistantAdapter errors out with Invalid 'retrieval' value #324

Open
thormuller opened this issue May 6, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@thormuller
Copy link

thormuller commented May 6, 2024

When attempting to integrate the OpenAIAssistantAdapter within a CopilotRuntime environment, the operation fails with a 400 Invalid value error. The error message says [Error: 400 Invalid value: 'retrieval'. Supported values are: 'code_interpreter', 'function', and 'file_search'.] This issue occurs when trying to configure the OpenAIAssistantAdapter with an unsupported tool type.

Error:
Error getting response: [Error: 400 Invalid value: 'retrieval'. Supported values are: 'code_interpreter', 'function', and 'file_search'.] {status: 400, ...}
To Reproduce

  1. Import CopilotRuntime and OpenAIAssistantAdapter from @copilotkit/backend.
    import { CopilotRuntime, OpenAIAssistantAdapter } from "@copilotkit/backend"; export const runtime = "edge";

  2. Set up a basic server with the CopilotRuntime.

  const copilotKit = new CopilotRuntime();
  console.log('openai key', process.env.OPENAI_API_KEY);

  return copilotKit.response(
    req,
    new OpenAIAssistantAdapter({ 
        assistantId: "####"
    })
  );}
  1. Access this API via the copilotkit chat UI
  2. Observe the error when making a request.

Expected behavior
The API should successfully return a chat completion response from the OpenAI server.

@thormuller thormuller added the bug Something isn't working label May 6, 2024
@thormuller
Copy link
Author

I've identified the specific breaking error in CopilotKit's openai-assistant-adapter. It stems for the move to V2 Assistants API.

From the openAI migration documentation from April 17:
The v2 version of the Assistants API contains the following changes:


- Tool rename: The retrieval tool has been renamed to the file_search tool
- Files belong to tools: Files are now associated with tools instead of Assistants and Messages. This means that:
AssistantFile and MessageFile objects no longer exist.
Instead of AssistantFile and MessageFile, files are attached to Assistants and Threads using the new tool_resources object.
The tool_resources for the code interpreter tool are a list of file_ids.
The tool_resources for the file_search tool are a new object called a vector_stores.
Messages now have an attachments, rather than a file_ids parameter. Message attachments are helpers that add the files to a Thread’s tool_resources.

https://platform.openai.com/docs/assistants/migration

Therefore, in your backend/src/lib/openai-assistant-adapter.ts:

const tools = [
...(forwardedProps.tools || []),
...(this.codeInterpreterEnabled ? [{ type: "code_interpreter" }] : []),
...(this.retrievalEnabled ? [{ type: "retrieval" }] : []),
];

You must change 'retrieval' to 'file-search'.

Until you make this change, OpenAIAssistantAdapter will be broken on the V2 API it's currently pointing to. You will want to double check the other migration steps mentioned in that documentation as well.

The alternative is for you to update the code to v1 for now, though this api will be discontinued by end of year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant