新增自定义模型

This commit is contained in:
jwangkun
2026-01-08 20:47:59 +08:00
parent 579071ac95
commit 82b46f93ce
10 changed files with 242 additions and 47 deletions

View File

@@ -49,7 +49,7 @@ const Header = ({ selectedModel, setSelectedModel, onOpenSettings, onToggleSideb
className="relative bg-white border border-slate-200 text-slate-800 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-auto p-2.5 outline-none appearance-none cursor-pointer pl-3 pr-8 shadow-sm font-medium hover:bg-slate-50 transition-colors"
>
{availableModels.map(m => (
<option key={m.value} value={m.value}>{m.label}</option>
<option key={`${m.provider}-${m.value}`} value={m.value}>{m.label}</option>
))}
</select>
<ChevronDown className="absolute right-3 top-3 text-slate-400 pointer-events-none group-hover:text-slate-600 transition-colors" size={14} />

View File

@@ -2,6 +2,7 @@
import React, { useState } from 'react';
import { Plus, Trash2, Bot, Key, Globe, ChevronDown, ChevronUp } from 'lucide-react';
import { AppConfig, ApiProvider, CustomModel } from '../../types';
import { MODELS } from '../../config';
interface ModelSectionProps {
config: AppConfig;
@@ -20,9 +21,25 @@ const ModelSection = ({ config, setConfig }: ModelSectionProps) => {
const handleAddModel = () => {
if (!newModelName.trim()) return;
const trimmedName = newModelName.trim();
// Check if model name already exists in preset models
const existingPresetModel = MODELS.find(m => m.value === trimmedName);
if (existingPresetModel) {
alert(`Model name "${trimmedName}" already exists as a preset model. Please choose a different name.`);
return;
}
// Check if model name already exists in custom models
const existingCustomModel = customModels.find(m => m.name === trimmedName);
if (existingCustomModel) {
alert(`Model name "${trimmedName}" already exists. Please choose a different name.`);
return;
}
const newModel: CustomModel = {
id: `custom-${Date.now()}`,
name: newModelName.trim(),
name: trimmedName,
provider: newModelProvider,
apiKey: newModelApiKey || undefined,
baseUrl: newModelBaseUrl || undefined