Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/app/core/setting/ai/modelSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
CommandItem,
CommandList,
} from "@/components/ui/command";
import { AiConfig } from "../config";
import { AiConfig, baseAiConfig } from "../config";
import { Store } from "@tauri-apps/plugin-store";
import emitter from "@/lib/emitter";

Expand Down Expand Up @@ -56,7 +56,22 @@ export default function ModelSelect(
if (requestId !== currentRequestIdRef.current) return

if (!models) return
setList(models)
// 如果API返回空列表,尝试使用静态模型列表作为后备
if (models.length === 0 && model) {
const baseConfig = baseAiConfig.find(c => c.baseURL === model.baseURL)
if (baseConfig?.staticModels?.length) {
setList(baseConfig.staticModels.map(id => ({
id,
object: 'model' as const,
created: 0,
owned_by: baseConfig.key,
})))
} else {
setList(models)
}
} else {
setList(models)
}

// 如果没有传入aiConfig,则从store中设置model值
if (!aiConfig && setModel) {
Expand Down
13 changes: 9 additions & 4 deletions src/app/core/setting/ai/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export default function AiPage() {

// 当前选中的AI配置
const currentConfig = userCustomModels.find(model => model.key === selectedAiConfig)

const getConfigDisplayTitle = (config?: AiConfig) => {
if (!config) return t('selectConfig')
return baseAiConfig.find(item => item.baseURL === config.baseURL)?.title || config.title
}

const parseHeadersToKeyValue = (headers: Record<string, string> = {}) => {
return Object.entries(headers).map(([key, value]) => ({
Expand Down Expand Up @@ -282,13 +287,13 @@ export default function AiPage() {
<Select value={selectedAiConfig} onValueChange={setSelectedAiConfig}>
<SelectTrigger className="w-full">
<div className="flex items-center gap-2">
{currentConfig?.title || t('selectConfig')}
{getConfigDisplayTitle(currentConfig)}
</div>
</SelectTrigger>
<SelectContent>
{userCustomModels.map((item) => (
<SelectItem value={item.key} key={item.key}>
{item.title}
{getConfigDisplayTitle(item)}
</SelectItem>
))}
</SelectContent>
Expand Down Expand Up @@ -331,7 +336,7 @@ export default function AiPage() {
/>
)}
<div>
<div className="font-medium">{currentConfig.title}</div>
<div className="font-medium">{baseAiConfig.find(config => config.baseURL === currentConfig.baseURL)?.title || currentConfig.title}</div>
<div className="text-sm text-muted-foreground">{currentConfig.baseURL}</div>
</div>
</div>
Expand Down Expand Up @@ -474,4 +479,4 @@ export default function AiPage() {
)}
</SettingType>
)
}
}
20 changes: 19 additions & 1 deletion src/app/core/setting/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export interface AiConfig {
apiKeyUrl?: string
customHeaders?: Record<string, string>
models?: ModelConfig[]
staticModels?: string[]
// 保持向后兼容
model?: string
temperature?: number
Expand Down Expand Up @@ -232,6 +233,23 @@ const baseAiConfig: AiConfig[] = [
icon: 'https://s2.loli.net/2025/09/15/ih7aTnGPvELFsVc.png',
apiKeyUrl: 'https://ai.gitee.com/'
},
{
key: 'bailian-coding',
title: '阿里云百炼(Coding Plan)',
baseURL: 'https://coding.dashscope.aliyuncs.com/v1',
icon: 'https://unpkg.com/@lobehub/icons-static-png/light/Bailian.png',
apiKeyUrl: 'https://dashscope.console.aliyun.com/apiKey',
staticModels: [
'qwen3.5-plus',
'qwen3-max-2026-01-23',
'qwen3-coder-next',
'qwen3-coder-plus',
'glm-5',
'glm-4.7',
'kimi-k2.5',
'MiniMax-M2.5',
]
},
]

export { baseAiConfig }
export { baseAiConfig }
2 changes: 2 additions & 0 deletions src/lib/ai/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Store } from "@tauri-apps/plugin-store";
import OpenAI from 'openai';
import { AiConfig } from "@/app/core/setting/config";
import { readFile } from "@tauri-apps/plugin-fs";
import { fetch as tauriFetch } from '@tauri-apps/plugin-http';

/**
* 获取当前的prompt内容
Expand Down Expand Up @@ -279,6 +280,7 @@ export async function createOpenAIClient(AiConfig?: AiConfig) {
apiKey: apiKey || '',
baseURL: baseURL,
dangerouslyAllowBrowser: true,
fetch: tauriFetch as unknown as typeof globalThis.fetch,
defaultHeaders:{
"x-stainless-arch": null,
"x-stainless-lang": null,
Expand Down