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:
Haruko386
2026-06-11 13:32:50 +08:00
committed by GitHub
parent 4b10c0b885
commit 84edf539e7
51 changed files with 275 additions and 702 deletions
+5 -22
View File
@@ -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 {