From 827cceccba8944336a90817403e020c32ea337a8 Mon Sep 17 00:00:00 2001 From: Joseff Date: Sun, 10 May 2026 23:26:24 -0400 Subject: [PATCH] Fix(Go): correct Name() and region URL fallback in Aliyun driver (#14673) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### 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) --- internal/entity/models/aliyun.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/internal/entity/models/aliyun.go b/internal/entity/models/aliyun.go index a1ddd6dddb..3ec313e1f0 100644 --- a/internal/entity/models/aliyun.go +++ b/internal/entity/models/aliyun.go @@ -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{}{}