Skip to content

fix(google): map OpenAI tool results to Gemini user role - #1773

Open
BetterAndBetterII wants to merge 1 commit into
Portkey-AI:mainfrom
BetterAndBetterII:cursor/fix-google-tool-role-mapping-74f8
Open

fix(google): map OpenAI tool results to Gemini user role#1773
BetterAndBetterII wants to merge 1 commit into
Portkey-AI:mainfrom
BetterAndBetterII:cursor/fix-google-tool-role-mapping-74f8

Conversation

@BetterAndBetterII

Copy link
Copy Markdown

Description: (required)

  • Google streamGenerateContent rejects OpenAI role: "tool" messages after they are rewritten to Google role function (HTTP 400: Role 'function' is not supported).
  • Map tool results to user. The adapter already emits a native functionResponse part; Gemini accepts that part on a user turn, not on role function.
  • Isolated to Google role mapping / tool-result handling. No other providers changed.

Fixes #1757

Tests Run/Test cases added: (required)

  • transformOpenAIRoleToGoogleRole('tool') returns user and not the rejected function role
  • Two-turn contents transform: assistant tool_calls → model functionCall; tool result → user functionResponse

Type of Change:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

streamGenerateContent rejects role "function". Tool results already
become functionResponse parts and must sit on a user turn.
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.

Google provider rejects tool results because role tool is mapped to function

2 participants