Repository navigation
Go: implement reasoning_chat, TTS, ASR for Groq - #15153
Conversation
Added new model entries and updated URL suffixes for ASR and TTS.
Add audio transcription and speech functionality
📝 WalkthroughWalkthroughThis PR extends the Groq provider with audio transcription and speech synthesis capabilities by implementing ChangesGroq Audio and Reasoning Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: 4
🤖 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 `@conf/models/groq.json`:
- Around line 56-62: Remove the duplicated model entry for "openai/gpt-oss-20b"
from the JSON array: locate the second object with "name": "openai/gpt-oss-20b"
(the block that includes "max_tokens": 131072 and "model_types": ["chat"]) and
delete that object so only the original declaration (the one at Lines 35-41)
remains, preventing duplicate UI options and name collisions.
In `@internal/entity/models/groq.go`:
- Around line 420-423: Validate inputs early in the audio methods: in
GroqModel.TranscribeAudio (and the other audio method around lines 536-539)
check that modelName and apiConfig are non-nil and that *modelName is not empty,
and also validate apiConfig.ApiKey is non-nil and non-empty before any
dereference; if any check fails return a clear error (e.g., "modelName is
missing" or "apiConfig or apiConfig.ApiKey is missing") so the code doesn't
panic when later using *modelName or *apiConfig.ApiKey.
- Around line 120-124: The code reads chatModelConfig.Effort without first
checking chatModelConfig for nil, which can panic for gpt-oss models; update the
conditional to guard chatModelConfig (e.g., check chatModelConfig != nil &&
chatModelConfig.Effort != nil) before assigning reqBody["reasoning_effort"],
ensuring modelLower/modelName logic still sets reqBody["include_reasoning"] when
appropriate.
- Around line 495-505: TranscribeAudio and AudioSpeech create requests with
http.NewRequest and no request context, so uploads/downloads can hang despite
transport.ResponseHeaderTimeout; wrap the request creation and g.httpClient.Do
call in a context with timeout (use context.WithTimeout and the existing
nonStreamCallTimeout), create the request with http.NewRequestWithContext(ctx,
...) instead of http.NewRequest, and ensure deferring cancel() before returning
so the overall HTTP call from TranscribeAudio and AudioSpeech is bounded when
using g.httpClient.
🪄 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: 93cdb26a-6dac-4199-a6bd-64270603ddad
📒 Files selected for processing (2)
conf/models/groq.jsoninternal/entity/models/groq.go
| { | ||
| "name": "openai/gpt-oss-20b", | ||
| "max_tokens": 131072, | ||
| "model_types": [ | ||
| "chat" | ||
| ] | ||
| }, |
There was a problem hiding this comment.
Remove the duplicated openai/gpt-oss-20b entry.
This model is already declared at Lines 35-41. Keeping both copies risks duplicate UI options and ambiguous name-based lookups.
Suggested fix
- {
- "name": "openai/gpt-oss-20b",
- "max_tokens": 131072,
- "model_types": [
- "chat"
- ]
- },📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| { | |
| "name": "openai/gpt-oss-20b", | |
| "max_tokens": 131072, | |
| "model_types": [ | |
| "chat" | |
| ] | |
| }, |
🤖 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 `@conf/models/groq.json` around lines 56 - 62, Remove the duplicated model
entry for "openai/gpt-oss-20b" from the JSON array: locate the second object
with "name": "openai/gpt-oss-20b" (the block that includes "max_tokens": 131072
and "model_types": ["chat"]) and delete that object so only the original
declaration (the one at Lines 35-41) remains, preventing duplicate UI options
and name collisions.
| modelLower := strings.ToLower(modelName) | ||
| if strings.Contains(modelLower, "gpt-oss") { | ||
| reqBody["include_reasoning"] = true | ||
| if chatModelConfig.Effort != nil { | ||
| reqBody["reasoning_effort"] = chatModelConfig.Effort |
There was a problem hiding this comment.
Guard chatModelConfig before reading Effort.
Line 123 dereferences chatModelConfig before the nil check below, so a gpt-oss request with chatModelConfig == nil will panic.
Suggested fix
modelLower := strings.ToLower(modelName)
if strings.Contains(modelLower, "gpt-oss") {
reqBody["include_reasoning"] = true
- if chatModelConfig.Effort != nil {
+ if chatModelConfig != nil && chatModelConfig.Effort != nil {
reqBody["reasoning_effort"] = chatModelConfig.Effort
}
} else if strings.Contains(modelLower, "qwen") || strings.Contains(modelLower, "deepseek") {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| modelLower := strings.ToLower(modelName) | |
| if strings.Contains(modelLower, "gpt-oss") { | |
| reqBody["include_reasoning"] = true | |
| if chatModelConfig.Effort != nil { | |
| reqBody["reasoning_effort"] = chatModelConfig.Effort | |
| modelLower := strings.ToLower(modelName) | |
| if strings.Contains(modelLower, "gpt-oss") { | |
| reqBody["include_reasoning"] = true | |
| if chatModelConfig != nil && chatModelConfig.Effort != nil { | |
| reqBody["reasoning_effort"] = chatModelConfig.Effort |
🤖 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/groq.go` around lines 120 - 124, The code reads
chatModelConfig.Effort without first checking chatModelConfig for nil, which can
panic for gpt-oss models; update the conditional to guard chatModelConfig (e.g.,
check chatModelConfig != nil && chatModelConfig.Effort != nil) before assigning
reqBody["reasoning_effort"], ensuring modelLower/modelName logic still sets
reqBody["include_reasoning"] when appropriate.
| func (g *GroqModel) TranscribeAudio(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig) (*ASRResponse, error) { | ||
| return nil, fmt.Errorf("%s, no such method", g.Name()) | ||
| if file == nil || *file == "" { | ||
| return nil, fmt.Errorf("file is missing") | ||
| } |
There was a problem hiding this comment.
Validate apiConfig and modelName up front in both audio methods.
Both methods later dereference *modelName and *apiConfig.ApiKey without guards, so nil inputs fail as panics instead of normal validation errors.
Suggested fix
func (g *GroqModel) TranscribeAudio(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig) (*ASRResponse, error) {
+ if apiConfig == nil || apiConfig.ApiKey == nil || *apiConfig.ApiKey == "" {
+ return nil, fmt.Errorf("api key is required")
+ }
+ if modelName == nil || strings.TrimSpace(*modelName) == "" {
+ return nil, fmt.Errorf("model name is required")
+ }
if file == nil || *file == "" {
return nil, fmt.Errorf("file is missing")
} func (g *GroqModel) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig) (*TTSResponse, error) {
+ if apiConfig == nil || apiConfig.ApiKey == nil || *apiConfig.ApiKey == "" {
+ return nil, fmt.Errorf("api key is required")
+ }
+ if modelName == nil || strings.TrimSpace(*modelName) == "" {
+ return nil, fmt.Errorf("model name is required")
+ }
if audioContent == nil || *audioContent == "" {
return nil, fmt.Errorf("audio content is empty")
}Also applies to: 536-539
🤖 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/groq.go` around lines 420 - 423, Validate inputs early
in the audio methods: in GroqModel.TranscribeAudio (and the other audio method
around lines 536-539) check that modelName and apiConfig are non-nil and that
*modelName is not empty, and also validate apiConfig.ApiKey is non-nil and
non-empty before any dereference; if any check fails return a clear error (e.g.,
"modelName is missing" or "apiConfig or apiConfig.ApiKey is missing") so the
code doesn't panic when later using *modelName or *apiConfig.ApiKey.
| // build request | ||
| req, err := http.NewRequest("POST", url, &body) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create request: %w", err) | ||
| } | ||
|
|
||
| req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", *apiConfig.ApiKey)) | ||
| req.Header.Set("Content-Type", writer.FormDataContentType()) | ||
|
|
||
| // send request | ||
| resp, err := g.httpClient.Do(req) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify that GroqModel has no client-level Timeout and the new audio methods omit request contexts.
set -euo pipefail
FILE="internal/entity/models/groq.go"
echo "== http.Client construction =="
sed -n '46,68p' "$FILE"
echo
echo "== timeout-related settings in the file =="
rg -n 'Timeout|ResponseHeaderTimeout|NewRequestWithContext|NewRequest\(' "$FILE"
echo
echo "== TranscribeAudio request creation =="
sed -n '420,530p' "$FILE"
echo
echo "== AudioSpeech request creation =="
sed -n '536,591p' "$FILE"Repository: infiniflow/ragflow
Length of output: 6100
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="internal/entity/models/groq.go"
echo "== Show nonStreamCallTimeout definition/nearby usage =="
rg -n "nonStreamCallTimeout" "$FILE"
echo
# print around first occurrence
LINE=$(rg -n "nonStreamCallTimeout" "$FILE" | head -n1 | cut -d: -f1)
start=$((LINE-10))
end=$((LINE+30))
sed -n "${start},${end}p" "$FILE" | nl -ba | sed -n '1,80p'
echo
echo "== Show nearby method using nonStreamCallTimeout (context creation) =="
# pick first context.WithTimeout occurrence
LINE2=$(rg -n "context\\.WithTimeout\\(context\\.Background\\(\\), nonStreamCallTimeout\\)" "$FILE" | head -n1 | cut -d: -f1 || true)
if [ -n "${LINE2}" ]; then
start2=$((LINE2-20))
end2=$((LINE2+20))
sed -n "${start2},${end2}p" "$FILE" | nl -ba | sed -n '1,80p'
fiRepository: infiniflow/ragflow
Length of output: 349
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="internal/entity/models/groq.go"
echo "== Show nonStreamCallTimeout definition/nearby usage =="
rg -n "nonStreamCallTimeout" "$FILE"
echo
# print around first occurrence
LINE=$(rg -n "nonStreamCallTimeout" "$FILE" | head -n1 | cut -d: -f1)
start=$((LINE-10))
end=$((LINE+30))
sed -n "${start},${end}p" "$FILE" | nl -ba | sed -n '1,80p'
echo
echo "== Show nearby method using nonStreamCallTimeout (context creation) =="
LINE2=$(rg -n "context\\.WithTimeout\\(context\\.Background\\(\\), nonStreamCallTimeout\\)" "$FILE" | head -n1 | cut -d: -f1 || true)
if [ -n "${LINE2}" ]; then
start2=$((LINE2-20))
end2=$((LINE2+20))
sed -n "${start2},${end2}p" "$FILE" | nl -ba | sed -n '1,80p'
fiRepository: infiniflow/ragflow
Length of output: 349
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="internal/entity/models/groq.go"
echo "== Find definition of nonStreamCallTimeout =="
rg -n "nonStreamCallTimeout" "$FILE"
echo
echo "== Show top of file (for const/var) =="
sed -n '1,120p' "$FILE" | nl -ba | head -n 120
echo
echo "== Show context.WithTimeout usage around lines 188 and 362 =="
sed -n '160,220p' "$FILE"
echo "----"
sed -n '330,390p' "$FILE"Repository: infiniflow/ragflow
Length of output: 378
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="internal/entity/models/groq.go"
echo "== Show top of file (possible const/var definitions) =="
sed -n '1,140p' "$FILE"
echo
echo "== Find definition of nonStreamCallTimeout (lines with 'nonStreamCallTimeout') =="
rg -n "nonStreamCallTimeout" "$FILE"
echo
echo "== Show block around first context.WithTimeout call (line ~188) =="
sed -n '160,220p' "$FILE"
echo
echo "== Show block around second context.WithTimeout call (line ~362) =="
sed -n '330,400p' "$FILE"Repository: infiniflow/ragflow
Length of output: 8296
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="internal/entity/models/groq.go"
echo "== Search for any http.Client Timeout usage in this file =="
rg -n "httpClient\\.Timeout|\\.Timeout\\s*:" "$FILE" || true
echo
echo "== Search for direct 'Timeout =' (transport already found elsewhere) =="
rg -n "Timeout\\s*=" "$FILE" || trueRepository: infiniflow/ragflow
Length of output: 346
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="internal/entity/models/groq.go"
echo "== Search for any http.Client Timeout usage in this file =="
rg -n "httpClient\\.Timeout|\\.Timeout\\s*:" "$FILE" || true
echo
echo "== Search for direct 'Timeout =' (transport already found elsewhere) =="
rg -n "Timeout\\s*=" "$FILE" || trueRepository: infiniflow/ragflow
Length of output: 346
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n "nonStreamCallTimeout" .Repository: infiniflow/ragflow
Length of output: 8175
Add overall deadline (context.WithTimeout) to GroqModel ASR/TTS HTTP calls
TranscribeAudio (lines ~495-505) and AudioSpeech (lines ~567-575) create requests with http.NewRequest (no request context), so the overall upload/download can run unbounded; transport.ResponseHeaderTimeout only caps waiting for response headers. Other non-streaming Groq requests in this file already use context.WithTimeout(..., nonStreamCallTimeout).
Suggested fix
+ ctx, cancel := context.WithTimeout(context.Background(), nonStreamCallTimeout)
+ defer cancel()
- req, err := http.NewRequest("POST", url, &body)
+ req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, &body)+ ctx, cancel := context.WithTimeout(context.Background(), nonStreamCallTimeout)
+ defer cancel()
- req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
+ req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewBuffer(jsonData))📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // build request | |
| req, err := http.NewRequest("POST", url, &body) | |
| if err != nil { | |
| return nil, fmt.Errorf("failed to create request: %w", err) | |
| } | |
| req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", *apiConfig.ApiKey)) | |
| req.Header.Set("Content-Type", writer.FormDataContentType()) | |
| // send request | |
| resp, err := g.httpClient.Do(req) | |
| // build request | |
| ctx, cancel := context.WithTimeout(context.Background(), nonStreamCallTimeout) | |
| defer cancel() | |
| req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, &body) | |
| if err != nil { | |
| return nil, fmt.Errorf("failed to create request: %w", err) | |
| } | |
| req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", *apiConfig.ApiKey)) | |
| req.Header.Set("Content-Type", writer.FormDataContentType()) | |
| // send request | |
| resp, err := g.httpClient.Do(req) |
🤖 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/groq.go` around lines 495 - 505, TranscribeAudio and
AudioSpeech create requests with http.NewRequest and no request context, so
uploads/downloads can hang despite transport.ResponseHeaderTimeout; wrap the
request creation and g.httpClient.Do call in a context with timeout (use
context.WithTimeout and the existing nonStreamCallTimeout), create the request
with http.NewRequestWithContext(ctx, ...) instead of http.NewRequest, and ensure
deferring cancel() before returning so the overall HTTP call from
TranscribeAudio and AudioSpeech is bounded when using g.httpClient.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15153 +/- ##
=======================================
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. 🚀 New features to boost your workflow:
|
What problem does this PR solve?
Go: implement reasoning_chat, TTS, ASR for Groq
Verify from CLI
Type of change