You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "Harry33t (via GitHub)" <gi...@apache.org> on 2026/05/04 08:08:05 UTC

[PR] fix(llm): use generic model fields in frontend instead of OllamaModels [dubbo-go-samples]

Harry33t opened a new pull request, #1093:
URL: https://github.com/apache/dubbo-go-samples/pull/1093

   # 修复:非 Ollama 提供商导致前端首页访问 panic
   
   ## 问题
   
   当 `LLM_PROVIDER` 不是 `ollama` 时(例如通过 OpenAI 兼容接口使用 openai、gemini),打开前端首页会触发 panic:
   
   ```
   runtime error: index out of range [0] with length 0
   ```
   
   错误堆栈指向 `llm/go-client/frontend/main.go`:
   
   ```go
   "DefaultModel": cfg.OllamaModels[0],
   ```
   
   ## 根本原因
   
   `config.go` 仅在 LLM 提供商为 `ollama` 时才会填充 `OllamaModels`:
   
   ```go
   if config.LLMProvider == "ollama" {
       config.OllamaModels = modelsList
   }
   ```
   
   因此对于其他提供商,该切片为空,访问索引 `[0]` 会触发 panic。
   
   CLI 已经使用通用的 `cfg.LLMModelsList` 和 `cfg.ModelName`,前端部分未同步适配。
   
   ## 修复方案
   
   - `main.go`:将 `cfg.LLMModelsList` 作为 `Models` 传入,`cfg.ModelName` 作为 `DefaultModel` 传入
   - `index.html`:遍历 `.Models`,将配置的 `MODEL_NAME` 标记为 `selected`,确保初始下拉框与用户 `.env` 中的配置匹配
   
   ## 验证
   
   使用 #1072 中的复现配置进行本地测试:
   
   ```
   LLM_PROVIDER = openai
   LLM_MODELS = gemini-2.5-flash
   LLM_BASE_URL = https://generativelanguage.googleapis.com/v1beta/openai/
   MODEL_NAME = gemini-2.5-flash
   ```
   
   - `GET /` 返回 HTTP **200**,无 panic
   - 下拉框渲染正常:`<option value="gemini-2.5-flash" selected>gemini-2.5-flash</option>`
   
   
   <img width="991" height="1108" alt="image" src="https://github.com/user-attachments/assets/0df5c41d-23e8-49a4-9b7c-744307ece70f" />
   
   
   Ollama 路径不受影响:`LLMModelsList` 和 `ModelName` 在 `config.go` 中对所有 provider 都会填充,因此当 provider 是 ollama 时,渲染结果与原来用 `OllamaModels` 完全一致,无回归。
   
   Closes #1072
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] fix(llm): use generic model fields in frontend instead of OllamaModels [dubbo-go-samples]

Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on PR #1093:
URL: https://github.com/apache/dubbo-go-samples/pull/1093#issuecomment-4378591338

   merge to main to fix ci fail


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] fix(llm): use generic model fields in frontend instead of OllamaModels [dubbo-go-samples]

Posted by "Harry33t (via GitHub)" <gi...@apache.org>.
Harry33t commented on PR #1093:
URL: https://github.com/apache/dubbo-go-samples/pull/1093#issuecomment-4370317690

   CI 的 lint 失败是 `book-flight-ai-agent/go-server/tools/tool_base.go:64` 的 `reflect.Ptr` 应改为 `reflect.Pointer`(govet 提示)。
   这是仓库里早已存在的问题,由 commit 6c49cca8c (2025-05-15) 引入,与本 PR 的改动完全无关。
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] fix(llm): use generic model fields in frontend instead of OllamaModels [dubbo-go-samples]

Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl merged PR #1093:
URL: https://github.com/apache/dubbo-go-samples/pull/1093


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org