Skip to content

refactor(go-models): share chat response handling - #17289

Merged
JinHai-CN merged 4 commits into
infiniflow:mainfrom
Harry-Hz-Zhang:refactor/llm-response-zai-ds-ali
Jul 24, 2026
Merged

JinHai-CN merged 4 commits into
infiniflow:mainfrom
Harry-Hz-Zhang:refactor/llm-response-zai-ds-ali

Conversation

@Harry-Hz-Zhang

@Harry-Hz-Zhang Harry-Hz-Zhang commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add provider-specific DeepSeek chat response handling aligned with its documented schema.
  • Share Zhipu and DeepSeek usage accounting and chat response helpers.

Testing

  • go test -c -o /tmp/ragflow-models.test ./internal/entity/models

#17284

@Harry-Hz-Zhang Harry-Hz-Zhang added ci Continue Integration ☯️ refactor Pull request that refactor/refine code labels Jul 23, 2026
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2eaacf15-8078-42a2-9f1b-0c8217efd39a

📥 Commits

Reviewing files that changed from the base of the PR and between 810788a and e1a2f2f.

📒 Files selected for processing (3)
  • internal/entity/models/base_model.go
  • internal/entity/models/deepseek.go
  • internal/entity/models/zhipu-ai.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • internal/entity/models/deepseek.go
  • internal/entity/models/base_model.go
  • internal/entity/models/zhipu-ai.go

📝 Walkthrough

Walkthrough

DeepSeek and Zhipu AI now share typed chat-response parsing, streaming usage decoding, model-usage collection, and centralized tool-call handling.

Changes

Chat response and usage integration

Layer / File(s) Summary
Shared response and usage plumbing
internal/entity/models/base_model.go
Adds generic response parsing, request-ID and token-usage wiring, ClickHouse usage collection, and streaming usage helpers.
DeepSeek response and streaming integration
internal/entity/models/deepseek.go
Adds a typed DeepSeek response model and adopts shared parsing, streaming usage application, and tool-call delta handling.
Zhipu AI response and streaming integration
internal/entity/models/zhipu-ai.go
Adopts shared non-streaming and streaming usage handling, centralized tool-call accumulation, and sorted tool-call finalization.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Provider
  participant ChatParser
  participant UsageCollector
  participant ClickHouse
  Provider->>ChatParser: chat completion response
  ChatParser->>UsageCollector: normalized response and usage
  UsageCollector->>ClickHouse: collect model usage
Loading

Poem

A rabbit watched the tokens stream,
Through DeepSeek’s thoughtful chatty dream.
Zhipu’s tools now neatly pair,
Shared usage hops through every layer.
ClickHouse counts with carrots bright! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main refactor: shared chat response handling in Go models.
Description check ✅ Passed The description matches the required Summary template and includes relevant context plus testing notes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as draft July 23, 2026 07:55
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as ready for review July 23, 2026 07:55

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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/base_model.go`:
- Around line 60-107: Make usage/analytics recording best-effort in
parseChatCompletionResponse, applyStreamUsage, and the streaming SSE callbacks
in deepseek.go and zhipu-ai.go: preserve the successfully parsed response and
continue through stream completion even when collectModelUsage or
clickhouse.GetDriver().CollectModelUsage fails. Handle or log usage-write errors
without returning them as primary chat or stream errors.
- Around line 93-95: Update ChatStreamlyWithSender and its applyStreamUsage
streaming path to populate modelUsage.RequestID from the first available usage
or response event before calling collectModelUsage(). Ensure both DeepSeek and
Zhipu streaming implementations preserve and pass the request ID when recording
usage.
🪄 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 Plus

Run ID: e807f662-72f7-4814-a911-9322488dc710

📥 Commits

Reviewing files that changed from the base of the PR and between e3e2d0a and 7cc3878.

📒 Files selected for processing (3)
  • internal/entity/models/base_model.go
  • internal/entity/models/deepseek.go
  • internal/entity/models/zhipu-ai.go

Comment thread internal/entity/models/base_model.go Resolved
Comment thread internal/entity/models/base_model.go Resolved
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as draft July 23, 2026 09:16
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as ready for review July 23, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration ☯️ refactor Pull request that refactor/refine code size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants