Skip to content

Conversation

@KariHall619
Copy link
Contributor

Motivation for Change

Previously, the model list was scattered across multiple files (Go manager, strategy, front-end configuration, tests, etc.) and easily became disconnected from each other; now, with a single YAML catalog as the authoritative source, the back-end, front-end, and default fallback logic are all referenced uniformly, which greatly reduces the maintenance cost when adding or deleting models and eliminates display inconsistencies.

Change Summary

  • Import pkg/ai/models/catalog.yaml to centrally maintain model metadata for cloud services such as OpenAI and DeepSeek;
  • Added pkg/ai/models/catalog.go to load YAML (supports environment variables or config/models.yaml overriding) and provide queries such as CatalogSnapshot, with accompanying catalog_test.go to verify loading and external overriding.
  • Refactored the Go backend: pkg/ai/manager.go, pkg/ai/generator.go, pkg/ai/providers/universal/strategy_openai.go all use the catalog to provide a list of models and a default endpoint. getOnlineProviders is now directly based on the catalog instead of a scattered hard-coded list.
  • Added models_catalog operation to the plugin service layer (pkg/plugin/service.go), which allows the frontend to obtain the full catalog or the catalog of a specified provider; model querying, error handling, etc. in the same file were also adjusted accordingly.
  • The front-end data flow has been changed to consume the catalog: aiService.fetchModelCatalog exposes a new API, and the catalog cache is prioritized during useAIChat initialization and failure fallback. All existing local mocks have been removed. Type definitions and UI handling are adapted to optional fields, and the AISettingsPanel dropdown fallback is changed to a "No model available" message. All related unit tests (aiService.spec.ts, useAIChat.test.ts, config.test.ts, etc.) have been updated accordingly.
  • Update .gitignore to allow tracking of the pkg/ai/models directory; complete front-end/back-end build and behavior tests (go test ./..., npm test -- --run) to ensure changes are stable.

test

go test ./...
cd frontend && npm test -- --run
To reproduce the UI effect: After running make install-local and restarting api-testing, check the model dropdown in the settings panel.

中文:

变更动机

之前模型列表散落在多个文件(Go manager、策略、前端配置、测试等), 在修改时容易遗漏;
现在通过单一 YAML catalog 为唯一来源,后端、前端和默认兜底逻辑都统一引用,大幅降低增删模型时的维护成本并消除显示不一致问题。

变更摘要

  • 引入 pkg/ai/models/catalog.yaml,集中维护 OpenAI、DeepSeek 等云服务的模型元数据;
  • 新增 pkg/ai/models/catalog.go 装载 YAML(支持环境变量或 config/models.yaml 覆盖)并提供 CatalogSnapshot 等查询,配套 catalog_test.go 验证加载与外部覆盖。
  • 重构 Go 后端:pkg/ai/manager.go, pkg/ai/generator.go, pkg/ai/providers/universal/strategy_openai.go 全部改用 catalog 提供的模型列表与默认 endpoint,getOnlineProviders 直接基于 catalog,而非散落的硬编码列表。
  • 在插件服务层增加 models_catalog 操作(pkg/plugin/service.go),前端可获取全量或指定 provider 的 catalog;同文件中模型查询、错误处理等同步调整。
  • 前端数据流改为消费 catalog:aiService.fetchModelCatalog 暴露新 API,useAIChat 初始化和失败兜底时优先使用 catalog 缓存,现有本地 mock 全部移除;类型定义和 UI 处理适配可选字段,AISettingsPanel 下拉兜底改为“暂无模型”提示。所有相关单测 (aiService.spec.ts, useAIChat.test.ts, config.test.ts 等) 随之更新。
  • 更新 .gitignore 允许跟踪 pkg/ai/models 目录;补齐前端/后端的构建与行为测试(go test ./...、npm test -- --run)确保改动稳定。

测试

go test ./...
cd frontend && npm test -- --run
如需复现 UI 效果:make install-local 后重启 api-testing,查看设置面板的模型下拉即可。

Refactors the AI chat UI to improve responsiveness across different screen sizes, ensuring a consistent user experience.

Improves the model selection process by fetching and caching the model catalog from the AI service.

Updates styles to enhance the visual appeal and usability of the chat interface.
Introduce pkg/ai/models catalog to load provider metadata from a single YAML source (with env/override support) and expose a models_catalog operation. Update manager, generator, and universal strategy to consume the catalog instead of hard-coded lists. Frontend now fetches the same catalog via aiService, removes local mocks, and adjusts dropdown fallbacks. Tests cover catalog loading and new client flows.
@KariHall619 KariHall619 force-pushed the centralize-ai-model-choice-backend-logic branch from 9b34bba to d53a5a0 Compare November 4, 2025 14:22
Add package documentation, replace deprecated strings.Title, and restructure env-path handling with an explicit #nosec justification so gosec accepts the override. Adjust test catalog WriteFile permissions to 0600 to silence G306. These changes resolve golangci-lint failures observed in the verify workflow.
Add an inline #nosec comment before the Unix socket directory creation so gosec no longer flags G301 during the workflow quality stage. No runtime behavior changes.
go fmt/go tidy expect gopkg.in/yaml.v3 listed as a direct requirement now that the catalog loader imports it. Update go.mod accordingly so the formatting step stays clean.
Refactor the Dockerfile to build frontend assets in a dedicated build-platform node stage and reuse them for each Go target, avoiding redundant npm runs under QEMU during multi-arch builds. The Go stage now cross-compiles using TARGETOS/TARGETARCH with module and npm caches. Additionally, skip the docker build job for pull requests in ci.yml so PRs run only quality and test jobs.
@LinuxSuRen LinuxSuRen merged commit 49d59ed into LinuxSuRen:master Nov 6, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants