-
Notifications
You must be signed in to change notification settings - Fork 45
fix(assistant): 切换免费模型 Intern-S1 → GLM-4.6V-Flash + 加关闭按钮 (#285) #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,22 +1,33 @@ | ||||||||||||||||||||||||||||||||||
| import { createOpenAICompatible } from "@ai-sdk/openai-compatible"; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||
| * Create Intern-AI model instance | ||||||||||||||||||||||||||||||||||
| * Uses environment variable INTERN_KEY for API key | ||||||||||||||||||||||||||||||||||
| * 在开发环境下,临时映射到 Deepseek 进行测试 | ||||||||||||||||||||||||||||||||||
| * @returns Configured Intern-AI model instance | ||||||||||||||||||||||||||||||||||
| * 免费聊天模型:智谱 GLM-4.6V-Flash | ||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||
| * 历史原因:此前默认走上海 AI Lab 的书生 Intern-S1,现因 key 过期改接智谱 | ||||||||||||||||||||||||||||||||||
| * GLM-4.6V-Flash(同样免费、128K 上下文、支持多模态)。为避免破坏用户 | ||||||||||||||||||||||||||||||||||
| * localStorage 里已有的 provider="intern" 设置,函数/Provider 名保留 `intern` | ||||||||||||||||||||||||||||||||||
| * 作为语义上的"免费兜底模型"标识。 | ||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||
| * 开发环境仍可通过 DEEPSEEK_API_KEY 快速切换到 Deepseek 接口做调试。 | ||||||||||||||||||||||||||||||||||
| * 生产环境需要在服务端配置 ZHIPU_API_KEY(智谱 AI 开放平台)。 | ||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||
| export function createInternModel() { | ||||||||||||||||||||||||||||||||||
| const isDev = process.env.NODE_ENV === "development"; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const intern = createOpenAICompatible({ | ||||||||||||||||||||||||||||||||||
| name: "intern", | ||||||||||||||||||||||||||||||||||
| baseURL: isDev | ||||||||||||||||||||||||||||||||||
| ? "https://api.deepseek.com" // 开发环境临时使用 Deepseek 接口测试 | ||||||||||||||||||||||||||||||||||
| : "https://chat.intern-ai.org.cn/api/v1/", | ||||||||||||||||||||||||||||||||||
| apiKey: isDev ? process.env.DEEPSEEK_API_KEY : process.env.INTERN_KEY, | ||||||||||||||||||||||||||||||||||
| if (isDev && process.env.DEEPSEEK_API_KEY) { | ||||||||||||||||||||||||||||||||||
| const deepseek = createOpenAICompatible({ | ||||||||||||||||||||||||||||||||||
| name: "deepseek", | ||||||||||||||||||||||||||||||||||
| baseURL: "https://api.deepseek.com", | ||||||||||||||||||||||||||||||||||
| apiKey: process.env.DEEPSEEK_API_KEY, | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
| return deepseek("deepseek-chat"); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const glm = createOpenAICompatible({ | ||||||||||||||||||||||||||||||||||
| name: "zhipu", | ||||||||||||||||||||||||||||||||||
| baseURL: "https://open.bigmodel.cn/api/paas/v4/", | ||||||||||||||||||||||||||||||||||
| apiKey: process.env.ZHIPU_API_KEY, | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+26
to
+29
|
||||||||||||||||||||||||||||||||||
| const glm = createOpenAICompatible({ | |
| name: "zhipu", | |
| baseURL: "https://open.bigmodel.cn/api/paas/v4/", | |
| apiKey: process.env.ZHIPU_API_KEY, | |
| const zhipuApiKey = process.env.ZHIPU_API_KEY; | |
| if (!zhipuApiKey || zhipuApiKey.trim() === "") { | |
| throw new Error( | |
| "Missing required environment variable ZHIPU_API_KEY. Configure it on the server (for example in Vercel Project Settings -> Environment Variables) before using the intern provider.", | |
| ); | |
| } | |
| const glm = createOpenAICompatible({ | |
| name: "zhipu", | |
| baseURL: "https://open.bigmodel.cn/api/paas/v4/", | |
| apiKey: zhipuApiKey, |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里用 throw 触发 fallback 会导致所有匿名请求都进入 catch 分支并打印带 stack 的 warn 日志(且文案是“Java Backend unavailable...”),实际会在生产环境造成大量噪音。建议改为显式的 if 分支直接跳过代理(不抛错、不进入 catch),或在 catch 中对匿名场景单独处理为低噪日志/不记录 error 对象。