mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-09-08 10:14:35 +08:00
Refactor[Go Model Provider]: refactor baseURL and modelConfig (#15627)
### What problem does this PR solve? As Title ### Type of change - [x] Refactoring
This commit is contained in:
@@ -29,39 +29,28 @@ import (
|
||||
)
|
||||
|
||||
type PaddleOCRLocalModel struct {
|
||||
BaseURL map[string]string
|
||||
URLSuffix URLSuffix
|
||||
httpClient *http.Client
|
||||
baseModel BaseModel
|
||||
}
|
||||
|
||||
func NewPaddleOCRLocalModel(baseURL map[string]string, urlSuffix URLSuffix) *PaddleOCRLocalModel {
|
||||
return &PaddleOCRLocalModel{
|
||||
BaseURL: baseURL,
|
||||
URLSuffix: urlSuffix,
|
||||
httpClient: &http.Client{
|
||||
Transport: &http.Transport{
|
||||
MaxIdleConns: 10,
|
||||
MaxIdleConnsPerHost: 100,
|
||||
IdleConnTimeout: time.Second * 90,
|
||||
DisableCompression: false,
|
||||
baseModel: BaseModel{
|
||||
BaseURL: baseURL,
|
||||
URLSuffix: urlSuffix,
|
||||
httpClient: &http.Client{
|
||||
Transport: &http.Transport{
|
||||
MaxIdleConns: 10,
|
||||
MaxIdleConnsPerHost: 100,
|
||||
IdleConnTimeout: time.Second * 90,
|
||||
DisableCompression: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PaddleOCRLocalModel) NewInstance(baseURL map[string]string) ModelDriver {
|
||||
return &PaddleOCRLocalModel{
|
||||
BaseURL: baseURL,
|
||||
URLSuffix: p.URLSuffix,
|
||||
httpClient: &http.Client{
|
||||
Transport: &http.Transport{
|
||||
MaxIdleConns: 10,
|
||||
MaxIdleConnsPerHost: 100,
|
||||
IdleConnTimeout: time.Second * 90,
|
||||
DisableCompression: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
return NewPaddleOCRLocalModel(baseURL, p.baseModel.URLSuffix)
|
||||
}
|
||||
|
||||
func (p *PaddleOCRLocalModel) Name() string {
|
||||
@@ -121,12 +110,11 @@ func (p *PaddleOCRLocalModel) OCRFile(modelName *string, content []byte, fileURL
|
||||
return nil, fmt.Errorf("local PaddleOCR requires file content, but content is empty")
|
||||
}
|
||||
|
||||
var region = "default"
|
||||
if apiConfig != nil && apiConfig.Region != nil && *apiConfig.Region != "" {
|
||||
region = *apiConfig.Region
|
||||
resolvedBaseURL, err := p.baseModel.GetBaseURL(apiConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s", p.BaseURL[region], p.URLSuffix.OCR)
|
||||
url := fmt.Sprintf("%s/%s", resolvedBaseURL, p.baseModel.URLSuffix.OCR)
|
||||
|
||||
base64Str := base64.StdEncoding.EncodeToString(content)
|
||||
|
||||
@@ -159,7 +147,7 @@ func (p *PaddleOCRLocalModel) OCRFile(modelName *string, content []byte, fileURL
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := p.httpClient.Do(req)
|
||||
resp, err := p.baseModel.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to send request to local PaddleOCR: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user