mirror of
https://github.com/margrop/wrong-notebook.git
synced 2026-12-04 05:09:29 +08:00
fix: 英文界面下 AI 提供商列表仍显示中文渠道名
国产大模型渠道预设增加英文名称,AI 提供商下拉列表和语音设置的 API Key 标签按界面语言显示。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -29,7 +29,7 @@ vi.mock('@/lib/auth', () => ({ authOptions: {} }));
|
||||
vi.stubGlobal('fetch', mocks.fetch);
|
||||
|
||||
import { getAIService } from '@/lib/ai';
|
||||
import { VENDOR_PRESETS, VENDOR_PROVIDER_IDS, isVendorProvider, resolveVendorConfig } from '@/lib/ai/vendor-presets';
|
||||
import { VENDOR_PRESETS, VENDOR_PROVIDER_IDS, getVendorName, isVendorProvider, resolveVendorConfig } from '@/lib/ai/vendor-presets';
|
||||
import type { VendorProviderId } from '@/lib/ai/vendor-presets';
|
||||
import { POST as listModels } from '@/app/api/ai/models/route';
|
||||
import { POST as testConnection } from '@/app/api/ai/test/route';
|
||||
@@ -57,6 +57,15 @@ describe('国产大模型渠道预设', () => {
|
||||
expect([...VENDOR_PROVIDER_IDS].sort()).toEqual(Object.keys(EXPECTED).sort());
|
||||
});
|
||||
|
||||
it('按界面语言显示渠道名称,英文名称不含中文', () => {
|
||||
for (const id of VENDOR_PROVIDER_IDS) {
|
||||
expect(getVendorName(id, 'zh')).toBe(VENDOR_PRESETS[id].name);
|
||||
expect(getVendorName(id, 'en'), id).not.toMatch(/[\u4e00-\u9fff()]/);
|
||||
}
|
||||
expect(getVendorName('volcengine-free', 'en')).toBe('Volcengine (free trial)');
|
||||
expect(getVendorName('glm', 'zh')).toBe('智谱 GLM');
|
||||
});
|
||||
|
||||
it('只识别已知渠道', () => {
|
||||
expect(isVendorProvider('openai')).toBe(false);
|
||||
expect(isVendorProvider('toString')).toBe(false);
|
||||
|
||||
@@ -14,7 +14,7 @@ import { OpenAIInstanceSettings } from "@/components/settings/openai-instance-se
|
||||
import { ProviderDocLinks } from "@/components/settings/provider-doc-links";
|
||||
import { VendorSettings } from "@/components/settings/vendor-settings";
|
||||
import { useLanguage } from "@/contexts/LanguageContext";
|
||||
import { isVendorProvider, VENDOR_PRESETS, VENDOR_PROVIDER_IDS } from "@/lib/ai/vendor-presets";
|
||||
import { getVendorName, isVendorProvider, VENDOR_PROVIDER_IDS } from "@/lib/ai/vendor-presets";
|
||||
import type { AppConfig } from "@/types/api";
|
||||
|
||||
interface AiProviderSettingsProps {
|
||||
@@ -27,7 +27,7 @@ interface AiProviderSettingsProps {
|
||||
|
||||
/** AI 渠道设置:选择渠道、填写对应配置、测试连接并保存 */
|
||||
export function AiProviderSettings({ config, setConfig, loading, saving, onSave }: AiProviderSettingsProps) {
|
||||
const { t } = useLanguage();
|
||||
const { t, language } = useLanguage();
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
@@ -50,10 +50,10 @@ export function AiProviderSettings({ config, setConfig, loading, saving, onSave
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{/* MiniMax Code OAuth 排在第 2 位,紧跟 MiniMax 官方渠道 */}
|
||||
<SelectItem value="minimax">{VENDOR_PRESETS.minimax.name}</SelectItem>
|
||||
<SelectItem value="minimax">{getVendorName("minimax", language)}</SelectItem>
|
||||
<SelectItem value="minimax-code">MiniMax Code OAuth</SelectItem>
|
||||
{VENDOR_PROVIDER_IDS.filter((id) => id !== 'minimax').map((id) => (
|
||||
<SelectItem key={id} value={id}>{VENDOR_PRESETS[id].name}</SelectItem>
|
||||
<SelectItem key={id} value={id}>{getVendorName(id, language)}</SelectItem>
|
||||
))}
|
||||
<SelectItem value="anthropic">Anthropic / Compatible</SelectItem>
|
||||
<SelectItem value="azure">Azure OpenAI</SelectItem>
|
||||
|
||||
@@ -122,7 +122,7 @@ export function OpenAIInstanceSettings({ value, onChange }: OpenAIInstanceSettin
|
||||
<Input
|
||||
value={selected.name || ''}
|
||||
onChange={(e) => updateSelected('name', e.target.value)}
|
||||
placeholder="e.g. 智谱 GLM-4V"
|
||||
placeholder="e.g. GLM-4V"
|
||||
className={!selected.name?.trim() ? 'border-destructive' : ''}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -10,7 +10,7 @@ import { PasswordInput } from "@/components/ui/password-input";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { ProviderErrorDetail } from "@/components/settings/provider-error-detail";
|
||||
import { useLanguage } from "@/contexts/LanguageContext";
|
||||
import { VENDOR_PRESETS } from "@/lib/ai/vendor-presets";
|
||||
import { getVendorName } from "@/lib/ai/vendor-presets";
|
||||
import { apiClient } from "@/lib/api-client";
|
||||
import { getSpeechAudio, unlockSpeechAudio } from "@/lib/cloud-speech";
|
||||
import { getApiErrorDetails, getApiErrorMessage } from "@/lib/error-message";
|
||||
@@ -48,7 +48,7 @@ interface TtsSettingsProps {
|
||||
}
|
||||
|
||||
/**
|
||||
* 动画语音讲解的朗读方式(管理员):浏览器本地语音,或由服务端调用 MiniMax / 千问的语音合成。
|
||||
* 动画语音讲解的朗读方式(管理员):浏览器本地语音,或由服务端调用 MiniMax、千问等渠道的语音合成。
|
||||
* 云端语音的 API Key 与「AI 设置」中对应渠道共用
|
||||
*/
|
||||
export function TtsSettings({ config, setConfig, saving, onSave }: TtsSettingsProps) {
|
||||
@@ -120,7 +120,7 @@ export function TtsSettings({ config, setConfig, saving, onSave }: TtsSettingsPr
|
||||
{provider && (
|
||||
<div key={provider} className="space-y-3 animate-in fade-in slide-in-from-top-2">
|
||||
<div className="space-y-2">
|
||||
<Label>{ownApiKey ? texts.speechApiKey : `${VENDOR_PRESETS[provider].name} API Key`}</Label>
|
||||
<Label>{ownApiKey ? texts.speechApiKey : `${getVendorName(provider, language)} API Key`}</Label>
|
||||
<PasswordInput
|
||||
value={apiKey || ""}
|
||||
onChange={(e) => updateApiKey(e.target.value)}
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
*/
|
||||
|
||||
export interface VendorPreset {
|
||||
name: string; // 显示名称
|
||||
name: string; // 中文界面的显示名称
|
||||
nameEn: string; // 英文界面的显示名称
|
||||
baseUrl: string; // 官方 OpenAI 兼容地址(中国大陆)
|
||||
model: string; // 默认模型(当前最新、支持图片输入)
|
||||
envPrefix: string; // 环境变量前缀:<PREFIX>_API_KEY / _BASE_URL / _MODEL
|
||||
@@ -16,6 +17,7 @@ export interface VendorPreset {
|
||||
export const VENDOR_PRESETS = {
|
||||
minimax: {
|
||||
name: 'MiniMax',
|
||||
nameEn: 'MiniMax',
|
||||
baseUrl: 'https://api.minimax.cn/v1',
|
||||
model: 'MiniMax-M3.1-Flash',
|
||||
envPrefix: 'MINIMAX',
|
||||
@@ -24,6 +26,7 @@ export const VENDOR_PRESETS = {
|
||||
},
|
||||
glm: {
|
||||
name: '智谱 GLM',
|
||||
nameEn: 'Zhipu GLM',
|
||||
baseUrl: 'https://open.bigmodel.cn/api/paas/v4',
|
||||
model: 'glm-5.3-flash',
|
||||
envPrefix: 'GLM',
|
||||
@@ -32,6 +35,7 @@ export const VENDOR_PRESETS = {
|
||||
},
|
||||
deepseek: {
|
||||
name: 'DeepSeek',
|
||||
nameEn: 'DeepSeek',
|
||||
baseUrl: 'https://api.deepseek.com',
|
||||
model: 'deepseek-flash',
|
||||
envPrefix: 'DEEPSEEK',
|
||||
@@ -40,6 +44,7 @@ export const VENDOR_PRESETS = {
|
||||
},
|
||||
kimi: {
|
||||
name: 'Kimi',
|
||||
nameEn: 'Kimi',
|
||||
baseUrl: 'https://api.moonshot.cn/v1',
|
||||
model: 'kimi-k3',
|
||||
envPrefix: 'KIMI',
|
||||
@@ -49,6 +54,7 @@ export const VENDOR_PRESETS = {
|
||||
// 默认为百炼 Token Plan 专属地址(Key 以 sk-sp- 开头);按量付费的 Key 改用 https://dashscope.aliyuncs.com/compatible-mode/v1
|
||||
qwen: {
|
||||
name: '千问 Qwen',
|
||||
nameEn: 'Qwen',
|
||||
baseUrl: 'https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1',
|
||||
model: 'qwen3.8-max',
|
||||
envPrefix: 'QWEN',
|
||||
@@ -58,6 +64,7 @@ export const VENDOR_PRESETS = {
|
||||
// 默认为 Step Plan 套餐地址(含语音合成);按量付费改用 https://api.stepfun.com/v1,国际站为 https://api.stepfun.ai/v1
|
||||
stepfun: {
|
||||
name: '阶跃星辰 StepFun',
|
||||
nameEn: 'StepFun',
|
||||
baseUrl: 'https://api.stepfun.com/step_plan/v1',
|
||||
model: 'step-5-preview',
|
||||
envPrefix: 'STEPFUN',
|
||||
@@ -67,6 +74,7 @@ export const VENDOR_PRESETS = {
|
||||
// 火山方舟(豆包大模型);推荐 Agent Plan、Coding Plan 等套餐,套餐的接口地址以火山引擎控制台为准。国际站为 BytePlus ModelArk
|
||||
volcengine: {
|
||||
name: '火山引擎 豆包',
|
||||
nameEn: 'Volcengine Doubao',
|
||||
baseUrl: 'https://ark.cn-beijing.volces.com/api/v3',
|
||||
model: 'doubao-seed-2-1-lite-260915',
|
||||
envPrefix: 'VOLCENGINE',
|
||||
@@ -76,6 +84,7 @@ export const VENDOR_PRESETS = {
|
||||
// 同为火山方舟,面向新用户的免费推理额度:每个模型有免费 token,开启「安心体验模式」后额度用完自动暂停,不产生费用
|
||||
'volcengine-free': {
|
||||
name: '火山引擎(免费试用)',
|
||||
nameEn: 'Volcengine (free trial)',
|
||||
baseUrl: 'https://ark.cn-beijing.volces.com/api/v3',
|
||||
model: 'doubao-seed-2-1-lite-260915',
|
||||
envPrefix: 'VOLCENGINE_FREE',
|
||||
@@ -94,6 +103,12 @@ export interface VendorConfig {
|
||||
model?: string;
|
||||
}
|
||||
|
||||
/** 按界面语言取渠道的显示名称 */
|
||||
export function getVendorName(provider: VendorProviderId, language: string): string {
|
||||
const preset = VENDOR_PRESETS[provider];
|
||||
return language === 'zh' ? preset.name : preset.nameEn;
|
||||
}
|
||||
|
||||
export function isVendorProvider(provider: unknown): provider is VendorProviderId {
|
||||
return typeof provider === 'string' && Object.prototype.hasOwnProperty.call(VENDOR_PRESETS, provider);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user