Skip to content

feat(go-models): add Groq provider driver - #15097

Merged
JinHai-CN merged 4 commits into
infiniflow:mainfrom
JSONbored:codex/groq-go-driver-15088
May 22, 2026
Merged

JinHai-CN merged 4 commits into
infiniflow:mainfrom
JSONbored:codex/groq-go-driver-15088

Conversation

@JSONbored

@JSONbored JSONbored commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Closes #15088.

Adds Groq support to the Go model-provider layer so Groq instances can be routed through the Go API server with the same OpenAI-compatible chat, streaming, model listing, and connection-check flow used by other SaaS providers.

Type of change

  • New Feature (non-breaking change which adds functionality)

Summary

  • Added a Groq Go model driver.
  • Added the Groq provider catalog and default OpenAI-compatible API URL.
  • Registered Groq in the model factory.
  • Added focused provider tests.

What changed

  • Implemented chat completions, SSE streaming, ListModels, and CheckConnection for Groq.
  • Covered request shape, stream termination, reasoning fallback, model listing, custom base URLs, safe transport setup, and unsupported methods.
  • Kept the provider catalog scoped to current Groq chat-capable model IDs.
  • Cleaned up pre-existing Go model package validation blockers so the package can be tested normally with vet enabled.

Why

The existing Python/provider catalog path includes Groq, but the Go model-provider layer did not have a Groq driver, so the Go API server could not instantiate or use Groq as requested in #15088.

Validation

  • go test ./internal/entity/models -count=1
  • go test ./internal/entity/... -count=1
  • jq empty conf/models/groq.json
  • git diff --check

Notes

The model package now validates without disabling vet.

@coderabbitai

coderabbitai Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ab1fce52-5320-4452-8b52-a9f76bc4ca88

📥 Commits

Reviewing files that changed from the base of the PR and between b4578a2 and 3627fc9.

📒 Files selected for processing (1)
  • internal/entity/models/factory.go

📝 Walkthrough

Walkthrough

This PR adds Groq provider support to the Go model-driver framework. It introduces a JSON configuration file defining the Groq OpenAI-compatible API defaults, registers the provider in the factory, implements a full-featured GroqModel driver with non-streaming and SSE streaming chat completions, model listing and connection checks, and comprehensive test coverage validating all code paths and error cases.

Changes

Groq Model Provider Integration

Layer / File(s) Summary
Configuration and Factory Registration
conf/models/groq.json, internal/entity/models/factory.go
Groq provider JSON config with https://api.groq.com/openai/v1 base URL, chat and models endpoint mappings, and a list of 8 supported chat models with 131,072 max tokens. Factory switch recognizes provider string "groq" and instantiates NewGroqModel.
Driver Type and HTTP Client Setup
internal/entity/models/groq.go (lines 1–99)
GroqModel struct with region-aware base URL map, URL suffix configuration, and HTTP client with transport setup (idle connection limits, timeouts, compression). NewGroqModel constructor and NewInstance factory method; Name() returns "groq"; region-keyed endpoint construction with default region fallback and trailing-slash trimming.
Request Payload and Response Contracts
internal/entity/models/groq.go (lines 101–151)
Helper function converts internal Message list and optional generation settings (max tokens, temperature, top_p, stop sequences) into Groq/OpenAI request payload map. Response structs for chat choices, deltas (with reasoning and content fields), finish reasons, and model listing.
Non-streaming Chat Completions
internal/entity/models/groq.go (lines 152–219)
ChatWithMessages validates API key, model name, and non-empty messages; constructs POST request to /chat/completions with stream=false; enforces HTTP 200; unmarshals response; extracts first choice's message content and reasoning (fallback between reasoning_content and reasoning fields).
Streaming Chat Completions
internal/entity/models/groq.go (lines 220–327)
ChatStreamlyWithSender validates inputs and requires stream enabled; POSTs to /chat/completions with stream=true and Accept: text/event-stream header; scans SSE response body for data: lines; unmarshals each delta event; forwards reasoning and content deltas to sender callback; recognizes [DONE] and finish-reason terminal signals; sends final "[DONE]" marker to sender.
Model Discovery and Connection Check
internal/entity/models/groq.go (lines 328–392)
ListModels performs GET to /models with API key validation, HTTP 200 enforcement, JSON unmarshal, and model-ID extraction. CheckConnection delegates to ListModels for health verification.
Unsupported Capability Stubs
internal/entity/models/groq.go (lines 393–435)
Stub methods for embeddings, reranking, balance, ASR/TTS, OCR, file parsing, and task APIs; each returns standardized "no such method" error.
Comprehensive Test Suite
internal/entity/models/groq_test.go
httptest server helper validating Authorization: Bearer header and JSON content type. Tests verify: driver name ("groq") and factory instantiation; custom HTTP transport support; chat happy-path and validation (missing model name, empty messages, HTTP error propagation); streaming happy-path, SSE delta parsing, [DONE] sentinel, sender callback errors, and unterminated stream detection; model listing and connection check success; base-URL trailing-slash handling; empty-region custom base-URL resolution; unsupported-method error assertions.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant GroqModel
  participant GroqAPI
  participant Sender as SSE_Sender

  rect rgba(100, 150, 200, 0.5)
  Note over Client,GroqAPI: Non-streaming Chat Flow
  Client->>GroqModel: ChatWithMessages(model, messages, apiConfig)
  GroqModel->>GroqModel: Validate inputs
  GroqModel->>GroqAPI: POST /chat/completions (stream=false)
  GroqAPI-->>GroqModel: JSON response with choices[0]
  GroqModel->>Client: ChatResponse{content, reasoning}
  end

  rect rgba(150, 150, 100, 0.5)
  Note over Client,Sender: Streaming Chat Flow
  Client->>GroqModel: ChatStreamlyWithSender(model, messages, apiConfig, sender)
  GroqModel->>GroqAPI: POST /chat/completions (stream=true, Accept: text/event-stream)
  GroqAPI-->>GroqModel: SSE stream (data: JSON events)
  loop Process SSE Events
    GroqModel->>GroqModel: Unmarshal event delta
    GroqModel->>Sender: Send reasoning/content deltas
  end
  GroqAPI-->>GroqModel: [DONE]
  GroqModel->>Sender: Send terminal "[DONE]"
  GroqModel-->>Client: return nil
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

The PR introduces a new model driver with heterogeneous logic: HTTP client configuration, region-aware endpoint resolution, dual chat modes (blocking and streaming SSE), request/response marshaling with multiple field variations, error handling across network and API layers, and 15 test functions covering edge cases. The streaming implementation is the densest portion, requiring careful attention to SSE parsing, delta accumulation, terminal detection, and sender callback contracts. Test coverage is thorough but adds to review scope.

Possibly related issues

  • infiniflow/ragflow#15088: The linked issue requesting Groq provider support in the Go driver framework; this PR directly fulfills its requirements by adding the GroqModel driver, JSON config, and test suite.

Possibly related PRs

  • infiniflow/ragflow#15064: Adds Astraflow (another OpenAI-compatible SaaS provider) with very similar driver structure, config registration, and test patterns.
  • infiniflow/ragflow#14850: Adds Novita provider with analogous non-streaming and SSE streaming chat, model listing, and CheckConnection implementations.
  • infiniflow/ragflow#15022: Extends factory registration in CreateModelDriver to add Azure OpenAI provider, following the same factory-dispatch pattern as this PR's Groq addition.

Suggested labels

size:XL

Suggested reviewers

  • Haruko386

Poem

🐰 A rabbit hops through Groq's swift gateway,
SSE streams dance in delta-split ballet,
Reasoning fields whisper, messages align,
From factory wires to completion so fine,
Chat flows now bloom—both swift and streamline! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding Groq provider driver support to the Go models package.
Description check ✅ Passed The PR description provides comprehensive coverage of objectives, changes, reasoning, and validation steps, fully aligned with the template's intent.
Linked Issues check ✅ Passed All requirements from #15088 are met: GroqModel implementation added, factory registration done, groq.json config provided with default URL, and all OpenAI-compatible endpoints (chat, streaming, list models, connection check) fully implemented.
Out of Scope Changes check ✅ Passed All changes are directly scoped to #15088 requirements: Groq driver implementation, configuration, factory registration, and comprehensive test coverage with no unrelated modifications.

✏️ 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.

❤️ Share

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

@JSONbored
JSONbored marked this pull request as ready for review May 21, 2026 06:41
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels May 21, 2026
@JinHai-CN

Copy link
Copy Markdown
Member

@JSONbored Since previous PR includes a binary file which is very big. So, I reset the head of main branch one hour ago. Would you please re-submit the commit from current HEAD of main branch? Thank you very much.

@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels May 21, 2026
@JSONbored

Copy link
Copy Markdown
Contributor Author

@JSONbored Since previous PR includes a binary file which is very big. So, I reset the head of main branch one hour ago. Would you please re-submit the commit from current HEAD of main branch? Thank you very much.

Sure, i will get this handled now 👍🏻

@JinHai-CN

Copy link
Copy Markdown
Member

@JSONbored Since previous PR includes a binary file which is very big. So, I reset the head of main branch one hour ago. Would you please re-submit the commit from current HEAD of main branch? Thank you very much.

Sure, i will get this handled now 👍🏻

Awesome, please let me know once you've finished. Thanks!

JSONbored added 3 commits May 21, 2026 00:58
Add a Groq Go model driver, provider catalog, factory registration, and focused tests for chat, streaming, model listing, connection checks, and custom base URL handling.
Fix vet-safe error formatting in existing model providers and align unsupported-method tests with currently implemented TogetherAI and Xinference capabilities so the Go model package validates cleanly.
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels May 21, 2026
@JSONbored

Copy link
Copy Markdown
Contributor Author

@JSONbored Since previous PR includes a binary file which is very big. So, I reset the head of main branch one hour ago. Would you please re-submit the commit from current HEAD of main branch? Thank you very much.

Sure, i will get this handled now 👍🏻

Awesome, please let me know once you've finished. Thanks!

Done!

@Haruko386

Copy link
Copy Markdown
Member

Hi @JSONbored, before I review your code, I want to know where I can find API Reference and Create API KEYS?
I try to find entries in https://groq.com/, when I try to press Free API-KEYS and Docs under Developers

@JSONbored

Copy link
Copy Markdown
Contributor Author

Hi @JSONbored, before I review your code, I want to know where I can find API Reference and Create API KEYS? I try to find entries in https://groq.com/, when I try to press Free API-KEYS and Docs under Developers

Hi @Haruko386, Groq’s developer docs and API keys are under GroqCloud:

The endpoints used by this PR are documented there:

  • POST https://api.groq.com/openai/v1/chat/completions
  • GET https://api.groq.com/openai/v1/models

So the default base URL in this driver is https://api.groq.com/openai/v1, with chat/completions and models as suffixes.

@Haruko386

Haruko386 commented May 21, 2026 •

Copy link
Copy Markdown
Member

@JSONbored emmm, I try to access these links, but it returned :

{"error": {"message":"Forbidden"}}

You can try it too.
I need API-KEY and API Reference Docs to verify your code, so, IDK what to do now : (

@JSONbored

Copy link
Copy Markdown
Contributor Author

@JSONbored emmm, I try to access these links, but it returned :

{"error": {"message":"Forbidden"}}

You can try it too. I need API-KEY and API Reference Docs to verify your code, so, IDK what to do now : (

Hi @Haruko386, thanks for checking. I tested the same GroqCloud links from my environment and they return HTTP 200, so the Forbidden response looks like a GroqCloud access restriction for your network/account/region rather than a broken URL.

The driver is using Groq’s OpenAI-compatible endpoints:

  • Chat completions: POST https://api.groq.com/openai/v1/chat/completions
  • Model listing: GET https://api.groq.com/openai/v1/models
  • Auth: Authorization: Bearer <GROQ_API_KEY>

I cannot provide a Groq API key, since reviewers need to create/manage their own key in GroqCloud. If GroqCloud is blocked for your environment, live API verification may not be possible there.

The PR includes httptest coverage for the request shape, auth header, chat response parsing, streaming response parsing, model listing, connection checks, error handling, and base URL normalization, so the wire behavior can still be reviewed without a live Groq key.

@Haruko386

Copy link
Copy Markdown
Member

@JSONbored I use VPN, and I can see the docs now, thank you for your time, I will review your code soon ;)

@Haruko386 Haruko386 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@JSONbored LGTM

@Haruko386 Haruko386 added the ci Continue Integration label May 22, 2026
@codecov

codecov Bot commented May 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.12%. Comparing base (b2bf915) to head (3627fc9).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15097   +/-   ##
=======================================
  Coverage   93.12%   93.12%           
=======================================
  Files          10       10           
  Lines         713      713           
  Branches      116      116           
=======================================
  Hits          664      664           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit f9ce07c into infiniflow:main May 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Implement provider: Groq in Go driver

3 participants