Fix(Go): correct Name() and region URL fallback in Aliyun driver (#14673)

### What problem does this PR solve?

Two bugs in the Aliyun Go driver:

1. **`Name()` returns `"siliconflow"`** — a copy-paste bug from when the
driver was created. `Name()` is used in error messages and log output,
so every Aliyun error incorrectly attributed itself to SiliconFlow.

2. **Silent empty URL for unknown regions in `ChatWithMessages`,
`ChatStreamlyWithSender`, and `ListModels`** — all three methods
construct the request URL as `z.BaseURL[region]` without checking
whether the key exists. For an unrecognised region this returns `""`,
producing a malformed URL like `"/chat/completions"` that the HTTP
transport rejects with a confusing error. `Encode` and `Rerank` (already
merged) correctly fall back to `"default"` and return a clear error.
This PR applies the same pattern to the remaining three methods.

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
Joseff
2026-05-10 23:26:24 -04:00
committed by GitHub
parent f852a7524e
commit 827cceccba

View File

@@ -71,7 +71,12 @@ func (z *AliyunModel) ChatWithMessages(modelName string, messages []Message, api
region = *apiConfig.Region
}
url := fmt.Sprintf("%s/%s", z.BaseURL[region], z.URLSuffix.Chat)
baseURL, ok := z.BaseURL[region]
if !ok || baseURL == "" {
return nil, fmt.Errorf("aliyun: no base URL configured for region %q", region)
}
url := fmt.Sprintf("%s/%s", strings.TrimSuffix(baseURL, "/"), z.URLSuffix.Chat)
// Convert messages to the format expected by API
apiMessages := make([]map[string]interface{}, len(messages))
@@ -207,7 +212,12 @@ func (z *AliyunModel) ChatStreamlyWithSender(modelName string, messages []Messag
region = *apiConfig.Region
}
url := fmt.Sprintf("%s/%s", z.BaseURL[region], z.URLSuffix.Chat)
baseURL, ok := z.BaseURL[region]
if !ok || baseURL == "" {
return fmt.Errorf("aliyun: no base URL configured for region %q", region)
}
url := fmt.Sprintf("%s/%s", strings.TrimSuffix(baseURL, "/"), z.URLSuffix.Chat)
// Convert messages to API format
apiMessages := make([]map[string]interface{}, len(messages))
@@ -573,7 +583,12 @@ func (z *AliyunModel) ListModels(apiConfig *APIConfig) ([]string, error) {
region = *apiConfig.Region
}
url := fmt.Sprintf("%s/%s", z.BaseURL[region], z.URLSuffix.Models)
baseURL, ok := z.BaseURL[region]
if !ok || baseURL == "" {
return nil, fmt.Errorf("aliyun: no base URL configured for region %q", region)
}
url := fmt.Sprintf("%s/%s", strings.TrimSuffix(baseURL, "/"), z.URLSuffix.Models)
// Build request body
reqBody := map[string]interface{}{}