Repository navigation
Add TogetherAI chat provider - #14957
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds TogetherAI provider support: configuration, factory routing, a TogetherAI ModelDriver with synchronous and SSE streaming chat, model listing/check, interface stubs, and tests validating chat, streaming, listing, connection, and error paths. ChangesTogetherAI Provider Integration
Sequence DiagramsequenceDiagram
participant Client
participant TogetherAIModel
participant TogetherAI_API
Client->>TogetherAIModel: ChatWithMessages / ChatStreamlyWithSender (model, messages, API key)
TogetherAIModel->>TogetherAI_API: POST /chat/completions (Bearer token, JSON or SSE)
TogetherAI_API-->>TogetherAIModel: 200 JSON response (choices, reasoning) or SSE data: events
TogetherAIModel-->>Client: aggregated message content + reasoning (and final [DONE] for streams)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/entity/models/togetherai.go`:
- Around line 236-239: The request is created with context.Background() in the
http.NewRequestWithContext call which provides no overall deadline for
streaming; change the code to accept a context.Context parameter from the caller
(preferred) or create a context.WithTimeout (e.g., 10m) and use that context
when calling http.NewRequestWithContext so streaming requests can be cancelled;
ensure you cancel the timeout context via its cancel func to avoid leaks and
update any caller sites (or add clear docs) if you opt to require a ctx
parameter; reference the http.NewRequestWithContext invocation and the
transport.ResponseHeaderTimeout setting when making the change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5f3df89d-8754-4814-b179-88c7e36316ac
📒 Files selected for processing (4)
conf/models/togetherai.jsoninternal/entity/models/factory.gointernal/entity/models/togetherai.gointernal/entity/models/togetherai_test.go
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/entity/models/togetherai.go (1)
284-298: 💤 Low valueInconsistent reasoning handling between streaming and non-streaming.
In
ChatWithMessages(lines 193-196),Reasoningis used as a fallback only whenReasoningContentis empty. Here in streaming, both fields are sent separately if present in the same delta. While SSE deltas typically populate only one field per chunk, this creates a semantic inconsistency.Consider aligning the behavior—either treat
Reasoningas a fallback in streaming as well, or document that streaming may emit both fields independently.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/entity/models/togetherai.go` around lines 284 - 298, The streaming handler currently sends both choice.Delta.ReasoningContent and choice.Delta.Reasoning when present, causing semantic mismatch with ChatWithMessages which treats Reasoning as a fallback; change the logic in the streaming delta handling (the block that calls sender with choice.Delta.ReasoningContent, choice.Delta.Reasoning, and choice.Delta.Content) so that you send ReasoningContent when non-empty and only send Reasoning if ReasoningContent is empty (i.e., use an if / else if between ReasoningContent and Reasoning), leaving the Content branch unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/entity/models/togetherai.go`:
- Around line 284-298: The streaming handler currently sends both
choice.Delta.ReasoningContent and choice.Delta.Reasoning when present, causing
semantic mismatch with ChatWithMessages which treats Reasoning as a fallback;
change the logic in the streaming delta handling (the block that calls sender
with choice.Delta.ReasoningContent, choice.Delta.Reasoning, and
choice.Delta.Content) so that you send ReasoningContent when non-empty and only
send Reasoning if ReasoningContent is empty (i.e., use an if / else if between
ReasoningContent and Reasoning), leaving the Content branch unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5b324a06-8512-4b4b-a025-b103e13c7ba2
📒 Files selected for processing (1)
internal/entity/models/togetherai.go
Haruko386
left a comment
There was a problem hiding this comment.
Hi @tmimmanuel, thank you for your contribution.
I haven’t been able to find any official documentation for some of these sections, so please let me know where I can find the relevant documentation.
|
@tmimmanuel, would you please fix the conflicts? |
aec19bd to
df6cd50
Compare
|
@JinHai-CN |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14957 +/- ##
=======================================
Coverage 94.16% 94.16%
=======================================
Files 10 10
Lines 703 703
Branches 112 112
=======================================
Hits 662 662
Misses 25 25
Partials 16 16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Haruko386
left a comment
There was a problem hiding this comment.
@tmimmanuel Let me know if I was wrong
| } | ||
| if chatModelConfig.Stop != nil { | ||
| reqBody["stop"] = *chatModelConfig.Stop | ||
| } |
There was a problem hiding this comment.
you forget #14957 (comment)
or plz let me know if was wrong
There was a problem hiding this comment.
I am sorry, I forgot by mistake. I will fix now.
What
/v1/chat/completionsAPINotes
https://api.together.ai/v1ChatConfig:max_tokens,temperature,top_p,stop, and GPT-OSSreasoning_effortreasoning/reasoning_contentintoReasonContentTests
go test -vet=off -run TestTogetherAI -count=1 ./internal/entity/modelsgo test -vet=off -count=1 ./internal/entity/modelsRefs #14736