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

fix: Look through all streaming chunks for tools calls #8829

Merged
merged 13 commits into from
Feb 11, 2025

Conversation

vblagoje
Copy link
Member

@vblagoje vblagoje commented Feb 7, 2025

Why:

Enhances the processing logic to support various LLM platforms—not just OpenAI. Testing with the OpenAI Python package using the Mistral platform revealed that some platforms may place tool_calls in any streamed chunk (not only in the first). This change ensures that all chunks are scanned for the tool_calls payload.

What:

  • Refined detection of tool calls across all streaming chunks.
  • Changed the assumption that tool_calls appear only in the first chunk to a search that finds them anywhere.

How can it be used:

This update ensures robust tool call tracking in streaming messages, accurately constructing payloads regardless of where the tool_calls appear:

# Updated logic to search for tool_calls in all chunks
tool_call_index = next((i for i, chunk in enumerate(chunks) if chunk.meta.get("tool_calls")), None)
tools_len = len(chunks[tool_call_index].meta.get("tool_calls", []))

How did you test it:

  • No tests were added, using old tests

Notes for the reviewer:

N/A

@github-actions github-actions bot added the type:documentation Improvements on the docs label Feb 7, 2025
@coveralls
Copy link
Collaborator

coveralls commented Feb 7, 2025

Pull Request Test Coverage Report for Build 13202693684

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.003%) to 92.712%

Files with Coverage Reduction New Missed Lines %
components/generators/chat/openai.py 2 96.4%
Totals Coverage Status
Change from base Build 13200853936: 0.003%
Covered Lines: 9057
Relevant Lines: 9769

💛 - Coveralls

@vblagoje vblagoje marked this pull request as ready for review February 10, 2025 16:07
@vblagoje vblagoje requested review from a team as code owners February 10, 2025 16:07
@vblagoje vblagoje requested review from dfokina and davidsbatista and removed request for a team February 10, 2025 16:07
Copy link
Contributor

@davidsbatista davidsbatista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vblagoje vblagoje merged commit a7c1661 into main Feb 11, 2025
18 checks passed
@vblagoje vblagoje deleted the tools_streaming_openai branch February 11, 2025 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic:tests type:documentation Improvements on the docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants