Skip to content

Conversation

agarcher
Copy link
Contributor

@agarcher agarcher commented Jun 5, 2025

When consumers supply tools that use a full OpenAI::Chat::ChatCompletionTool rather than providing only an OpenAI::BaseModel, the calls to OpenAI fail because the tools argument winds up invalid. The mapping in the library overwrites the tool in the array with nil because there are missing return values from the second and third options of the case statement.

my_function_definition = OpenAI::Models::FunctionDefinition.new(
  name: "my_tool_name",
  description: "My tool description",
  parameters: OpenAI::BaseModel.new({ ... })
)
my_tool_definition = OpenAI::Chat::ChatCompletionTool.new(
  type: :function,
  function: my_function_definition
)
openai_client.chat.completions.create(
  ...
  tools: [my_tool_definition]
)

@agarcher agarcher requested a review from a team as a code owner June 5, 2025 14:51
@ms-jpq ms-jpq changed the base branch from main to next June 5, 2025 14:56
@ms-jpq ms-jpq changed the title Fix tool parameter mapping for chat completions fix: tool parameter mapping for chat completions Jun 5, 2025
@ms-jpq
Copy link
Collaborator

ms-jpq commented Jun 5, 2025

ohh, thank you so much for fixing this!

@ms-jpq ms-jpq merged commit 5999b9f into openai:next Jun 5, 2025
@stainless-app stainless-app bot mentioned this pull request Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants