Repository navigation
Go: add ASR, TTS, OCR command - #14836
Conversation
Signed-off-by: Jin Hai <[email protected]>
📝 WalkthroughWalkthroughThis PR introduces audio transcription (ASR), text-to-speech (TTS), and OCR capabilities by extending the ModelDriver interface with five new methods (including streaming variants), implementing stub methods across 24 provider models, adding service-layer routing and HTTP handlers with SSE streaming support, registering new API endpoints, and integrating CLI commands for user-mode operations. ChangesAudio and OCR Operations (ASR/TTS/OCR)
🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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: 17
🧹 Nitpick comments (18)
internal/entity/models/moonshot.go (2)
38-41: ⚡ Quick winReplace panic with error return.
The
ParseFile()stub currently panics. Consider returning an error instead for graceful handling.♻️ Proposed fix to return error instead of panic
func (m *MoonshotModel) ParseFile() { - //TODO implement me - panic("implement me") + // TODO: implement me + return fmt.Errorf("%s, ParseFile not implemented", m.Name()) }Note: This will require updating the
ParseFile()method signature in theModelDriverinterface to returnerror.🤖 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/moonshot.go` around lines 38 - 41, The ParseFile() method on MoonshotModel currently panics; change it to return an error instead: update the MoonshotModel.ParseFile implementation to perform its parsing work and return nil on success or an error on failure (no panics), and update the ModelDriver interface's ParseFile signature to return error so callers can handle failures gracefully; ensure all implementations of ModelDriver are updated to match the new signature and adjust any callers to check and propagate the returned error.
515-517: ⚡ Quick winFix inconsistent receiver variable name.
The receiver variable on line 515 uses
minstead ofz, which is inconsistent with the rest of the file wherezis used forMoonshotModel.♻️ Proposed fix for consistent receiver naming
-func (m *MoonshotModel) OCRFile(modelName *string, fileContent *string, apiConfig *APIConfig, ocrConfig *OCRConfig) (*OCRResponse, error) { +func (z *MoonshotModel) OCRFile(modelName *string, fileContent *string, apiConfig *APIConfig, ocrConfig *OCRConfig) (*OCRResponse, error) { - return nil, fmt.Errorf("%s, no such method", m.Name()) + return nil, fmt.Errorf("%s, no such method", z.Name()) }🤖 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/moonshot.go` around lines 515 - 517, The method OCRFile on type MoonshotModel uses receiver variable "m" inconsistent with the rest of the file which uses "z"; change the receiver in the function signature from "m *MoonshotModel" to "z *MoonshotModel" (i.e., update func (m *MoonshotModel) OCRFile(...) to func (z *MoonshotModel) OCRFile(...)) so the method's receiver name matches other methods and references to the receiver inside the function (use z.Name() if applicable).internal/entity/models/dummy.go (2)
29-32: ⚡ Quick winReplace panic with error return.
The
ParseFile()stub currently panics. Consider returning an error instead for graceful handling, consistent with other unimplemented methods in this file that returnfmt.Errorf("not implemented").♻️ Proposed fix to return error instead of panic
func (d *DummyModel) ParseFile() { - //TODO implement me - panic("implement me") + // TODO: implement me + return fmt.Errorf("not implemented") }Note: This will require updating the
ParseFile()method signature in theModelDriverinterface to returnerror.🤖 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/dummy.go` around lines 29 - 32, The ParseFile method on DummyModel should not panic; change DummyModel.ParseFile to return an error (e.g., fmt.Errorf("not implemented")) instead of calling panic, and update the ModelDriver interface's ParseFile signature to return error so callers can handle it; also update any other types that implement ModelDriver to match the new signature (adjust function signatures and return fmt.Errorf("not implemented") where appropriate) and import fmt if needed.
87-89: ⚡ Quick winFix inconsistent receiver variable names.
The receiver variables on lines 87 and 97 use
zinstead ofd, which is inconsistent with the rest of the file.♻️ Proposed fix for consistent receiver naming
-func (z *DummyModel) TranscribeAudioWithSender(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig, sender func(*string, *string) error) error { +func (d *DummyModel) TranscribeAudioWithSender(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig, sender func(*string, *string) error) error { - return fmt.Errorf("%s, no such method", z.Name()) + return fmt.Errorf("%s, no such method", d.Name()) }-func (z *DummyModel) AudioSpeechWithSender(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig, sender func(*string, *string) error) error { +func (d *DummyModel) AudioSpeechWithSender(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig, sender func(*string, *string) error) error { - return fmt.Errorf("%s, no such method", z.Name()) + return fmt.Errorf("%s, no such method", d.Name()) }Also applies to: 96-98
🤖 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/dummy.go` around lines 87 - 89, The receiver name for DummyModel methods (e.g., TranscribeAudioWithSender and the other method around lines 96-98) is inconsistent: it uses "z" while the rest of the file uses "d"; change the receiver from "z *DummyModel" to "d *DummyModel" for those methods (match other methods' receiver naming), and update any references inside those methods to use "d" (for example the call to Name() should be d.Name()) so naming is consistent across the file.internal/entity/models/ollama.go (2)
23-26: ⚡ Quick winReplace panic with error return.
The
ParseFile()stub currently panics. Consider returning an error instead for graceful handling.♻️ Proposed fix to return error instead of panic
func (o *OllamaModel) ParseFile() { - //TODO implement me - panic("implement me") + // TODO: implement me + return fmt.Errorf("%s, ParseFile not implemented", o.Name()) }Note: This will require updating the
ParseFile()method signature in theModelDriverinterface to returnerror.🤖 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/ollama.go` around lines 23 - 26, The OllamaModel.ParseFile method currently panics; change it to return an error instead and remove the panic to allow graceful handling: update the OllamaModel.ParseFile method signature to return error, replace the panic with a descriptive error return (e.g., fmt.Errorf("ParseFile not implemented for OllamaModel")), and update the ModelDriver interface's ParseFile signature to return error; then update all callers of ModelDriver.ParseFile to handle the returned error appropriately. Ensure you import fmt (or use errors) where needed and run tests to fix call sites.
458-460: ⚡ Quick winFix inconsistent receiver variable names.
The receiver variables use inconsistent names (
zon lines 458, 467 andmon line 472) instead ofo, which is used throughout the rest of the file.♻️ Proposed fix for consistent receiver naming
-func (z *OllamaModel) TranscribeAudioWithSender(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig, sender func(*string, *string) error) error { +func (o *OllamaModel) TranscribeAudioWithSender(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig, sender func(*string, *string) error) error { - return fmt.Errorf("%s, no such method", z.Name()) + return fmt.Errorf("%s, no such method", o.Name()) }-func (z *OllamaModel) AudioSpeechWithSender(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig, sender func(*string, *string) error) error { +func (o *OllamaModel) AudioSpeechWithSender(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig, sender func(*string, *string) error) error { - return fmt.Errorf("%s, no such method", z.Name()) + return fmt.Errorf("%s, no such method", o.Name()) }-func (m *OllamaModel) OCRFile(modelName *string, fileContent *string, apiConfig *APIConfig, ocrConfig *OCRConfig) (*OCRResponse, error) { +func (o *OllamaModel) OCRFile(modelName *string, fileContent *string, apiConfig *APIConfig, ocrConfig *OCRConfig) (*OCRResponse, error) { - return nil, fmt.Errorf("%s, no such method", m.Name()) + return nil, fmt.Errorf("%s, no such method", o.Name()) }Also applies to: 467-469, 472-474
🤖 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/ollama.go` around lines 458 - 460, Several methods on the OllamaModel use inconsistent receiver names (`z` and `m`) instead of the file-wide convention `o`; update the method declarations for TranscribeAudioWithSender and the other affected methods to use receiver `o *OllamaModel` and replace any internal uses of `z` or `m` with `o` so the receiver name is consistent across the file (e.g., change func (z *OllamaModel) TranscribeAudioWithSender(...) to func (o *OllamaModel) TranscribeAudioWithSender(...) and similarly for the other methods referenced).internal/entity/models/gitee.go (2)
606-608: ⚡ Quick winFix inconsistent receiver variable names.
The receiver variables on lines 606 and 615 use
zinstead ofg, which is inconsistent with the rest of the file.♻️ Proposed fix for consistent receiver naming
-func (z *GiteeModel) TranscribeAudioWithSender(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig, sender func(*string, *string) error) error { +func (g *GiteeModel) TranscribeAudioWithSender(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig, sender func(*string, *string) error) error { - return fmt.Errorf("%s, no such method", z.Name()) + return fmt.Errorf("%s, no such method", g.Name()) }-func (z *GiteeModel) AudioSpeechWithSender(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig, sender func(*string, *string) error) error { +func (g *GiteeModel) AudioSpeechWithSender(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig, sender func(*string, *string) error) error { - return fmt.Errorf("%s, no such method", z.Name()) + return fmt.Errorf("%s, no such method", g.Name()) }Also applies to: 615-617
🤖 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/gitee.go` around lines 606 - 608, The receiver variable is inconsistent: change the receiver from "z" to "g" in the GiteeModel methods (e.g., TranscribeAudioWithSender and the related TranscribeAudio method) so they match the rest of the file’s receiver naming; update all uses inside those functions (e.g., z.Name()) to use g.Name() and ensure the function signatures and any references use the same receiver name.
39-42: ⚡ Quick winReplace panic with error return.
The
ParseFile()stub currently panics, which will crash the application if called. Consider returning an error instead for graceful handling.♻️ Proposed fix to return error instead of panic
func (g *GiteeModel) ParseFile() { - //TODO implement me - panic("implement me") + // TODO: implement me + return fmt.Errorf("%s, ParseFile not implemented", g.Name()) }Note: This will require updating the
ParseFile()method signature in theModelDriverinterface to returnerror.🤖 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/gitee.go` around lines 39 - 42, The ParseFile method on GiteeModel currently panics; change its behavior to return an error by updating the ParseFile signature to return error (e.g., ParseFile() error) both on GiteeModel and in the ModelDriver interface, replace the panic("implement me") with a proper implementation that returns either nil on success or a descriptive error on failure, and update all other types that implement ModelDriver to match the new signature so callers can handle errors gracefully.internal/entity/models/siliconflow.go (2)
730-732: ⚡ Quick winFix inconsistent receiver variable names.
The new stub methods use inconsistent receiver variables (
oon lines 730, 739;zon lines 734, 743;mon line 748). The file uses bothsandzelsewhere, but the new methods should be consistent.♻️ Proposed fix for consistent receiver naming
Consider using
sconsistently since that's what's used inNewSiliconflowModelandParseFile:-func (o *SiliconflowModel) TranscribeAudio(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig) (*ASRResponse, error) { +func (s *SiliconflowModel) TranscribeAudio(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig) (*ASRResponse, error) { - return nil, fmt.Errorf("%s, no such method", o.Name()) + return nil, fmt.Errorf("%s, no such method", s.Name()) } -func (z *SiliconflowModel) TranscribeAudioWithSender(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig, sender func(*string, *string) error) error { +func (s *SiliconflowModel) TranscribeAudioWithSender(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig, sender func(*string, *string) error) error { - return fmt.Errorf("%s, no such method", z.Name()) + return fmt.Errorf("%s, no such method", s.Name()) } -func (o *SiliconflowModel) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, asrConfig *TTSConfig) (*TTSResponse, error) { +func (s *SiliconflowModel) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, asrConfig *TTSConfig) (*TTSResponse, error) { - return nil, fmt.Errorf("%s, no such method", o.Name()) + return nil, fmt.Errorf("%s, no such method", s.Name()) } -func (z *SiliconflowModel) AudioSpeechWithSender(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig, sender func(*string, *string) error) error { +func (s *SiliconflowModel) AudioSpeechWithSender(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig, sender func(*string, *string) error) error { - return fmt.Errorf("%s, no such method", z.Name()) + return fmt.Errorf("%s, no such method", s.Name()) } -func (m *SiliconflowModel) OCRFile(modelName *string, fileContent *string, apiConfig *APIConfig, ocrConfig *OCRConfig) (*OCRResponse, error) { +func (s *SiliconflowModel) OCRFile(modelName *string, fileContent *string, apiConfig *APIConfig, ocrConfig *OCRConfig) (*OCRResponse, error) { - return nil, fmt.Errorf("%s, no such method", m.Name()) + return nil, fmt.Errorf("%s, no such method", s.Name()) }Also applies to: 734-736, 739-741, 743-745, 748-750
🤖 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/siliconflow.go` around lines 730 - 732, The new stub methods (e.g., TranscribeAudio, and the other stubbed transcribe methods) use inconsistent receiver names like o, z, and m; update each method receiver to use the same identifier used elsewhere in this file (use s to match NewSiliconflowModel and ParseFile) so all methods have a consistent receiver signature (e.g., change func (o *SiliconflowModel) TranscribeAudio(...) to func (s *SiliconflowModel) TranscribeAudio(...), and do the same for the other stub methods).
39-42: ⚡ Quick winReplace panic with error return.
The
ParseFile()stub currently panics. Consider returning an error instead for graceful handling.♻️ Proposed fix to return error instead of panic
func (s *SiliconflowModel) ParseFile() { - //TODO implement me - panic("implement me") + // TODO: implement me + return fmt.Errorf("%s, ParseFile not implemented", s.Name()) }Note: This will require updating the
ParseFile()method signature in theModelDriverinterface to returnerror.🤖 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/siliconflow.go` around lines 39 - 42, Replace the panic in SiliconflowModel.ParseFile with an error return: change ParseFile to return error, implement a graceful default behavior (e.g., return fmt.Errorf("ParseFile not implemented for SiliconflowModel") or real parsing logic) and remove panic("implement me"); update the ModelDriver interface signature to have ParseFile() error and update all implementers/call sites to handle the returned error (propagate or handle appropriately) so the code no longer panics.internal/entity/models/zhipu-ai.go (1)
615-617: ⚡ Quick winFix inconsistent receiver variable names.
The new stub methods use inconsistent receiver variables (
oon lines 615, 624 andmon line 633) instead ofz, which is used consistently throughout the rest of the file.♻️ Proposed fix for consistent receiver naming
-func (o *ZhipuAIModel) TranscribeAudio(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig) (*ASRResponse, error) { +func (z *ZhipuAIModel) TranscribeAudio(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig) (*ASRResponse, error) { - return nil, fmt.Errorf("%s, no such method", o.Name()) + return nil, fmt.Errorf("%s, no such method", z.Name()) }-func (o *ZhipuAIModel) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, asrConfig *TTSConfig) (*TTSResponse, error) { +func (z *ZhipuAIModel) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, asrConfig *TTSConfig) (*TTSResponse, error) { - return nil, fmt.Errorf("%s, no such method", o.Name()) + return nil, fmt.Errorf("%s, no such method", z.Name()) }-func (m *ZhipuAIModel) OCRFile(modelName *string, fileContent *string, apiConfig *APIConfig, ocrConfig *OCRConfig) (*OCRResponse, error) { +func (z *ZhipuAIModel) OCRFile(modelName *string, fileContent *string, apiConfig *APIConfig, ocrConfig *OCRConfig) (*OCRResponse, error) { - return nil, fmt.Errorf("%s, no such method", m.Name()) + return nil, fmt.Errorf("%s, no such method", z.Name()) }Also applies to: 624-626, 633-635
🤖 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/zhipu-ai.go` around lines 615 - 617, The stub methods on ZhipuAIModel use inconsistent receiver names ("o" and "m") instead of the file's standard "z"; update the receiver of TranscribeAudio and the other ZhipuAIModel stub methods to use "z" (e.g., change "func (o *ZhipuAIModel) TranscribeAudio..." and any "func (m *ZhipuAIModel) ..." stubs to "func (z *ZhipuAIModel) ...") so the receiver naming is consistent with the rest of the file.internal/entity/models/cohere.go (2)
20-23: ⚡ Quick winReplace panic with error return.
The
ParseFile()stub currently panics. Consider returning an error instead for graceful handling.♻️ Proposed fix to return error instead of panic
func (c *CoHereModel) ParseFile() { - //TODO implement me - panic("implement me") + // TODO: implement me + return fmt.Errorf("%s, ParseFile not implemented", c.Name()) }Note: This will require updating the
ParseFile()method signature in theModelDriverinterface to returnerror.🤖 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/cohere.go` around lines 20 - 23, Replace the panic in CoHereModel.ParseFile with an error-returning implementation: change the ParseFile method on CoHereModel to return error (e.g., func (c *CoHereModel) ParseFile() error), update the ModelDriver interface to reflect the new signature, replace panic("implement me") with a sensible default return (either nil if no error or an appropriate error value) and update all callers to handle the returned error; ensure any tests or usages of ParseFile are updated to check the error result.
493-495: ⚡ Quick winFix inconsistent receiver variable names.
The receiver variables on lines 493 and 502 use
zinstead ofc, which is inconsistent with the rest of the file.♻️ Proposed fix for consistent receiver naming
-func (z *CoHereModel) TranscribeAudioWithSender(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig, sender func(*string, *string) error) error { +func (c *CoHereModel) TranscribeAudioWithSender(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig, sender func(*string, *string) error) error { - return fmt.Errorf("%s, no such method", z.Name()) + return fmt.Errorf("%s, no such method", c.Name()) }-func (z *CoHereModel) AudioSpeechWithSender(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig, sender func(*string, *string) error) error { +func (c *CoHereModel) AudioSpeechWithSender(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig, sender func(*string, *string) error) error { - return fmt.Errorf("%s, no such method", z.Name()) + return fmt.Errorf("%s, no such method", c.Name()) }Also applies to: 502-504
🤖 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/cohere.go` around lines 493 - 495, The methods TranscribeAudioWithSender and the other CoHereModel methods in this file use the receiver name z which is inconsistent with the rest of the file; change the receiver from z to c for CoHereModel methods (e.g., func (z *CoHereModel) TranscribeAudioWithSender(...) -> func (c *CoHereModel) TranscribeAudioWithSender(...)) and update any uses of the receiver inside those methods to c so the receiver naming matches the rest of the CoHereModel implementations.internal/cli/user_parser.go (2)
2811-2840: ⚡ Quick winAdd optional semicolon handling for consistency.
parseASRCommand(lines 2764-2767) andparseTTSCommand(lines 2800-2803) both include optional semicolon handling, butparseOCRCommanddoes not. For consistency, add the same semicolon handling.♻️ Proposed fix
file, err := p.parseQuotedString() if err != nil { return nil, err } p.nextToken() + + // Semicolon is optional + if p.curToken.Type == TokenSemicolon { + p.nextToken() + } cmd := NewCommand("ocr_user_command") cmd.Params["composite_model_name"] = compositeModelName cmd.Params["file"] = file return cmd, nil }🤖 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/cli/user_parser.go` around lines 2811 - 2840, parseOCRCommand currently lacks the optional semicolon handling present in parseASRCommand and parseTTSCommand; update parseOCRCommand to accept and consume an optional TokenSemicolon after consuming the FILE argument (i.e., after the second p.nextToken()/parseQuotedString sequence) by checking if p.curToken.Type == TokenSemicolon and calling p.nextToken() so the parser behavior is consistent with parseASRCommand and parseTTSCommand.
2583-2617: 💤 Low valueClarify OCR streaming support in error message.
Line 2612 states
"expected CHAT, THINK, ASR, or TTS after STREAM", but aparseOCRCommandmethod exists (lines 2811-2840). Either:
- OCR should be added to the switch statement if streaming is supported, or
- The error message should clarify that OCR is not streamable (if that's intentional).
Consider adding a comment explaining why OCR is excluded from streaming if that's the intended design.
🤖 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/cli/user_parser.go` around lines 2583 - 2617, The parseStreamCommand function currently only handles TokenChat, TokenThink, TokenASR, and TokenTTS but parseOCRCommand exists; either add streaming support or clarify intent: if OCR is streamable, add a case TokenOCR that calls p.parseOCRCommand() mirroring the other branches and set command.Params["stream"]=true; if OCR is intentionally non-streamable, update the default error string to mention OCR is not supported for streaming (e.g. "expected CHAT, THINK, ASR, or TTS after STREAM; OCR is not streamable") and add a brief inline comment near parseStreamCommand explaining why OCR is excluded. Ensure you reference parseStreamCommand, parseOCRCommand, and TokenOCR/TokenChat/TokenThink/TokenASR/TokenTTS when making the change.internal/service/model_service.go (2)
1207-1291: ⚡ Quick winAdd input validation for audioFile parameter.
The method doesn't validate that
audioFileis non-nil and non-empty before proceeding. This validation should be added for consistency with other service methods.♻️ Proposed fix
func (m *ModelProviderService) TranscribeAudioStream(providerName, instanceName, modelName, userID string, audioFile *string, apiConfig *modelModule.APIConfig, asrConfig *modelModule.ASRConfig, sender func(*string, *string) error) (common.ErrorCode, error) { + if audioFile == nil || *audioFile == "" { + return common.CodeBadRequest, errors.New("audio file is required") + } + // Get tenant ID from user tenants, err := m.userTenantDAO.GetByUserIDAndRole(userID, "owner")🤖 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/service/model_service.go` around lines 1207 - 1291, Add a guard at the start of TranscribeAudioStream to validate the audioFile parameter: ensure audioFile is not nil and *audioFile is not the empty string, and if it fails return an appropriate input error (e.g. common.CodeInvalidArgument and an error like "audio file is required"). Place this check before any provider/instance/model lookup so callers fail fast; update any callers/tests if they expect different error codes.
1396-1480: ⚡ Quick winAdd input validation for audioContent parameter.
The method doesn't validate that
audioContentis non-nil and non-empty before proceeding. This validation should be added for consistency with other service methods.♻️ Proposed fix
func (m *ModelProviderService) AudioSpeechStream(providerName, instanceName, modelName, userID string, audioContent *string, apiConfig *modelModule.APIConfig, ttsConfig *modelModule.TTSConfig, sender func(*string, *string) error) (common.ErrorCode, error) { + if audioContent == nil || *audioContent == "" { + return common.CodeBadRequest, errors.New("audio content is required") + } + // Get tenant ID from user tenants, err := m.userTenantDAO.GetByUserIDAndRole(userID, "owner")🤖 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/service/model_service.go` around lines 1396 - 1480, In AudioSpeechStream add an early input validation for the audioContent parameter (e.g., immediately after tenant resolution) that returns a parameter error when audioContent is nil or empty; specifically check if audioContent == nil || len(*audioContent) == 0 and return an appropriate error code (use the project standard like common.CodeInvalidParams or common.CodeBadRequest) and an explanatory error, so the method bails out before provider/instance/model lookups when no audio data is supplied.internal/cli/user_command.go (1)
1964-1999: ⚡ Quick winRemove or implement commented-out code.
There are two blocks of commented-out code related to file handling (lines 1964-1967 for parameter extraction and lines 1994-1999 for file saving). If file output is not yet implemented, consider removing these comments or tracking the feature separately. Leaving commented code can clutter the codebase.
🤖 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/cli/user_command.go` around lines 1964 - 1999, Either remove the stale commented-out file handling or re-enable and implement it: read the "file" param from cmd.Params into fileToSave (e.g., fileToSave, ok := cmd.Params["file"].(string); handle missing param with an error return), then after setting result.Duration write the audio bytes with os.WriteFile(fileToSave, resp.Body, 0644) and on write error append to result.Message and set result.Code = 1 (or return an error as appropriate); ensure you import "os" if enabling this and keep JSON unmarshalling of resp.Body separate from saving raw bytes if needed (e.g., use resp.Body raw for file or expect the API to return audio bytes rather than JSON).
🤖 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/cli/user_command.go`:
- Around line 2033-2036: The error message for extracting audioFile from
cmd.Params is a copy-paste mistake: when audioFile, ok :=
cmd.Params["audio_file"].(string) fails, update the returned error in that
branch to indicate the audio file is missing (e.g., "audio file not provided" or
"audio_file not provided") instead of "text not provided" so the message matches
the checked parameter and variable audioFile.
- Around line 2095-2098: The error message in the file parameter check is a
copy-paste mistake: change the returned error in the block that checks filename,
ok := cmd.Params["file"].(string) (in user_command.go) from "text not provided"
to "file not provided" so the message matches the parameter being validated;
update the fmt.Errorf call inside that conditional to return a clear "file not
provided" error.
- Around line 1626-1628: The error message on the audios type-assertion is a
copy-paste mistake — update the fmt.Errorf call in the block that checks audios,
where audios, ok := cmd.Params["audios"].([]string), to return an error message
"audios not provided" (replace the incorrect "images not provided") so the error
matches the checked parameter and aids correct diagnostics.
In `@internal/entity/models/baichuan.go`:
- Around line 392-395: The comment and parameter in BaichuanModel.AudioSpeech
are misleading: change the comment to reflect Text-to-Speech (convert text to
audio) instead of "convert audio to text", rename the input parameter
audioContent to textContent (and its pointer type usage) to match TTS semantics
and TTSConfig, and update any local references and callers of AudioSpeech
accordingly; keep the function behavior (returning nil, fmt.Errorf) but ensure
the error message still references z.Name() and the new parameter name where
applicable.
In `@internal/entity/models/baidu.go`:
- Around line 585-588: The function AudioSpeech currently has a misleading
comment and an inconsistent parameter name (asrConfig) for a TTS operation;
update the comment to reflect that AudioSpeech converts text to audio (TTS) and
rename the parameter from asrConfig to ttsConfig (or a clearly TTS-specific
name) in the AudioSpeech signature and any internal references, ensuring
APIConfig/TTSConfig types remain correct and the error return still uses
b.Name() unchanged.
In `@internal/entity/models/deepseek.go`:
- Around line 602-605: The comment above DeepSeekModel.AudioSpeech is wrong and
some parameter names are inconsistent with TTS semantics; change the comment to
describe Text-to-Speech (TTS) — e.g., "Text-to-speech (TTS) convert text to
audio" — and rename parameters to reflect TTS input: replace audioContent with
textContent and asrConfig with ttsConfig (while keeping types TTSResponse and
TTSConfig unchanged) so the signature DeepSeekModel.AudioSpeech(modelName
*string, textContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig)
accurately reflects behavior.
In `@internal/entity/models/fishaudio.go`:
- Around line 74-77: The comment and parameter name are inconsistent with this
method's TTS intent: update the comment on FishAudioModel.AudioSpeech to
"AudioSpeech converts text to speech (TTS)" (or equivalent clearly stating TTS),
rename the parameter asrConfig to ttsConfig so its name matches the TTSConfig
type, and update any callers/usages of AudioSpeech to use the new parameter
name; leave the method body/return as-is other than the renaming.
In `@internal/entity/models/google.go`:
- Around line 353-355: Receiver naming is inconsistent: change the receiver
variable from "z" to "g" on the GoogleModel methods that currently use "z"
(notably TranscribeAudioWithSender and the other method around the 362-364
range) so they match the rest of the file; update the method signatures (e.g.,
func (z *GoogleModel) TranscribeAudioWithSender(...) error) to use (g
*GoogleModel) and adjust any uses of the receiver inside those methods to "g".
In `@internal/entity/models/lmstudio.go`:
- Around line 464-467: The comment and parameter name on
LmStudioModel.AudioSpeech are misleading: update the doc comment to indicate
this is text-to-speech (converts text to audio) instead of "convert audio to
text", and rename the parameter from asrConfig to ttsConfig to match its type
(*TTSConfig) and the existing AudioSpeechWithSender method; ensure the function
signature and any internal references use ttsConfig consistently to avoid naming
mismatch.
In `@internal/entity/models/minimax.go`:
- Around line 465-468: The function MinimaxModel.AudioSpeech is documented and
parameterized as if it did ASR, but its return type is TTSResponse and it
accepts a TTSConfig; update the comment to "AudioSpeech converts text to speech
(TTS)", rename the parameter audioContent to textContent, and rename asrConfig
to ttsConfig (keeping its type TTSConfig) so names match behavior; update any
uses of AudioSpeech to pass/expect textContent and ttsConfig accordingly and
keep the existing error return unchanged.
In `@internal/entity/models/nvidia.go`:
- Around line 22-25: The ParseFile implementation for NvidiaModel currently
panics; replace the panic with a safe non-panicking flow in
NvidiaModel.ParseFile by implementing a no-op (or an early return) and
optionally logging that Nvidia provider parsing is unsupported (use whatever
package logger is available, e.g., processLogger or a local logger) so the
server won't crash if this code path is hit; ensure the method signature remains
unchanged and does not panic.
In `@internal/entity/models/openai.go`:
- Around line 611-614: Update the misleading comment and parameter name on
OpenAIModel.AudioSpeech: change the comment from "convert audio to text" to
"convert text to audio (TTS)" and rename the third/fourth parameter from
asrConfig to ttsConfig to match the *TTSConfig type and align with
AudioSpeechWithSender; ensure the function signature and any internal references
use ttsConfig and the comment accurately describes TTS behavior for
OpenAIModel.AudioSpeech.
In `@internal/entity/models/types.go`:
- Around line 32-33: Update the misleading comment for the AudioSpeech method:
replace "convert audio to text" with a clear TTS description such as "convert
text to audio (text-to-speech)" and ensure it references the method signature
AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig,
asrConfig *TTSConfig) returning (*TTSResponse, error) so readers understand this
is a text-to-speech function.
In `@internal/entity/models/volcengine.go`:
- Around line 522-525: The function VolcEngine.AudioSpeech has a misleading
comment and an incorrect parameter name: change the comment to reflect
Text-to-Speech (TTS) instead of "convert audio to text" and rename the parameter
from asrConfig to ttsConfig in the AudioSpeech signature and all internal uses
within that function (and any callers), updating any related variable names and
docs to match TTS semantics (e.g., use *TTSConfig ttsConfig and a comment like
"AudioSpeech performs text-to-speech").
In `@internal/service/model_service.go`:
- Around line 1104-1204: In TranscribeAudio, add input validation at the top to
ensure audioFile is non-nil and not an empty string (return common.CodeNotFound
or appropriate error if invalid), then update the two nil-response error
messages from "empty chat response" to "empty ASR response" where
providerInfo.ModelDriver.TranscribeAudio (the provider fallback branch) and
newProviderInfo.TranscribeAudio (the active/local branch) return a nil
*modelModule.ASRResponse; keep existing error codes (common.CodeServerError)
when returning these messages.
- Around line 1482-1582: In OCRFile, validate fileContent at the start (ensure
fileContent != nil and strings.TrimSpace(*fileContent) != "") and return an
appropriate client error (e.g., common.CodeInvalidArgument or the project's
equivalent) with a descriptive error if validation fails; also replace both
occurrences of the error message "empty chat response" (the checks where
response == nil) with "empty OCR response" so the message matches the operation
(references: function ModelProviderService.OCRFile, parameter fileContent, local
variable response).
- Around line 1294-1394: In ModelProviderService.AudioSpeech: add input
validation to return common.CodeServerError with a clear error when audioContent
is nil or points to an empty string (check audioContent == nil ||
strings.TrimSpace(*audioContent) == "") before any provider/instance lookups,
and replace both occurrences of the error text "empty chat response" (the checks
after providerInfo.ModelDriver.AudioSpeech and newProviderInfo.AudioSpeech where
response == nil) with "empty TTS response"; reference the audioContent param and
the local variable response so the changes are easy to locate.
---
Nitpick comments:
In `@internal/cli/user_command.go`:
- Around line 1964-1999: Either remove the stale commented-out file handling or
re-enable and implement it: read the "file" param from cmd.Params into
fileToSave (e.g., fileToSave, ok := cmd.Params["file"].(string); handle missing
param with an error return), then after setting result.Duration write the audio
bytes with os.WriteFile(fileToSave, resp.Body, 0644) and on write error append
to result.Message and set result.Code = 1 (or return an error as appropriate);
ensure you import "os" if enabling this and keep JSON unmarshalling of resp.Body
separate from saving raw bytes if needed (e.g., use resp.Body raw for file or
expect the API to return audio bytes rather than JSON).
In `@internal/cli/user_parser.go`:
- Around line 2811-2840: parseOCRCommand currently lacks the optional semicolon
handling present in parseASRCommand and parseTTSCommand; update parseOCRCommand
to accept and consume an optional TokenSemicolon after consuming the FILE
argument (i.e., after the second p.nextToken()/parseQuotedString sequence) by
checking if p.curToken.Type == TokenSemicolon and calling p.nextToken() so the
parser behavior is consistent with parseASRCommand and parseTTSCommand.
- Around line 2583-2617: The parseStreamCommand function currently only handles
TokenChat, TokenThink, TokenASR, and TokenTTS but parseOCRCommand exists; either
add streaming support or clarify intent: if OCR is streamable, add a case
TokenOCR that calls p.parseOCRCommand() mirroring the other branches and set
command.Params["stream"]=true; if OCR is intentionally non-streamable, update
the default error string to mention OCR is not supported for streaming (e.g.
"expected CHAT, THINK, ASR, or TTS after STREAM; OCR is not streamable") and add
a brief inline comment near parseStreamCommand explaining why OCR is excluded.
Ensure you reference parseStreamCommand, parseOCRCommand, and
TokenOCR/TokenChat/TokenThink/TokenASR/TokenTTS when making the change.
In `@internal/entity/models/cohere.go`:
- Around line 20-23: Replace the panic in CoHereModel.ParseFile with an
error-returning implementation: change the ParseFile method on CoHereModel to
return error (e.g., func (c *CoHereModel) ParseFile() error), update the
ModelDriver interface to reflect the new signature, replace panic("implement
me") with a sensible default return (either nil if no error or an appropriate
error value) and update all callers to handle the returned error; ensure any
tests or usages of ParseFile are updated to check the error result.
- Around line 493-495: The methods TranscribeAudioWithSender and the other
CoHereModel methods in this file use the receiver name z which is inconsistent
with the rest of the file; change the receiver from z to c for CoHereModel
methods (e.g., func (z *CoHereModel) TranscribeAudioWithSender(...) -> func (c
*CoHereModel) TranscribeAudioWithSender(...)) and update any uses of the
receiver inside those methods to c so the receiver naming matches the rest of
the CoHereModel implementations.
In `@internal/entity/models/dummy.go`:
- Around line 29-32: The ParseFile method on DummyModel should not panic; change
DummyModel.ParseFile to return an error (e.g., fmt.Errorf("not implemented"))
instead of calling panic, and update the ModelDriver interface's ParseFile
signature to return error so callers can handle it; also update any other types
that implement ModelDriver to match the new signature (adjust function
signatures and return fmt.Errorf("not implemented") where appropriate) and
import fmt if needed.
- Around line 87-89: The receiver name for DummyModel methods (e.g.,
TranscribeAudioWithSender and the other method around lines 96-98) is
inconsistent: it uses "z" while the rest of the file uses "d"; change the
receiver from "z *DummyModel" to "d *DummyModel" for those methods (match other
methods' receiver naming), and update any references inside those methods to use
"d" (for example the call to Name() should be d.Name()) so naming is consistent
across the file.
In `@internal/entity/models/gitee.go`:
- Around line 606-608: The receiver variable is inconsistent: change the
receiver from "z" to "g" in the GiteeModel methods (e.g.,
TranscribeAudioWithSender and the related TranscribeAudio method) so they match
the rest of the file’s receiver naming; update all uses inside those functions
(e.g., z.Name()) to use g.Name() and ensure the function signatures and any
references use the same receiver name.
- Around line 39-42: The ParseFile method on GiteeModel currently panics; change
its behavior to return an error by updating the ParseFile signature to return
error (e.g., ParseFile() error) both on GiteeModel and in the ModelDriver
interface, replace the panic("implement me") with a proper implementation that
returns either nil on success or a descriptive error on failure, and update all
other types that implement ModelDriver to match the new signature so callers can
handle errors gracefully.
In `@internal/entity/models/moonshot.go`:
- Around line 38-41: The ParseFile() method on MoonshotModel currently panics;
change it to return an error instead: update the MoonshotModel.ParseFile
implementation to perform its parsing work and return nil on success or an error
on failure (no panics), and update the ModelDriver interface's ParseFile
signature to return error so callers can handle failures gracefully; ensure all
implementations of ModelDriver are updated to match the new signature and adjust
any callers to check and propagate the returned error.
- Around line 515-517: The method OCRFile on type MoonshotModel uses receiver
variable "m" inconsistent with the rest of the file which uses "z"; change the
receiver in the function signature from "m *MoonshotModel" to "z *MoonshotModel"
(i.e., update func (m *MoonshotModel) OCRFile(...) to func (z *MoonshotModel)
OCRFile(...)) so the method's receiver name matches other methods and references
to the receiver inside the function (use z.Name() if applicable).
In `@internal/entity/models/ollama.go`:
- Around line 23-26: The OllamaModel.ParseFile method currently panics; change
it to return an error instead and remove the panic to allow graceful handling:
update the OllamaModel.ParseFile method signature to return error, replace the
panic with a descriptive error return (e.g., fmt.Errorf("ParseFile not
implemented for OllamaModel")), and update the ModelDriver interface's ParseFile
signature to return error; then update all callers of ModelDriver.ParseFile to
handle the returned error appropriately. Ensure you import fmt (or use errors)
where needed and run tests to fix call sites.
- Around line 458-460: Several methods on the OllamaModel use inconsistent
receiver names (`z` and `m`) instead of the file-wide convention `o`; update the
method declarations for TranscribeAudioWithSender and the other affected methods
to use receiver `o *OllamaModel` and replace any internal uses of `z` or `m`
with `o` so the receiver name is consistent across the file (e.g., change func
(z *OllamaModel) TranscribeAudioWithSender(...) to func (o *OllamaModel)
TranscribeAudioWithSender(...) and similarly for the other methods referenced).
In `@internal/entity/models/siliconflow.go`:
- Around line 730-732: The new stub methods (e.g., TranscribeAudio, and the
other stubbed transcribe methods) use inconsistent receiver names like o, z, and
m; update each method receiver to use the same identifier used elsewhere in this
file (use s to match NewSiliconflowModel and ParseFile) so all methods have a
consistent receiver signature (e.g., change func (o *SiliconflowModel)
TranscribeAudio(...) to func (s *SiliconflowModel) TranscribeAudio(...), and do
the same for the other stub methods).
- Around line 39-42: Replace the panic in SiliconflowModel.ParseFile with an
error return: change ParseFile to return error, implement a graceful default
behavior (e.g., return fmt.Errorf("ParseFile not implemented for
SiliconflowModel") or real parsing logic) and remove panic("implement me");
update the ModelDriver interface signature to have ParseFile() error and update
all implementers/call sites to handle the returned error (propagate or handle
appropriately) so the code no longer panics.
In `@internal/entity/models/zhipu-ai.go`:
- Around line 615-617: The stub methods on ZhipuAIModel use inconsistent
receiver names ("o" and "m") instead of the file's standard "z"; update the
receiver of TranscribeAudio and the other ZhipuAIModel stub methods to use "z"
(e.g., change "func (o *ZhipuAIModel) TranscribeAudio..." and any "func (m
*ZhipuAIModel) ..." stubs to "func (z *ZhipuAIModel) ...") so the receiver
naming is consistent with the rest of the file.
In `@internal/service/model_service.go`:
- Around line 1207-1291: Add a guard at the start of TranscribeAudioStream to
validate the audioFile parameter: ensure audioFile is not nil and *audioFile is
not the empty string, and if it fails return an appropriate input error (e.g.
common.CodeInvalidArgument and an error like "audio file is required"). Place
this check before any provider/instance/model lookup so callers fail fast;
update any callers/tests if they expect different error codes.
- Around line 1396-1480: In AudioSpeechStream add an early input validation for
the audioContent parameter (e.g., immediately after tenant resolution) that
returns a parameter error when audioContent is nil or empty; specifically check
if audioContent == nil || len(*audioContent) == 0 and return an appropriate
error code (use the project standard like common.CodeInvalidParams or
common.CodeBadRequest) and an explanatory error, so the method bails out before
provider/instance/model lookups when no audio data is supplied.
🪄 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: d617b13d-6ab6-4502-9917-5779968a361b
📒 Files selected for processing (32)
internal/cli/client.gointernal/cli/parser.gointernal/cli/user_command.gointernal/cli/user_parser.gointernal/entity/models/aliyun.gointernal/entity/models/baichuan.gointernal/entity/models/baidu.gointernal/entity/models/cohere.gointernal/entity/models/deepseek.gointernal/entity/models/dummy.gointernal/entity/models/fishaudio.gointernal/entity/models/gitee.gointernal/entity/models/google.gointernal/entity/models/huggingface.gointernal/entity/models/lmstudio.gointernal/entity/models/minimax.gointernal/entity/models/moonshot.gointernal/entity/models/nvidia.gointernal/entity/models/ollama.gointernal/entity/models/openai.gointernal/entity/models/openrouter.gointernal/entity/models/siliconflow.gointernal/entity/models/stepfun.gointernal/entity/models/types.gointernal/entity/models/upstage.gointernal/entity/models/vllm.gointernal/entity/models/volcengine.gointernal/entity/models/xai.gointernal/entity/models/zhipu-ai.gointernal/handler/providers.gointernal/router/router.gointernal/service/model_service.go
| audios, ok := cmd.Params["audios"].([]string) | ||
| if !ok { | ||
| return nil, fmt.Errorf("images not provided") |
There was a problem hiding this comment.
Fix copy-paste error in error message.
The error message says "images not provided" but should say "audios not provided" to match the parameter being checked.
📝 Proposed fix
audios, ok := cmd.Params["audios"].([]string)
if !ok {
- return nil, fmt.Errorf("images not provided")
+ return nil, fmt.Errorf("audios not provided")
}📝 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.
| audios, ok := cmd.Params["audios"].([]string) | |
| if !ok { | |
| return nil, fmt.Errorf("images not provided") | |
| audios, ok := cmd.Params["audios"].([]string) | |
| if !ok { | |
| return nil, fmt.Errorf("audios not provided") |
🤖 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/cli/user_command.go` around lines 1626 - 1628, The error message on
the audios type-assertion is a copy-paste mistake — update the fmt.Errorf call
in the block that checks audios, where audios, ok :=
cmd.Params["audios"].([]string), to return an error message "audios not
provided" (replace the incorrect "images not provided") so the error matches the
checked parameter and aids correct diagnostics.
| audioFile, ok := cmd.Params["audio_file"].(string) | ||
| if !ok { | ||
| return nil, fmt.Errorf("text not provided") | ||
| } |
There was a problem hiding this comment.
Fix copy-paste error in error message.
The error message says "text not provided" but should say "audio file not provided" to match the parameter being checked.
📝 Proposed fix
audioFile, ok := cmd.Params["audio_file"].(string)
if !ok {
- return nil, fmt.Errorf("text not provided")
+ return nil, fmt.Errorf("audio file not provided")
}📝 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.
| audioFile, ok := cmd.Params["audio_file"].(string) | |
| if !ok { | |
| return nil, fmt.Errorf("text not provided") | |
| } | |
| audioFile, ok := cmd.Params["audio_file"].(string) | |
| if !ok { | |
| return nil, fmt.Errorf("audio file not provided") | |
| } |
🤖 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/cli/user_command.go` around lines 2033 - 2036, The error message for
extracting audioFile from cmd.Params is a copy-paste mistake: when audioFile, ok
:= cmd.Params["audio_file"].(string) fails, update the returned error in that
branch to indicate the audio file is missing (e.g., "audio file not provided" or
"audio_file not provided") instead of "text not provided" so the message matches
the checked parameter and variable audioFile.
| filename, ok := cmd.Params["file"].(string) | ||
| if !ok { | ||
| return nil, fmt.Errorf("text not provided") | ||
| } |
There was a problem hiding this comment.
Fix copy-paste error in error message.
The error message says "text not provided" but should say "file not provided" to match the parameter being checked.
📝 Proposed fix
filename, ok := cmd.Params["file"].(string)
if !ok {
- return nil, fmt.Errorf("text not provided")
+ return nil, fmt.Errorf("file not provided")
}📝 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.
| filename, ok := cmd.Params["file"].(string) | |
| if !ok { | |
| return nil, fmt.Errorf("text not provided") | |
| } | |
| filename, ok := cmd.Params["file"].(string) | |
| if !ok { | |
| return nil, fmt.Errorf("file not provided") | |
| } |
🤖 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/cli/user_command.go` around lines 2095 - 2098, The error message in
the file parameter check is a copy-paste mistake: change the returned error in
the block that checks filename, ok := cmd.Params["file"].(string) (in
user_command.go) from "text not provided" to "file not provided" so the message
matches the parameter being validated; update the fmt.Errorf call inside that
conditional to return a clear "file not provided" error.
| // AudioSpeech convert audio to text | ||
| func (z *BaichuanModel) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, asrConfig *TTSConfig) (*TTSResponse, error) { | ||
| return nil, fmt.Errorf("%s, no such method", z.Name()) | ||
| } |
There was a problem hiding this comment.
Correct the misleading comment and parameter name.
Same issue: incorrect comment direction for TTS, and parameter naming inconsistency.
📝 Proposed fix
-// AudioSpeech convert audio to text
-func (z *BaichuanModel) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, asrConfig *TTSConfig) (*TTSResponse, error) {
+// AudioSpeech converts text to audio (text-to-speech synthesis)
+func (z *BaichuanModel) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig) (*TTSResponse, error) {
return nil, fmt.Errorf("%s, no such method", z.Name())
}🤖 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/baichuan.go` around lines 392 - 395, The comment and
parameter in BaichuanModel.AudioSpeech are misleading: change the comment to
reflect Text-to-Speech (convert text to audio) instead of "convert audio to
text", rename the input parameter audioContent to textContent (and its pointer
type usage) to match TTS semantics and TTSConfig, and update any local
references and callers of AudioSpeech accordingly; keep the function behavior
(returning nil, fmt.Errorf) but ensure the error message still references
z.Name() and the new parameter name where applicable.
| // AudioSpeech convert audio to text | ||
| func (b *BaiduModel) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, asrConfig *TTSConfig) (*TTSResponse, error) { | ||
| return nil, fmt.Errorf("%s, no such method", b.Name()) | ||
| } |
There was a problem hiding this comment.
Correct the misleading comment and parameter name.
Same issue: incorrect comment direction for TTS, and parameter naming inconsistency.
📝 Proposed fix
-// AudioSpeech convert audio to text
-func (b *BaiduModel) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, asrConfig *TTSConfig) (*TTSResponse, error) {
+// AudioSpeech converts text to audio (text-to-speech synthesis)
+func (b *BaiduModel) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig) (*TTSResponse, error) {
return nil, fmt.Errorf("%s, no such method", b.Name())
}📝 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.
| // AudioSpeech convert audio to text | |
| func (b *BaiduModel) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, asrConfig *TTSConfig) (*TTSResponse, error) { | |
| return nil, fmt.Errorf("%s, no such method", b.Name()) | |
| } | |
| // AudioSpeech converts text to audio (text-to-speech synthesis) | |
| func (b *BaiduModel) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig) (*TTSResponse, error) { | |
| return nil, fmt.Errorf("%s, no such method", b.Name()) | |
| } |
🤖 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/baidu.go` around lines 585 - 588, The function
AudioSpeech currently has a misleading comment and an inconsistent parameter
name (asrConfig) for a TTS operation; update the comment to reflect that
AudioSpeech converts text to audio (TTS) and rename the parameter from asrConfig
to ttsConfig (or a clearly TTS-specific name) in the AudioSpeech signature and
any internal references, ensuring APIConfig/TTSConfig types remain correct and
the error return still uses b.Name() unchanged.
| // AudioSpeech convert audio to text | ||
| AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, asrConfig *TTSConfig) (*TTSResponse, error) |
There was a problem hiding this comment.
Fix incorrect comment for AudioSpeech.
The comment on line 32 says "convert audio to text", but AudioSpeech is a text-to-speech (TTS) method that converts text to audio, not the other way around.
📝 Proposed fix for the comment
- // AudioSpeech convert audio to text
+ // AudioSpeech converts text to audio (TTS)
AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, asrConfig *TTSConfig) (*TTSResponse, error)📝 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.
| // AudioSpeech convert audio to text | |
| AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, asrConfig *TTSConfig) (*TTSResponse, error) | |
| // AudioSpeech converts text to audio (TTS) | |
| AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, asrConfig *TTSConfig) (*TTSResponse, error) |
🤖 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/types.go` around lines 32 - 33, Update the misleading
comment for the AudioSpeech method: replace "convert audio to text" with a clear
TTS description such as "convert text to audio (text-to-speech)" and ensure it
references the method signature AudioSpeech(modelName *string, audioContent
*string, apiConfig *APIConfig, asrConfig *TTSConfig) returning (*TTSResponse,
error) so readers understand this is a text-to-speech function.
| // AudioSpeech convert audio to text | ||
| func (o *VolcEngine) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, asrConfig *TTSConfig) (*TTSResponse, error) { | ||
| return nil, fmt.Errorf("%s, no such method", o.Name()) | ||
| } |
There was a problem hiding this comment.
Correct the misleading comment and parameter name.
Same issue: the comment incorrectly states "convert audio to text" for a TTS operation, and the parameter should be ttsConfig not asrConfig.
📝 Proposed fix
-// AudioSpeech convert audio to text
-func (o *VolcEngine) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, asrConfig *TTSConfig) (*TTSResponse, error) {
+// AudioSpeech converts text to audio (text-to-speech synthesis)
+func (o *VolcEngine) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig) (*TTSResponse, error) {
return nil, fmt.Errorf("%s, no such method", o.Name())
}📝 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.
| // AudioSpeech convert audio to text | |
| func (o *VolcEngine) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, asrConfig *TTSConfig) (*TTSResponse, error) { | |
| return nil, fmt.Errorf("%s, no such method", o.Name()) | |
| } | |
| // AudioSpeech converts text to audio (text-to-speech synthesis) | |
| func (o *VolcEngine) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig) (*TTSResponse, error) { | |
| return nil, fmt.Errorf("%s, no such method", o.Name()) | |
| } |
🤖 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/volcengine.go` around lines 522 - 525, The function
VolcEngine.AudioSpeech has a misleading comment and an incorrect parameter name:
change the comment to reflect Text-to-Speech (TTS) instead of "convert audio to
text" and rename the parameter from asrConfig to ttsConfig in the AudioSpeech
signature and all internal uses within that function (and any callers), updating
any related variable names and docs to match TTS semantics (e.g., use *TTSConfig
ttsConfig and a comment like "AudioSpeech performs text-to-speech").
| func (m *ModelProviderService) TranscribeAudio(providerName, instanceName, modelName, userID string, audioFile *string, apiConfig *modelModule.APIConfig, asrConfig *modelModule.ASRConfig) (*modelModule.ASRResponse, common.ErrorCode, error) { | ||
| if apiConfig == nil { | ||
| apiConfig = &modelModule.APIConfig{} | ||
| } | ||
| if asrConfig == nil { | ||
| asrConfig = &modelModule.ASRConfig{} | ||
| } | ||
|
|
||
| // Get tenant ID from user | ||
| tenants, err := m.userTenantDAO.GetByUserIDAndRole(userID, "owner") | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
|
|
||
| if len(tenants) == 0 { | ||
| return nil, common.CodeNotFound, errors.New("user has no tenants") | ||
| } | ||
|
|
||
| tenantID := tenants[0].TenantID | ||
|
|
||
| // Check if provider exists | ||
| provider, err := m.modelProviderDAO.GetByTenantIDAndProviderName(tenantID, providerName) | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
|
|
||
| instance, err := m.modelInstanceDAO.GetByProviderIDAndInstanceName(provider.ID, instanceName) | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
|
|
||
| modelInfo, err := m.modelDAO.GetModelByProviderIDAndInstanceIDAndModelName(provider.ID, instance.ID, modelName) | ||
| if err != nil { | ||
| providerInfo := dao.GetModelProviderManager().FindProvider(providerName) | ||
| if providerInfo == nil { | ||
| return nil, common.CodeNotFound, errors.New("provider not found") | ||
| } | ||
|
|
||
| _, err = dao.GetModelProviderManager().GetModelByName(providerName, modelName) | ||
| if err != nil { | ||
| return nil, common.CodeNotFound, errors.New(fmt.Sprintf("provider %s model %s not found", providerName, modelName)) | ||
| } | ||
|
|
||
| var extra map[string]string | ||
| err = json.Unmarshal([]byte(instance.Extra), &extra) | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
|
|
||
| region := extra["region"] | ||
| apiConfig.Region = ®ion | ||
| apiConfig.ApiKey = &instance.APIKey | ||
|
|
||
| var response *modelModule.ASRResponse | ||
| response, err = providerInfo.ModelDriver.TranscribeAudio(&modelName, audioFile, apiConfig, asrConfig) | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
| if response == nil { | ||
| return nil, common.CodeServerError, errors.New("empty chat response") | ||
| } | ||
|
|
||
| return response, common.CodeSuccess, nil | ||
| } | ||
|
|
||
| if modelInfo.Status == "active" { | ||
| // For local deployed models | ||
| providerInfo := dao.GetModelProviderManager().FindProvider(providerName) | ||
| if providerInfo == nil { | ||
| return nil, common.CodeNotFound, errors.New("provider not found") | ||
| } | ||
|
|
||
| var extra map[string]string | ||
| err = json.Unmarshal([]byte(instance.Extra), &extra) | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
|
|
||
| region := extra["region"] | ||
| apiConfig.Region = ®ion | ||
| apiConfig.ApiKey = &instance.APIKey | ||
|
|
||
| newURL := map[string]string{ | ||
| region: extra["base_url"], | ||
| } | ||
| newProviderInfo := providerInfo.ModelDriver.NewInstance(newURL) | ||
|
|
||
| var response *modelModule.ASRResponse | ||
| response, err = newProviderInfo.TranscribeAudio(&modelName, audioFile, apiConfig, asrConfig) | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
| if response == nil { | ||
| return nil, common.CodeServerError, errors.New("empty chat response") | ||
| } | ||
|
|
||
| return response, common.CodeSuccess, nil | ||
| } | ||
|
|
||
| return nil, common.CodeServerError, errors.New("model is disabled") | ||
| } |
There was a problem hiding this comment.
Fix error messages and add input validation.
- Lines 1163 and 1197: The error messages say
"empty chat response"but should say"empty ASR response"to match the actual operation. - Missing validation: The method doesn't validate that
audioFileis non-nil and non-empty before proceeding. Consider adding validation at the start of the method.
🐛 Proposed fix
func (m *ModelProviderService) TranscribeAudio(providerName, instanceName, modelName, userID string, audioFile *string, apiConfig *modelModule.APIConfig, asrConfig *modelModule.ASRConfig) (*modelModule.ASRResponse, common.ErrorCode, error) {
if apiConfig == nil {
apiConfig = &modelModule.APIConfig{}
}
if asrConfig == nil {
asrConfig = &modelModule.ASRConfig{}
}
+ if audioFile == nil || *audioFile == "" {
+ return nil, common.CodeBadRequest, errors.New("audio file is required")
+ }
// Get tenant ID from user
tenants, err := m.userTenantDAO.GetByUserIDAndRole(userID, "owner")And fix the error messages:
if response == nil {
- return nil, common.CodeServerError, errors.New("empty chat response")
+ return nil, common.CodeServerError, errors.New("empty ASR response")
} if response == nil {
- return nil, common.CodeServerError, errors.New("empty chat response")
+ return nil, common.CodeServerError, errors.New("empty ASR response")
}📝 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.
| func (m *ModelProviderService) TranscribeAudio(providerName, instanceName, modelName, userID string, audioFile *string, apiConfig *modelModule.APIConfig, asrConfig *modelModule.ASRConfig) (*modelModule.ASRResponse, common.ErrorCode, error) { | |
| if apiConfig == nil { | |
| apiConfig = &modelModule.APIConfig{} | |
| } | |
| if asrConfig == nil { | |
| asrConfig = &modelModule.ASRConfig{} | |
| } | |
| // Get tenant ID from user | |
| tenants, err := m.userTenantDAO.GetByUserIDAndRole(userID, "owner") | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| if len(tenants) == 0 { | |
| return nil, common.CodeNotFound, errors.New("user has no tenants") | |
| } | |
| tenantID := tenants[0].TenantID | |
| // Check if provider exists | |
| provider, err := m.modelProviderDAO.GetByTenantIDAndProviderName(tenantID, providerName) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| instance, err := m.modelInstanceDAO.GetByProviderIDAndInstanceName(provider.ID, instanceName) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| modelInfo, err := m.modelDAO.GetModelByProviderIDAndInstanceIDAndModelName(provider.ID, instance.ID, modelName) | |
| if err != nil { | |
| providerInfo := dao.GetModelProviderManager().FindProvider(providerName) | |
| if providerInfo == nil { | |
| return nil, common.CodeNotFound, errors.New("provider not found") | |
| } | |
| _, err = dao.GetModelProviderManager().GetModelByName(providerName, modelName) | |
| if err != nil { | |
| return nil, common.CodeNotFound, errors.New(fmt.Sprintf("provider %s model %s not found", providerName, modelName)) | |
| } | |
| var extra map[string]string | |
| err = json.Unmarshal([]byte(instance.Extra), &extra) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| region := extra["region"] | |
| apiConfig.Region = ®ion | |
| apiConfig.ApiKey = &instance.APIKey | |
| var response *modelModule.ASRResponse | |
| response, err = providerInfo.ModelDriver.TranscribeAudio(&modelName, audioFile, apiConfig, asrConfig) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| if response == nil { | |
| return nil, common.CodeServerError, errors.New("empty chat response") | |
| } | |
| return response, common.CodeSuccess, nil | |
| } | |
| if modelInfo.Status == "active" { | |
| // For local deployed models | |
| providerInfo := dao.GetModelProviderManager().FindProvider(providerName) | |
| if providerInfo == nil { | |
| return nil, common.CodeNotFound, errors.New("provider not found") | |
| } | |
| var extra map[string]string | |
| err = json.Unmarshal([]byte(instance.Extra), &extra) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| region := extra["region"] | |
| apiConfig.Region = ®ion | |
| apiConfig.ApiKey = &instance.APIKey | |
| newURL := map[string]string{ | |
| region: extra["base_url"], | |
| } | |
| newProviderInfo := providerInfo.ModelDriver.NewInstance(newURL) | |
| var response *modelModule.ASRResponse | |
| response, err = newProviderInfo.TranscribeAudio(&modelName, audioFile, apiConfig, asrConfig) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| if response == nil { | |
| return nil, common.CodeServerError, errors.New("empty chat response") | |
| } | |
| return response, common.CodeSuccess, nil | |
| } | |
| return nil, common.CodeServerError, errors.New("model is disabled") | |
| } | |
| func (m *ModelProviderService) TranscribeAudio(providerName, instanceName, modelName, userID string, audioFile *string, apiConfig *modelModule.APIConfig, asrConfig *modelModule.ASRConfig) (*modelModule.ASRResponse, common.ErrorCode, error) { | |
| if apiConfig == nil { | |
| apiConfig = &modelModule.APIConfig{} | |
| } | |
| if asrConfig == nil { | |
| asrConfig = &modelModule.ASRConfig{} | |
| } | |
| if audioFile == nil || *audioFile == "" { | |
| return nil, common.CodeBadRequest, errors.New("audio file is required") | |
| } | |
| // Get tenant ID from user | |
| tenants, err := m.userTenantDAO.GetByUserIDAndRole(userID, "owner") | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| if len(tenants) == 0 { | |
| return nil, common.CodeNotFound, errors.New("user has no tenants") | |
| } | |
| tenantID := tenants[0].TenantID | |
| // Check if provider exists | |
| provider, err := m.modelProviderDAO.GetByTenantIDAndProviderName(tenantID, providerName) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| instance, err := m.modelInstanceDAO.GetByProviderIDAndInstanceName(provider.ID, instanceName) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| modelInfo, err := m.modelDAO.GetModelByProviderIDAndInstanceIDAndModelName(provider.ID, instance.ID, modelName) | |
| if err != nil { | |
| providerInfo := dao.GetModelProviderManager().FindProvider(providerName) | |
| if providerInfo == nil { | |
| return nil, common.CodeNotFound, errors.New("provider not found") | |
| } | |
| _, err = dao.GetModelProviderManager().GetModelByName(providerName, modelName) | |
| if err != nil { | |
| return nil, common.CodeNotFound, errors.New(fmt.Sprintf("provider %s model %s not found", providerName, modelName)) | |
| } | |
| var extra map[string]string | |
| err = json.Unmarshal([]byte(instance.Extra), &extra) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| region := extra["region"] | |
| apiConfig.Region = ®ion | |
| apiConfig.ApiKey = &instance.APIKey | |
| var response *modelModule.ASRResponse | |
| response, err = providerInfo.ModelDriver.TranscribeAudio(&modelName, audioFile, apiConfig, asrConfig) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| if response == nil { | |
| return nil, common.CodeServerError, errors.New("empty ASR response") | |
| } | |
| return response, common.CodeSuccess, nil | |
| } | |
| if modelInfo.Status == "active" { | |
| // For local deployed models | |
| providerInfo := dao.GetModelProviderManager().FindProvider(providerName) | |
| if providerInfo == nil { | |
| return nil, common.CodeNotFound, errors.New("provider not found") | |
| } | |
| var extra map[string]string | |
| err = json.Unmarshal([]byte(instance.Extra), &extra) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| region := extra["region"] | |
| apiConfig.Region = ®ion | |
| apiConfig.ApiKey = &instance.APIKey | |
| newURL := map[string]string{ | |
| region: extra["base_url"], | |
| } | |
| newProviderInfo := providerInfo.ModelDriver.NewInstance(newURL) | |
| var response *modelModule.ASRResponse | |
| response, err = newProviderInfo.TranscribeAudio(&modelName, audioFile, apiConfig, asrConfig) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| if response == nil { | |
| return nil, common.CodeServerError, errors.New("empty ASR response") | |
| } | |
| return response, common.CodeSuccess, nil | |
| } | |
| return nil, common.CodeServerError, errors.New("model is disabled") | |
| } |
🤖 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/service/model_service.go` around lines 1104 - 1204, In
TranscribeAudio, add input validation at the top to ensure audioFile is non-nil
and not an empty string (return common.CodeNotFound or appropriate error if
invalid), then update the two nil-response error messages from "empty chat
response" to "empty ASR response" where providerInfo.ModelDriver.TranscribeAudio
(the provider fallback branch) and newProviderInfo.TranscribeAudio (the
active/local branch) return a nil *modelModule.ASRResponse; keep existing error
codes (common.CodeServerError) when returning these messages.
| func (m *ModelProviderService) AudioSpeech(providerName, instanceName, modelName, userID string, audioContent *string, apiConfig *modelModule.APIConfig, ttsConfig *modelModule.TTSConfig) (*modelModule.TTSResponse, common.ErrorCode, error) { | ||
| if apiConfig == nil { | ||
| apiConfig = &modelModule.APIConfig{} | ||
| } | ||
| if ttsConfig == nil { | ||
| ttsConfig = &modelModule.TTSConfig{} | ||
| } | ||
|
|
||
| // Get tenant ID from user | ||
| tenants, err := m.userTenantDAO.GetByUserIDAndRole(userID, "owner") | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
|
|
||
| if len(tenants) == 0 { | ||
| return nil, common.CodeNotFound, errors.New("user has no tenants") | ||
| } | ||
|
|
||
| tenantID := tenants[0].TenantID | ||
|
|
||
| // Check if provider exists | ||
| provider, err := m.modelProviderDAO.GetByTenantIDAndProviderName(tenantID, providerName) | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
|
|
||
| instance, err := m.modelInstanceDAO.GetByProviderIDAndInstanceName(provider.ID, instanceName) | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
|
|
||
| modelInfo, err := m.modelDAO.GetModelByProviderIDAndInstanceIDAndModelName(provider.ID, instance.ID, modelName) | ||
| if err != nil { | ||
| providerInfo := dao.GetModelProviderManager().FindProvider(providerName) | ||
| if providerInfo == nil { | ||
| return nil, common.CodeNotFound, errors.New("provider not found") | ||
| } | ||
|
|
||
| _, err = dao.GetModelProviderManager().GetModelByName(providerName, modelName) | ||
| if err != nil { | ||
| return nil, common.CodeNotFound, errors.New(fmt.Sprintf("provider %s model %s not found", providerName, modelName)) | ||
| } | ||
|
|
||
| var extra map[string]string | ||
| err = json.Unmarshal([]byte(instance.Extra), &extra) | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
|
|
||
| region := extra["region"] | ||
| apiConfig.Region = ®ion | ||
| apiConfig.ApiKey = &instance.APIKey | ||
|
|
||
| var response *modelModule.TTSResponse | ||
| response, err = providerInfo.ModelDriver.AudioSpeech(&modelName, audioContent, apiConfig, ttsConfig) | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
| if response == nil { | ||
| return nil, common.CodeServerError, errors.New("empty chat response") | ||
| } | ||
|
|
||
| return response, common.CodeSuccess, nil | ||
| } | ||
|
|
||
| if modelInfo.Status == "active" { | ||
| // For local deployed models | ||
| providerInfo := dao.GetModelProviderManager().FindProvider(providerName) | ||
| if providerInfo == nil { | ||
| return nil, common.CodeNotFound, errors.New("provider not found") | ||
| } | ||
|
|
||
| var extra map[string]string | ||
| err = json.Unmarshal([]byte(instance.Extra), &extra) | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
|
|
||
| region := extra["region"] | ||
| apiConfig.Region = ®ion | ||
| apiConfig.ApiKey = &instance.APIKey | ||
|
|
||
| newURL := map[string]string{ | ||
| region: extra["base_url"], | ||
| } | ||
| newProviderInfo := providerInfo.ModelDriver.NewInstance(newURL) | ||
|
|
||
| var response *modelModule.TTSResponse | ||
| response, err = newProviderInfo.AudioSpeech(&modelName, audioContent, apiConfig, ttsConfig) | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
| if response == nil { | ||
| return nil, common.CodeServerError, errors.New("empty chat response") | ||
| } | ||
|
|
||
| return response, common.CodeSuccess, nil | ||
| } | ||
|
|
||
| return nil, common.CodeServerError, errors.New("model is disabled") | ||
| } |
There was a problem hiding this comment.
Fix error messages and add input validation.
- Lines 1353 and 1387: The error messages say
"empty chat response"but should say"empty TTS response"to match the actual operation. - Missing validation: The method doesn't validate that
audioContentis non-nil and non-empty before proceeding.
🐛 Proposed fix
func (m *ModelProviderService) AudioSpeech(providerName, instanceName, modelName, userID string, audioContent *string, apiConfig *modelModule.APIConfig, ttsConfig *modelModule.TTSConfig) (*modelModule.TTSResponse, common.ErrorCode, error) {
if apiConfig == nil {
apiConfig = &modelModule.APIConfig{}
}
if ttsConfig == nil {
ttsConfig = &modelModule.TTSConfig{}
}
+ if audioContent == nil || *audioContent == "" {
+ return nil, common.CodeBadRequest, errors.New("audio content is required")
+ }
// Get tenant ID from user
tenants, err := m.userTenantDAO.GetByUserIDAndRole(userID, "owner")And fix the error messages:
if response == nil {
- return nil, common.CodeServerError, errors.New("empty chat response")
+ return nil, common.CodeServerError, errors.New("empty TTS response")
} if response == nil {
- return nil, common.CodeServerError, errors.New("empty chat response")
+ return nil, common.CodeServerError, errors.New("empty TTS response")
}🤖 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/service/model_service.go` around lines 1294 - 1394, In
ModelProviderService.AudioSpeech: add input validation to return
common.CodeServerError with a clear error when audioContent is nil or points to
an empty string (check audioContent == nil || strings.TrimSpace(*audioContent)
== "") before any provider/instance lookups, and replace both occurrences of the
error text "empty chat response" (the checks after
providerInfo.ModelDriver.AudioSpeech and newProviderInfo.AudioSpeech where
response == nil) with "empty TTS response"; reference the audioContent param and
the local variable response so the changes are easy to locate.
| func (m *ModelProviderService) OCRFile(providerName, instanceName, modelName, userID string, fileContent *string, apiConfig *modelModule.APIConfig, ocrConfig *modelModule.OCRConfig) (*modelModule.OCRResponse, common.ErrorCode, error) { | ||
| if apiConfig == nil { | ||
| apiConfig = &modelModule.APIConfig{} | ||
| } | ||
| if ocrConfig == nil { | ||
| ocrConfig = &modelModule.OCRConfig{} | ||
| } | ||
|
|
||
| // Get tenant ID from user | ||
| tenants, err := m.userTenantDAO.GetByUserIDAndRole(userID, "owner") | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
|
|
||
| if len(tenants) == 0 { | ||
| return nil, common.CodeNotFound, errors.New("user has no tenants") | ||
| } | ||
|
|
||
| tenantID := tenants[0].TenantID | ||
|
|
||
| // Check if provider exists | ||
| provider, err := m.modelProviderDAO.GetByTenantIDAndProviderName(tenantID, providerName) | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
|
|
||
| instance, err := m.modelInstanceDAO.GetByProviderIDAndInstanceName(provider.ID, instanceName) | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
|
|
||
| modelInfo, err := m.modelDAO.GetModelByProviderIDAndInstanceIDAndModelName(provider.ID, instance.ID, modelName) | ||
| if err != nil { | ||
| providerInfo := dao.GetModelProviderManager().FindProvider(providerName) | ||
| if providerInfo == nil { | ||
| return nil, common.CodeNotFound, errors.New("provider not found") | ||
| } | ||
|
|
||
| _, err = dao.GetModelProviderManager().GetModelByName(providerName, modelName) | ||
| if err != nil { | ||
| return nil, common.CodeNotFound, errors.New(fmt.Sprintf("provider %s model %s not found", providerName, modelName)) | ||
| } | ||
|
|
||
| var extra map[string]string | ||
| err = json.Unmarshal([]byte(instance.Extra), &extra) | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
|
|
||
| region := extra["region"] | ||
| apiConfig.Region = ®ion | ||
| apiConfig.ApiKey = &instance.APIKey | ||
|
|
||
| var response *modelModule.OCRResponse | ||
| response, err = providerInfo.ModelDriver.OCRFile(&modelName, fileContent, apiConfig, ocrConfig) | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
| if response == nil { | ||
| return nil, common.CodeServerError, errors.New("empty chat response") | ||
| } | ||
|
|
||
| return response, common.CodeSuccess, nil | ||
| } | ||
|
|
||
| if modelInfo.Status == "active" { | ||
| // For local deployed models | ||
| providerInfo := dao.GetModelProviderManager().FindProvider(providerName) | ||
| if providerInfo == nil { | ||
| return nil, common.CodeNotFound, errors.New("provider not found") | ||
| } | ||
|
|
||
| var extra map[string]string | ||
| err = json.Unmarshal([]byte(instance.Extra), &extra) | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
|
|
||
| region := extra["region"] | ||
| apiConfig.Region = ®ion | ||
| apiConfig.ApiKey = &instance.APIKey | ||
|
|
||
| newURL := map[string]string{ | ||
| region: extra["base_url"], | ||
| } | ||
| newProviderInfo := providerInfo.ModelDriver.NewInstance(newURL) | ||
|
|
||
| var response *modelModule.OCRResponse | ||
| response, err = newProviderInfo.OCRFile(&modelName, fileContent, apiConfig, ocrConfig) | ||
| if err != nil { | ||
| return nil, common.CodeServerError, err | ||
| } | ||
| if response == nil { | ||
| return nil, common.CodeServerError, errors.New("empty chat response") | ||
| } | ||
|
|
||
| return response, common.CodeSuccess, nil | ||
| } | ||
|
|
||
| return nil, common.CodeServerError, errors.New("model is disabled") | ||
| } |
There was a problem hiding this comment.
Fix error messages and add input validation.
- Lines 1541 and 1575: The error messages say
"empty chat response"but should say"empty OCR response"to match the actual operation. - Missing validation: The method doesn't validate that
fileContentis non-nil and non-empty before proceeding.
🐛 Proposed fix
func (m *ModelProviderService) OCRFile(providerName, instanceName, modelName, userID string, fileContent *string, apiConfig *modelModule.APIConfig, ocrConfig *modelModule.OCRConfig) (*modelModule.OCRResponse, common.ErrorCode, error) {
if apiConfig == nil {
apiConfig = &modelModule.APIConfig{}
}
if ocrConfig == nil {
ocrConfig = &modelModule.OCRConfig{}
}
+ if fileContent == nil || *fileContent == "" {
+ return nil, common.CodeBadRequest, errors.New("file content is required")
+ }
// Get tenant ID from user
tenants, err := m.userTenantDAO.GetByUserIDAndRole(userID, "owner")And fix the error messages:
if response == nil {
- return nil, common.CodeServerError, errors.New("empty chat response")
+ return nil, common.CodeServerError, errors.New("empty OCR response")
} if response == nil {
- return nil, common.CodeServerError, errors.New("empty chat response")
+ return nil, common.CodeServerError, errors.New("empty OCR response")
}📝 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.
| func (m *ModelProviderService) OCRFile(providerName, instanceName, modelName, userID string, fileContent *string, apiConfig *modelModule.APIConfig, ocrConfig *modelModule.OCRConfig) (*modelModule.OCRResponse, common.ErrorCode, error) { | |
| if apiConfig == nil { | |
| apiConfig = &modelModule.APIConfig{} | |
| } | |
| if ocrConfig == nil { | |
| ocrConfig = &modelModule.OCRConfig{} | |
| } | |
| // Get tenant ID from user | |
| tenants, err := m.userTenantDAO.GetByUserIDAndRole(userID, "owner") | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| if len(tenants) == 0 { | |
| return nil, common.CodeNotFound, errors.New("user has no tenants") | |
| } | |
| tenantID := tenants[0].TenantID | |
| // Check if provider exists | |
| provider, err := m.modelProviderDAO.GetByTenantIDAndProviderName(tenantID, providerName) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| instance, err := m.modelInstanceDAO.GetByProviderIDAndInstanceName(provider.ID, instanceName) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| modelInfo, err := m.modelDAO.GetModelByProviderIDAndInstanceIDAndModelName(provider.ID, instance.ID, modelName) | |
| if err != nil { | |
| providerInfo := dao.GetModelProviderManager().FindProvider(providerName) | |
| if providerInfo == nil { | |
| return nil, common.CodeNotFound, errors.New("provider not found") | |
| } | |
| _, err = dao.GetModelProviderManager().GetModelByName(providerName, modelName) | |
| if err != nil { | |
| return nil, common.CodeNotFound, errors.New(fmt.Sprintf("provider %s model %s not found", providerName, modelName)) | |
| } | |
| var extra map[string]string | |
| err = json.Unmarshal([]byte(instance.Extra), &extra) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| region := extra["region"] | |
| apiConfig.Region = ®ion | |
| apiConfig.ApiKey = &instance.APIKey | |
| var response *modelModule.OCRResponse | |
| response, err = providerInfo.ModelDriver.OCRFile(&modelName, fileContent, apiConfig, ocrConfig) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| if response == nil { | |
| return nil, common.CodeServerError, errors.New("empty chat response") | |
| } | |
| return response, common.CodeSuccess, nil | |
| } | |
| if modelInfo.Status == "active" { | |
| // For local deployed models | |
| providerInfo := dao.GetModelProviderManager().FindProvider(providerName) | |
| if providerInfo == nil { | |
| return nil, common.CodeNotFound, errors.New("provider not found") | |
| } | |
| var extra map[string]string | |
| err = json.Unmarshal([]byte(instance.Extra), &extra) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| region := extra["region"] | |
| apiConfig.Region = ®ion | |
| apiConfig.ApiKey = &instance.APIKey | |
| newURL := map[string]string{ | |
| region: extra["base_url"], | |
| } | |
| newProviderInfo := providerInfo.ModelDriver.NewInstance(newURL) | |
| var response *modelModule.OCRResponse | |
| response, err = newProviderInfo.OCRFile(&modelName, fileContent, apiConfig, ocrConfig) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| if response == nil { | |
| return nil, common.CodeServerError, errors.New("empty chat response") | |
| } | |
| return response, common.CodeSuccess, nil | |
| } | |
| return nil, common.CodeServerError, errors.New("model is disabled") | |
| } | |
| func (m *ModelProviderService) OCRFile(providerName, instanceName, modelName, userID string, fileContent *string, apiConfig *modelModule.APIConfig, ocrConfig *modelModule.OCRConfig) (*modelModule.OCRResponse, common.ErrorCode, error) { | |
| if apiConfig == nil { | |
| apiConfig = &modelModule.APIConfig{} | |
| } | |
| if ocrConfig == nil { | |
| ocrConfig = &modelModule.OCRConfig{} | |
| } | |
| if fileContent == nil || *fileContent == "" { | |
| return nil, common.CodeBadRequest, errors.New("file content is required") | |
| } | |
| // Get tenant ID from user | |
| tenants, err := m.userTenantDAO.GetByUserIDAndRole(userID, "owner") | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| if len(tenants) == 0 { | |
| return nil, common.CodeNotFound, errors.New("user has no tenants") | |
| } | |
| tenantID := tenants[0].TenantID | |
| // Check if provider exists | |
| provider, err := m.modelProviderDAO.GetByTenantIDAndProviderName(tenantID, providerName) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| instance, err := m.modelInstanceDAO.GetByProviderIDAndInstanceName(provider.ID, instanceName) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| modelInfo, err := m.modelDAO.GetModelByProviderIDAndInstanceIDAndModelName(provider.ID, instance.ID, modelName) | |
| if err != nil { | |
| providerInfo := dao.GetModelProviderManager().FindProvider(providerName) | |
| if providerInfo == nil { | |
| return nil, common.CodeNotFound, errors.New("provider not found") | |
| } | |
| _, err = dao.GetModelProviderManager().GetModelByName(providerName, modelName) | |
| if err != nil { | |
| return nil, common.CodeNotFound, errors.New(fmt.Sprintf("provider %s model %s not found", providerName, modelName)) | |
| } | |
| var extra map[string]string | |
| err = json.Unmarshal([]byte(instance.Extra), &extra) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| region := extra["region"] | |
| apiConfig.Region = ®ion | |
| apiConfig.ApiKey = &instance.APIKey | |
| var response *modelModule.OCRResponse | |
| response, err = providerInfo.ModelDriver.OCRFile(&modelName, fileContent, apiConfig, ocrConfig) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| if response == nil { | |
| return nil, common.CodeServerError, errors.New("empty OCR response") | |
| } | |
| return response, common.CodeSuccess, nil | |
| } | |
| if modelInfo.Status == "active" { | |
| // For local deployed models | |
| providerInfo := dao.GetModelProviderManager().FindProvider(providerName) | |
| if providerInfo == nil { | |
| return nil, common.CodeNotFound, errors.New("provider not found") | |
| } | |
| var extra map[string]string | |
| err = json.Unmarshal([]byte(instance.Extra), &extra) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| region := extra["region"] | |
| apiConfig.Region = ®ion | |
| apiConfig.ApiKey = &instance.APIKey | |
| newURL := map[string]string{ | |
| region: extra["base_url"], | |
| } | |
| newProviderInfo := providerInfo.ModelDriver.NewInstance(newURL) | |
| var response *modelModule.OCRResponse | |
| response, err = newProviderInfo.OCRFile(&modelName, fileContent, apiConfig, ocrConfig) | |
| if err != nil { | |
| return nil, common.CodeServerError, err | |
| } | |
| if response == nil { | |
| return nil, common.CodeServerError, errors.New("empty OCR response") | |
| } | |
| return response, common.CodeSuccess, nil | |
| } | |
| return nil, common.CodeServerError, errors.New("model is disabled") | |
| } |
🤖 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/service/model_service.go` around lines 1482 - 1582, In OCRFile,
validate fileContent at the start (ensure fileContent != nil and
strings.TrimSpace(*fileContent) != "") and return an appropriate client error
(e.g., common.CodeInvalidArgument or the project's equivalent) with a
descriptive error if validation fails; also replace both occurrences of the
error message "empty chat response" (the checks where response == nil) with
"empty OCR response" so the message matches the operation (references: function
ModelProviderService.OCRFile, parameter fileContent, local variable response).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14836 +/- ##
=======================================
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:
|
### What problem does this PR solve? ``` RAGFlow(user)> asr with 'glm-asr-2512@test@zhipu-ai' audio './speech.wav'; CLI error: zhipu, no such method RAGFlow(user)> stream asr with 'glm-asr-2512@test@zhipu-ai' audio './speech.wav'; CLI error: zhipu, no such method RAGFlow(user)> tts with 'glm-tts@test@zhipu-ai' text 'how are you'; CLI error: zhipu, no such method RAGFlow(user)> stream tts with 'glm-tts@test@zhipu-ai' text 'how are you'; CLI error: zhipu, no such method RAGFlow(user)> ocr with 'glm-ocr@test@zhipu-ai' file './test.log'; CLI error: zhipu, no such method ``` ### Type of change - [x] New Feature (non-breaking change which adds functionality) Signed-off-by: Jin Hai <[email protected]>
What problem does this PR solve?
Type of change