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

Handle arbitrary length StreamChunkPart #4630

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mattrossman
Copy link
Contributor

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

This changes OpenAiClient.StreamChunk.text and OpenAiClient.StreamChunk.asAiResponse getters to respect arbitrary length this.parts instead of only considering the first part.

After patching this locally, I was able to use Google's Gemini models via their OpenAI compatibility API.

Areas to Review:

I'm not sure what is expected when there's multiple "Content" parts, all I know is that Gemini delivers one "Usage" and one "Content" part in the same chunk. For now I've .join()-ed all content parts into a single string.

I'm not certain why the asAiReponse implementation produces an empty string of content for the case when no parts are present (versus just providing an empty parts array).

if (this.parts.length === 0) {
return AiResponse.AiResponse.fromText({
role: AiRole.model,
content: ""
})
}

I've preserved this behavior in case, though I imagine it could be removed.

Related

@mattrossman mattrossman requested a review from tim-smart as a code owner March 21, 2025 22:39
Copy link

changeset-bot bot commented Mar 21, 2025

🦋 Changeset detected

Latest commit: 4513ae8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@effect/ai-openai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@IMax153 IMax153 self-assigned this Mar 24, 2025
@IMax153 IMax153 added the ai label Mar 24, 2025
}
}

if (aiResponseParts.length === 0) {
Copy link
Member

Choose a reason for hiding this comment

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

I agree that we should leave this logic in here for now, at least until I've gotten some test cases written for AiResponse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Waiting on Author
Development

Successfully merging this pull request may close these issues.

@effect/ai-openai discards meaningful content with multiple StreamChunkPart
3 participants