mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-09-08 10:14:35 +08:00
Go: Refactor list-models func (#15900)
### What problem does this PR solve? As title Issue: #15853 ### Type of change - [x] Refactoring
This commit is contained in:
@@ -363,33 +363,16 @@ func (a *AstraflowModel) ListModels(apiConfig *APIConfig) ([]ListModelResponse,
|
||||
return nil, fmt.Errorf("API request failed with status %d: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
|
||||
var result map[string]interface{}
|
||||
if err = json.Unmarshal(body, &result); err != nil {
|
||||
// Parse response
|
||||
var modelList ModelList
|
||||
if err = json.Unmarshal(body, &modelList); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse response: %w", err)
|
||||
}
|
||||
|
||||
data, ok := result["data"].([]interface{})
|
||||
if !ok {
|
||||
if modelList.Models == nil {
|
||||
return nil, fmt.Errorf("invalid models list format")
|
||||
}
|
||||
|
||||
models := make([]ListModelResponse, 0, len(data))
|
||||
var modelMap map[string]interface{}
|
||||
for _, m := range data {
|
||||
modelMap, ok = m.(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
var id string
|
||||
id, ok = modelMap["id"].(string)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
models = append(models, ListModelResponse{
|
||||
Name: id,
|
||||
})
|
||||
}
|
||||
return models, nil
|
||||
return ParseListModel(modelList), nil
|
||||
}
|
||||
|
||||
func (a *AstraflowModel) CheckConnection(apiConfig *APIConfig) error {
|
||||
|
||||
Reference in New Issue
Block a user