Skip to content

Conversation

@trsdn
Copy link

@trsdn trsdn commented May 23, 2025

The OpenAI API expects the tool_calls array to have a minimum length of 1 if the property is present in an assistant message. Sending an empty tool_calls array results in a 400 error.

This commit fixes the issue by modifying the messages_format method in web/src/common/openai.ts. The method now checks if content_tool_calls (the source array from MyMessage) is null, undefined, or empty. If it is, the tool_calls property is deleted from the formatted assistant message object before it's sent to the API. This ensures that an empty tool_calls array is not transmitted.

A potential variable shadowing issue within the map function was also addressed by renaming an inner variable.

Unit tests have been added in web/src/common/openai.test.ts to cover scenarios where content_tool_calls is undefined, null, or empty, verifying that tool_calls is correctly omitted. A test case for valid content_tool_calls is also included.

The OpenAI API expects the `tool_calls` array to have a minimum length of 1 if the property is present in an assistant message. Sending an empty `tool_calls` array results in a 400 error.

This commit fixes the issue by modifying the `messages_format` method in `web/src/common/openai.ts`. The method now checks if `content_tool_calls` (the source array from `MyMessage`) is null, undefined, or empty. If it is, the `tool_calls` property is deleted from the formatted assistant message object before it's sent to the API. This ensures that an empty `tool_calls` array is not transmitted.

A potential variable shadowing issue within the map function was also addressed by renaming an inner variable.

Unit tests have been added in `web/src/common/openai.test.ts` to cover scenarios where `content_tool_calls` is undefined, null, or empty, verifying that `tool_calls` is correctly omitted. A test case for valid `content_tool_calls` is also included.
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.

1 participant