Go: validate Baidu OCR inputs (#15168)

### What problem does this PR solve?

Closes #15167.

The Baidu Go provider advertises OCR support through
`paddleocr-vl-0.9b`, but `BaiduModel.OCRFile` dereferenced required
inputs before validating them. Calling OCR with a missing API config,
API key, or model name could panic instead of returning a normal error.

This PR adds explicit input validation for those required values.

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

---------

Co-authored-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Renzo
2026-05-26 09:51:05 +07:00
committed by GitHub
parent b961810e79
commit 806414df43

View File

@@ -638,6 +638,12 @@ func (b *BaiduModel) OCRFile(modelName *string, content []byte, fileURL *string,
if (fileURL == nil || *fileURL == "") && (content == nil || len(content) == 0) {
return nil, fmt.Errorf("image url or content is required")
}
if apiConfig == nil || apiConfig.ApiKey == nil || *apiConfig.ApiKey == "" {
return nil, fmt.Errorf("api key is required")
}
if modelName == nil || *modelName == "" {
return nil, fmt.Errorf("model name is required")
}
region := "default"
if apiConfig.Region != nil && *apiConfig.Region != "" {