Skip to content

Conversation

@coldpatch
Copy link

Some providers (e.g. zenmux) emit data lines without a space after the colon (data:value instead of data: value), which is spec-compliant but currently causes all streamed events to return as nil.

This PR aims to update the current sse scanner to make the space optional by trimming the leading space from the extracted value. This matches what the official Anthropic and OpenAI SDKs do.

I've tested this with zenmux (which was previously broken) and it works - I'm more than willing to write a regression test however its a simple enough change that i kinda just cba - existing providers (OpenRouter, OpenAI, Anthropic) still work fine.

You can recreate the issue by using the current stream-text example and the zenmux api with a free account + w/e free models currently available (e.g., kuaishou/kat-coder-pro-v1/google/gemini-3-pro-preview-free).

opts := anthropic.AnthropicModelOptions{
	BaseURL: "https://zenmux.ai/api/anthropic",
	APIKey:  os.Getenv("ZENMUX_API_KEY"),
}
model := anthropic.NewAnthropicModel("kuaishou/kat-coder-pro-v1", opts)

response, err := model.Stream(context.Background(), &llmsdk.LanguageModelInput{
	Messages: []llmsdk.Message{
		llmsdk.NewUserMessage(
			llmsdk.NewTextPart("Tell me a story."),
		),
		llmsdk.NewAssistantMessage(
			llmsdk.NewTextPart("What kind of story would you like to hear?"),
		),
		llmsdk.NewUserMessage(
			llmsdk.NewTextPart("A fairy tale."),
		),
	},
})

if err != nil {
	log.Fatalf("Stream failed: %v", err)
}

accumulator := llmsdk.NewStreamAccumulator()

for response.Next() {
	current := response.Current()
	litter.Dump(current)

	if err := accumulator.AddPartial(*current); err != nil {
		log.Printf("Failed to add partial: %v", err)
	}
}

if err := response.Err(); err != nil {
	log.Fatalf("Stream error: %v", err)
}

finalResponse, err := accumulator.ComputeResponse()
if err != nil {
	log.Fatalf("Failed to compute response: %v", err)
}

litter.Dump(finalResponse)

Copy link
Owner

@hoangvvo hoangvvo left a comment

Choose a reason for hiding this comment

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

lgtm. thanks!

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.

2 participants