perf: 模型管理界面重做
This commit is contained in:
@@ -1,27 +1,66 @@
|
||||
import { ref } from 'vue';
|
||||
|
||||
import providerList from './providerList.json';
|
||||
|
||||
const providerOptions =
|
||||
ref<Array<{ icon: string; label: string; options: any; value: string }>>(
|
||||
providerList,
|
||||
);
|
||||
export interface ProviderModelPreset {
|
||||
description: string;
|
||||
label: string;
|
||||
llmModel: string;
|
||||
supportChat?: boolean;
|
||||
supportEmbed?: boolean;
|
||||
supportFunctionCalling?: boolean;
|
||||
supportRerank?: boolean;
|
||||
}
|
||||
|
||||
export interface ProviderPreset {
|
||||
description: string;
|
||||
icon: string;
|
||||
label: string;
|
||||
mode: 'hosted' | 'self-hosted';
|
||||
options: {
|
||||
chatPath?: string;
|
||||
embedPath?: string;
|
||||
llmEndpoint?: string;
|
||||
modelList?: ProviderModelPreset[];
|
||||
rerankPath?: string;
|
||||
};
|
||||
tags?: string[];
|
||||
value: string;
|
||||
}
|
||||
|
||||
const providerOptions = providerList as ProviderPreset[];
|
||||
|
||||
export const getProviderPresetByValue = (targetValue?: string) =>
|
||||
providerOptions.find((item) => item.value === targetValue);
|
||||
|
||||
/**
|
||||
* 根据传入的value,返回对应的icon属性
|
||||
* @param targetValue 要匹配的value值
|
||||
* @returns 匹配到的icon字符串,未匹配到返回空字符串
|
||||
*/
|
||||
export const getIconByValue = (targetValue: string): string => {
|
||||
const matchItem = providerOptions.value.find(
|
||||
(item) => item.value === targetValue,
|
||||
);
|
||||
|
||||
return matchItem?.icon || '';
|
||||
};
|
||||
export const getIconByValue = (targetValue: string): string =>
|
||||
getProviderPresetByValue(targetValue)?.icon || '';
|
||||
|
||||
export const isSvgString = (icon: any) => {
|
||||
if (typeof icon !== 'string') return false;
|
||||
// 简单判断:是否包含 SVG 根标签
|
||||
return icon.trim().startsWith('<svg') && icon.trim().endsWith('</svg>');
|
||||
};
|
||||
|
||||
export const getProviderBadgeText = (
|
||||
providerName?: string,
|
||||
providerType?: string,
|
||||
) => {
|
||||
const preset = getProviderPresetByValue(providerType);
|
||||
const source = providerName || preset?.label || providerType || 'AI';
|
||||
const ascii = source
|
||||
.replaceAll(/[^a-z]/gi, '')
|
||||
.slice(0, 2)
|
||||
.toUpperCase();
|
||||
|
||||
if (ascii) {
|
||||
return ascii;
|
||||
}
|
||||
|
||||
return source.replaceAll(/\s+/g, '').slice(0, 2).toUpperCase();
|
||||
};
|
||||
|
||||
export const providerPresets = providerOptions;
|
||||
|
||||
Reference in New Issue
Block a user