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

Error thrown if type?: function is not specified specified in tool_choice #521

Open
1 task done
huypham50 opened this issue Nov 21, 2023 · 3 comments
Open
1 task done
Labels
openai api Related to underlying OpenAI API

Comments

@huypham50
Copy link

huypham50 commented Nov 21, 2023

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • This is an issue with the Node library

Describe the bug

const response = await openai.chat.completions.create({
  model: 'gpt-4-1106-preview',
  messages: [{
    role: 'user',
    content: prompt,
  }],
  tool_choice: {
    type: 'function', // this prop is optional but if you remove it an error will be thrown (documented below)
    function: {
      name,
    }
  },
  tools: [
    {
      type: 'function',
      function: {
        name,
        description,
        parameters
      }
    }
  ],
})
error: {
  message: "'$.tool_choice' is invalid. Please check the API reference: https://platform.openai.com/docs/api-reference.",
  type: 'invalid_request_error',
  param: null,
  code: null
},
code: null,
param: null,
type: 'invalid_request_error'

To Reproduce

See above.

Also, it looks like parallel function calling is disabled if tool_choice is specified, is this intended?

Code snippets

No response

OS

macOS

Node version

v18.12.1

Library version

^4.19.0

@huypham50 huypham50 added the bug Something isn't working label Nov 21, 2023
@rattrayalex rattrayalex added openai api Related to underlying OpenAI API and removed bug Something isn't working labels Nov 22, 2023
@rattrayalex
Copy link
Collaborator

Thanks, I'll look into whether type: 'function' should be required in the client (which I think is the case) or whether the API should be relaxed. I'm not sure you should expect a response this week, however.

Also, it looks like parallel function calling is disabled if tool_choice is specified, is this intended?

Yes, that is intended.

rattrayalex added a commit to rattrayalex/openai-openapi that referenced this issue Nov 22, 2023
Fixes openai/openai-node#521

Current API behavior is to throw if `type: function` is not provided, my assumption is that `function` is also required.

cc @athyuttamre
@huypham50
Copy link
Author

Thanks for the quick fix!

Also, it looks like parallel function calling is disabled if tool_choice is specified, is this intended?

Yes, that is intended.

I don't think this should be the case. I can specify the function that will be called and it should be able to run in parallel as well.

If we take a look at the example in the docs, get_current_weather should be able to process all 3 cities and not just 1. If you specify tool_choice, the response will only include the first city (SF).

@rattrayalex
Copy link
Collaborator

I see your point, and you're welcome to suggest that at community.openai.com where the backend teams monitor for API feedback.

For now, you can of course work around this by only passing the tool you want called and omitting tool_choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
openai api Related to underlying OpenAI API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants