Fix OpenAI Chat stream: prevent tool_calls[].type becoming "functionf…#296
Fix OpenAI Chat stream: prevent tool_calls[].type becoming "functionf…#296plusor wants to merge 2 commits intoactiveagents:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes an OpenAI Chat streaming merge issue where tool_calls[].type could become "functionfunctionfunction..." due to string concatenation during delta merges.
Changes:
- Convert streaming deltas via
api_message.delta.deep_to_hto preserve non-string enum values (preventinghash_merge_deltastring concatenation on:type). - Normalize tool call type handling by switching
process_function_callsto compareapi_function_call[:type].to_sagainst"function".
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
674a691 to
3df2617
Compare
…unction..." When merging streaming deltas, delta was converted with as_json.deep_symbolize_keys, which left tool_calls[].type as the string "function". hash_merge_delta concatenates when the existing value is a String (hash[key] += value), so each chunk appended "function" and produced "functionfunctionfunction...". - Use delta.deep_to_h so the gem returns symbol-keyed hashes with :type => :function. Merges then hit the replace branch and type stays :function. - Match when :function in process_function_calls for consistency.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| def stub_streaming_response(response_body, request_options = {}) | ||
| default_request = { | ||
| messages: [{ content: "What's the weather in Boston?",role: "user" }], |
There was a problem hiding this comment.
Missing space after comma. The code has "What's the weather in Boston?",role: "user" but should have a space after the comma for consistency with Ruby style conventions.
| messages: [{ content: "What's the weather in Boston?",role: "user" }], | |
| messages: [{ content: "What's the weather in Boston?", role: "user" }], |
- Remove extra empty line at class body beginning - Add spaces inside array brackets per rubocop style rules - Add missing space after comma 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
I've reviewed the PR and addressed the linting issues. Here's a summary: Linting Fixes AppliedThe rubocop issues were in
The linting fixes are available in branch Test Validation
The fix properly addresses the original issue where |
…unction..."
When merging streaming deltas, delta was converted with as_json.deep_symbolize_keys, which left tool_calls[].type as the string "function". hash_merge_delta concatenates when the existing value is a String (hash[key] += value), so each chunk appended "function" and produced "functionfunctionfunction...".