Skip to content
Merged
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
20 changes: 10 additions & 10 deletions ui/ModelModal/src/ModelModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@ import { useForm, Controller } from 'react-hook-form';
import {
AddModelForm,
Model,
ConstsModelType,
ModelModalProps,
} from './types/types';
import { DEFAULT_MODEL_PROVIDERS } from './constants/providers';
import { ModelProvider } from './constants/providers';
import { getLocaleMessage } from './constants/locale';
import './assets/fonts/iconfont';
import { lightTheme } from './theme';

const titleMap = {
[ConstsModelType.ModelTypeLLM]: '对话模型',
[ConstsModelType.ModelTypeCoder]: '代码补全模型',
[ConstsModelType.ModelTypeEmbedding]: '向量模型',
[ConstsModelType.ModelTypeAudio]: '音频模型',
[ConstsModelType.ModelTypeReranker]: '重排序模型',
const titleMap: Record<string, string> = {
["llm"]: '对话模型',
["chat"]: '对话模型',
["coder"]: '代码补全模型',
["code"]: '代码补全模型',
["embedding"]: '向量模型',
["rerank"]: '重排序模型',
["reranker"]: '重排序模型',
};

export const ModelModal: React.FC<ModelModalProps> = ({
open,
onClose,
refresh,
data,
type = ConstsModelType.ModelTypeLLM,
type = "llm",
modelService,
language = 'zh-CN',
}: ModelModalProps) => {
Expand Down Expand Up @@ -362,7 +362,7 @@ export const ModelModal: React.FC<ModelModalProps> = ({
setModelLoading(false);
setSuccess(false);
reset({
provider: it.label as keyof typeof ModelProvider,
provider: it.label as keyof typeof DEFAULT_MODEL_PROVIDERS,
base_url:
it.label === 'AzureOpenAI' ? '' : it.defaultBaseUrl,
model: '',
Expand Down
130 changes: 7 additions & 123 deletions ui/ModelModal/src/constants/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,131 +112,15 @@ export const DEFAULT_MODEL_PROVIDERS: ModelProviderMap = {
modelDocumentUrl: 'https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/OpenAI',
defaultBaseUrl: 'https://<resource_name>.openai.azure.com',
},
Other: {
label: 'Other',
cn: '其他',
icon: 'icon-a-AIshezhi',
urlWrite: true,
secretRequired: true,
customHeader: false,
modelDocumentUrl: '',
defaultBaseUrl: '',
},
};

// 根据模型类型过滤提供商
export const getProvidersByType = (type: string, providers: ModelProviderMap = DEFAULT_MODEL_PROVIDERS): ModelProviderMap => {
if (type === 'embedding' || type === 'rerank') {
return {
BaiZhiCloud: providers.BaiZhiCloud,
Other: providers.Other,
};
}
return providers;
};

export const ModelProvider = {
BaiZhiCloud: {
label: 'BaiZhiCloud',
cn: '百智云',
icon: 'icon-baizhiyunlogo',
urlWrite: false,
secretRequired: true,
customHeader: false,
modelDocumentUrl: 'https://model-square.app.baizhi.cloud/token',
defaultBaseUrl: 'https://model-square.app.baizhi.cloud/v1',
},
DeepSeek: {
label: 'DeepSeek',
cn: '',
icon: 'icon-deepseek',
urlWrite: false,
secretRequired: true,
customHeader: false,
modelDocumentUrl: 'https://platform.deepseek.com/api_keys',
defaultBaseUrl: 'https://api.deepseek.com/v1',
},
Hunyuan: {
label: 'Hunyuan',
cn: '腾讯混元',
icon: 'icon-tengxunhunyuan',
urlWrite: false,
secretRequired: true,
customHeader: false,
modelDocumentUrl: 'https://console.cloud.tencent.com/hunyuan/start',
defaultBaseUrl: 'https://api.hunyuan.cloud.tencent.com/v1',
},
BaiLian: {
label: 'BaiLian',
cn: '阿里云百炼',
icon: 'icon-aliyunbailian',
urlWrite: false,
secretRequired: true,
customHeader: false,
modelDocumentUrl: 'https://bailian.console.aliyun.com/?tab=model#/api-key',
defaultBaseUrl: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
},
Volcengine: {
label: 'Volcengine',
cn: '火山引擎',
icon: 'icon-huoshanyinqing',
urlWrite: false,
secretRequired: true,
customHeader: false,
modelDocumentUrl:
'https://console.volcengine.com/ark/region:ark+cn-beijing/apiKey',
defaultBaseUrl: 'https://ark.cn-beijing.volces.com/api/v3',
},
OpenAI: {
label: 'OpenAI',
cn: '',
icon: 'icon-chatgpt',
urlWrite: false,
secretRequired: true,
customHeader: false,
modelDocumentUrl: 'https://platform.openai.com/api-keys',
defaultBaseUrl: 'https://api.openai.com/v1',
},
Ollama: {
label: 'Ollama',
cn: '',
icon: 'icon-ollama',
urlWrite: true,
secretRequired: false,
customHeader: true,
modelDocumentUrl: '',
defaultBaseUrl: 'http://127.0.0.1:11434/v1',
},
SiliconFlow: {
label: 'SiliconFlow',
cn: '硅基流动',
icon: 'icon-a-ziyuan2',
urlWrite: false,
secretRequired: true,
customHeader: false,
modelDocumentUrl: 'https://cloud.siliconflow.cn/account/ak',
defaultBaseUrl: 'https://api.siliconflow.cn/v1',
},
Moonshot: {
label: 'Moonshot',
cn: '月之暗面',
icon: 'icon-Kim',
Gemini: {
label: 'Gemini',
cn: 'Gemini',
icon: 'icon-gemini',
urlWrite: false,
secretRequired: true,
customHeader: false,
modelDocumentUrl: 'https://platform.moonshot.cn/console/api-keys',
defaultBaseUrl: 'https://api.moonshot.cn/v1',
},
AzureOpenAI: {
label: 'AzureOpenAI',
cn: 'Azure OpenAI',
icon: 'icon-azure',
urlWrite: true,
secretRequired: true,
customHeader: false,
modelDocumentUrl:
'https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/OpenAI',
defaultBaseUrl: 'https://<resource_name>.openai.azure.com',
modelDocumentUrl: 'https://ai.google.dev/gemini-api/docs',
defaultBaseUrl: 'https://generativelanguage.googleapis.com',
},
Other: {
label: 'Other',
Expand All @@ -248,4 +132,4 @@ export const ModelProvider = {
modelDocumentUrl: '',
defaultBaseUrl: '',
},
};
};
7 changes: 2 additions & 5 deletions ui/ModelModal/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
export { ModelModal } from './ModelModal';

// 类型定义
export type { ModelType, Model, ModelParam, ConstsModelStatus, ConstsModelProvider, ModelProviderConfig, ModelProviderMap, CreateModelReq as CreateModelData, ListModelReq as GetModelNameData, CheckModelReq as CheckModelData, UpdateModelReq as UpdateModelData, ModelService, ModelListItem, AddModelForm, ModelModalProps } from './types/types';

// 导出 ConstsModelType 枚举值
export { ConstsModelType } from './types/types';
export type { Model, ModelParam, ModelProviderConfig, ModelProviderMap, CreateModelReq as CreateModelData, ListModelReq as GetModelNameData, CheckModelReq as CheckModelData, UpdateModelReq as UpdateModelData, ModelService, ModelListItem, AddModelForm, ModelModalProps } from './types/types';

// 常量
export { DEFAULT_MODEL_PROVIDERS, getProvidersByType } from './constants/providers';
export { DEFAULT_MODEL_PROVIDERS} from './constants/providers';
export { LOCALE_MESSAGES, getLocaleMessage, getTitleMap } from './constants/locale';

// 主题类型声明会通过TypeScript自动包含
Expand Down
109 changes: 20 additions & 89 deletions ui/ModelModal/src/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
import { ModelProvider } from "@/constants/providers";

// 基础类型定义
export type ModelType = 'llm' | 'embedding' | 'reranker' | 'coder' | 'audio';

// 模型类型常量
export enum ConstsModelType {
ModelTypeLLM = "llm",
ModelTypeCoder = "coder",
ModelTypeEmbedding = "embedding",
ModelTypeAudio = "audio",
ModelTypeReranker = "reranker",
}

// 域模型接口
export interface Model {
/** 接口地址 如:https://api.qwen.com */
Expand All @@ -35,17 +21,17 @@ export interface Model {
/** 模型名称 如: deepseek-v3 */
model_name?: string;
/** 模型类型 llm:对话模型 coder:代码模型 */
model_type?: ConstsModelType;
model_type?: string;
/** 输出token数 */
output?: number;
/** 高级参数 */
param?: ModelParam;
/** 提供商 */
provider?: ConstsModelProvider;
provider?: string;
/** 模型显示名称 */
show_name?: string;
/** 状态 active:启用 inactive:禁用 */
status?: ConstsModelStatus;
status?: string;
/** 更新时间 */
updated_at?: number;
}
Expand All @@ -59,24 +45,6 @@ export interface ModelParam {
support_prompt_cache?: boolean;
}

export enum ConstsModelStatus {
ModelStatusActive = "active",
ModelStatusInactive = "inactive",
}

export enum ConstsModelProvider {
ModelProviderSiliconFlow = "SiliconFlow",
ModelProviderOpenAI = "OpenAI",
ModelProviderOllama = "Ollama",
ModelProviderDeepSeek = "DeepSeek",
ModelProviderMoonshot = "Moonshot",
ModelProviderAzureOpenAI = "AzureOpenAI",
ModelProviderBaiZhiCloud = "BaiZhiCloud",
ModelProviderHunyuan = "Hunyuan",
ModelProviderBaiLian = "BaiLian",
ModelProviderVolcengine = "Volcengine",
}

// 模型提供商配置
export interface ModelProviderConfig {
label: string;
Expand All @@ -103,61 +71,35 @@ export interface ModelParam {

// 创建模型数据
export interface CreateModelReq {
api_base: string;
api_base?: string;
api_header?: string;
api_key?: string;
api_version?: string;
model_name: string;
model_type?: ConstsModelType;
model_name?: string;
model_type?: string;
param?: ModelParam;
provider:
| "SiliconFlow"
| "OpenAI"
| "Ollama"
| "DeepSeek"
| "Moonshot"
| "AzureOpenAI"
| "BaiZhiCloud"
| "Hunyuan"
| "BaiLian"
| "Volcengine"
| "Other";
/** 模型显示名称 */
provider?: string;
show_name?: string;
}

// 获取模型列表数据
export interface ListModelReq {
api_header?: string;
api_key?: string;
base_url: string;
provider:
| "SiliconFlow"
| "OpenAI"
| "Ollama"
| "DeepSeek"
| "Moonshot"
| "AzureOpenAI"
| "BaiZhiCloud"
| "Hunyuan"
| "BaiLian"
| "Volcengine";
type: ConstsModelType;
base_url?: string;
provider?: string;
type?: string;
}

// 检查模型数据
export interface CheckModelReq {
/** 接口地址 */
api_base: string;
api_base?: string;
api_header?: string;
/** 接口密钥 */
api_key: string;
api_key?: string;
api_version?: string;
/** 模型名称 */
model_name: string;
/** 提供商 */
provider: ConstsModelProvider;
type: "llm" | "coder" | "embedding" | "rerank";
model_name?: string;
provider?: string;
type?: string;
}

// 更新模型数据
Expand All @@ -175,22 +117,11 @@ export interface UpdateModelReq {
/** 高级参数 */
param?: ModelParam;
/** 提供商 */
provider:
| "SiliconFlow"
| "OpenAI"
| "Ollama"
| "DeepSeek"
| "Moonshot"
| "AzureOpenAI"
| "BaiZhiCloud"
| "Hunyuan"
| "BaiLian"
| "Volcengine"
| "Other";
provider?: string;
/** 模型显示名称 */
show_name?: string;
/** 状态 active:启用 inactive:禁用 */
status?: ConstsModelStatus;
status?: string;
}

// 模型服务接口
Expand All @@ -207,14 +138,14 @@ export interface ModelListItem {

// 表单数据
export interface AddModelForm {
provider: keyof typeof ModelProvider;
provider: string;
model: string;
base_url: string;
api_version: string;
api_key: string;
api_header_key: string;
api_header_value: string;
type: ModelType;
type: string;
show_name: string;
// 高级设置字段
context_window_size: number;
Expand All @@ -228,7 +159,7 @@ export interface AddModelForm {
export interface ModelModalProps {
open: boolean;
data: Model | null;
type: ConstsModelType;
type: string;
onClose: () => void;
refresh: () => void;
modelService: ModelService;
Expand Down
Loading