初始化
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { ref } from 'vue';
|
||||
|
||||
import providerList from './providerList.json';
|
||||
|
||||
const providerOptions =
|
||||
ref<Array<{ icon: string; label: string; options: any; value: string }>>(
|
||||
providerList,
|
||||
);
|
||||
|
||||
/**
|
||||
* 根据传入的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 isSvgString = (icon: any) => {
|
||||
if (typeof icon !== 'string') return false;
|
||||
// 简单判断:是否包含 SVG 根标签
|
||||
return icon.trim().startsWith('<svg') && icon.trim().endsWith('</svg>');
|
||||
};
|
||||
@@ -0,0 +1,71 @@
|
||||
import type { BooleanField, ModelAbilityItem } from './model-ability';
|
||||
|
||||
import type { llmType } from '#/api';
|
||||
|
||||
/**
|
||||
* 将 llm 数据转换为标签选中状态
|
||||
* @param llm LLM数据对象
|
||||
* @param modelAbility 模型能力数组
|
||||
* @returns 更新后的模型能力数组
|
||||
*/
|
||||
export const mapLlmToModelAbility = (
|
||||
llm: llmType,
|
||||
modelAbility: ModelAbilityItem[],
|
||||
): ModelAbilityItem[] => {
|
||||
return modelAbility.map((tag) => ({
|
||||
...tag,
|
||||
selected: Boolean(llm[tag.field as keyof llmType]),
|
||||
}));
|
||||
};
|
||||
|
||||
/**
|
||||
* 从标签选中状态生成 features 对象
|
||||
* @param modelAbility 模型能力数组
|
||||
* @returns 包含所有字段的features对象
|
||||
*/
|
||||
export const generateFeaturesFromModelAbility = (
|
||||
modelAbility: ModelAbilityItem[],
|
||||
): Record<BooleanField, boolean> => {
|
||||
const features: Partial<Record<BooleanField, boolean>> = {};
|
||||
|
||||
modelAbility.forEach((tag) => {
|
||||
features[tag.field] = tag.selected;
|
||||
});
|
||||
|
||||
return features as Record<BooleanField, boolean>;
|
||||
};
|
||||
|
||||
/**
|
||||
* 过滤显示选中的标签
|
||||
* @param modelAbility 模型能力数组
|
||||
* @returns 选中的标签数组
|
||||
*/
|
||||
export const getSelectedModelAbility = (
|
||||
modelAbility: ModelAbilityItem[],
|
||||
): ModelAbilityItem[] => {
|
||||
return modelAbility.filter((tag) => tag.selected);
|
||||
};
|
||||
|
||||
/**
|
||||
* 重置所有标签为未选中状态
|
||||
* @param modelAbility 模型能力数组
|
||||
*/
|
||||
export const resetModelAbility = (modelAbility: ModelAbilityItem[]): void => {
|
||||
modelAbility.forEach((tag) => {
|
||||
tag.selected = false;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 根据标签选中状态更新表单数据
|
||||
* @param modelAbility 模型能力数组
|
||||
* @param formData 表单数据对象
|
||||
*/
|
||||
export const updateFormDataFromModelAbility = (
|
||||
modelAbility: ModelAbilityItem[],
|
||||
formData: Record<BooleanField, boolean>,
|
||||
): void => {
|
||||
modelAbility.forEach((tag) => {
|
||||
formData[tag.field] = tag.selected;
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,169 @@
|
||||
import { $t } from '#/locales';
|
||||
|
||||
export type BooleanField =
|
||||
| 'supportAudio'
|
||||
| 'supportFree'
|
||||
| 'supportImage'
|
||||
| 'supportImageB64Only'
|
||||
| 'supportThinking'
|
||||
| 'supportTool'
|
||||
| 'supportToolMessage'
|
||||
| 'supportVideo';
|
||||
|
||||
export interface ModelAbilityItem {
|
||||
activeType: 'danger' | 'info' | 'primary' | 'success' | 'warning';
|
||||
defaultType: 'info';
|
||||
field: BooleanField;
|
||||
label: string;
|
||||
selected: boolean;
|
||||
value: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模型能力标签的默认配置
|
||||
* @returns ModelAbilityItem[] 模型能力配置数组
|
||||
*/
|
||||
export const getDefaultModelAbility = (): ModelAbilityItem[] => [
|
||||
{
|
||||
label: $t('llm.modelAbility.supportThinking'),
|
||||
value: 'thinking',
|
||||
defaultType: 'info',
|
||||
activeType: 'success',
|
||||
selected: false,
|
||||
field: 'supportThinking',
|
||||
},
|
||||
{
|
||||
label: $t('llm.modelAbility.supportTool'),
|
||||
value: 'tool',
|
||||
defaultType: 'info',
|
||||
activeType: 'success',
|
||||
selected: false,
|
||||
field: 'supportTool',
|
||||
},
|
||||
{
|
||||
label: $t('llm.modelAbility.supportVideo'),
|
||||
value: 'video',
|
||||
defaultType: 'info',
|
||||
activeType: 'success',
|
||||
selected: false,
|
||||
field: 'supportVideo',
|
||||
},
|
||||
{
|
||||
label: $t('llm.modelAbility.supportImage'),
|
||||
value: 'image',
|
||||
defaultType: 'info',
|
||||
activeType: 'success',
|
||||
selected: false,
|
||||
field: 'supportImage',
|
||||
},
|
||||
{
|
||||
label: $t('llm.modelAbility.supportFree'),
|
||||
value: 'free',
|
||||
defaultType: 'info',
|
||||
activeType: 'success',
|
||||
selected: false,
|
||||
field: 'supportFree',
|
||||
},
|
||||
{
|
||||
label: $t('llm.modelAbility.supportAudio'),
|
||||
value: 'audio',
|
||||
defaultType: 'info',
|
||||
activeType: 'success',
|
||||
selected: false,
|
||||
field: 'supportAudio',
|
||||
},
|
||||
{
|
||||
label: $t('llm.modelAbility.supportImageB64Only'),
|
||||
value: 'imageB64',
|
||||
defaultType: 'info',
|
||||
activeType: 'success',
|
||||
selected: false,
|
||||
field: 'supportImageB64Only',
|
||||
},
|
||||
{
|
||||
label: $t('llm.modelAbility.supportToolMessage'),
|
||||
value: 'toolMessage',
|
||||
defaultType: 'info',
|
||||
activeType: 'success',
|
||||
selected: true,
|
||||
field: 'supportToolMessage',
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* 根据字段数组获取对应的标签选中状态
|
||||
* @param modelAbility 模型能力数组
|
||||
* @param fields 需要获取的字段数组
|
||||
* @returns 以字段名为键、选中状态为值的对象
|
||||
*/
|
||||
export const getTagsSelectedStatus = (
|
||||
modelAbility: ModelAbilityItem[],
|
||||
fields: BooleanField[],
|
||||
): Record<BooleanField, boolean> => {
|
||||
const result: Partial<Record<BooleanField, boolean>> = {};
|
||||
|
||||
fields.forEach((field) => {
|
||||
const tagItem = modelAbility.find((tag) => tag.field === field);
|
||||
result[field] = tagItem?.selected ?? false;
|
||||
});
|
||||
|
||||
return result as Record<BooleanField, boolean>;
|
||||
};
|
||||
|
||||
/**
|
||||
* 同步标签选中状态与formData中的布尔字段
|
||||
* @param modelAbility 模型能力数组
|
||||
* @param formData 表单数据对象
|
||||
*/
|
||||
export const syncTagSelectedStatus = (
|
||||
modelAbility: ModelAbilityItem[],
|
||||
formData: Record<BooleanField, boolean>,
|
||||
): void => {
|
||||
modelAbility.forEach((tag) => {
|
||||
tag.selected = formData[tag.field] ?? false;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 处理标签点击事件
|
||||
* @param modelAbility 模型能力数组
|
||||
* @param item 被点击的标签项
|
||||
* @param formData 表单数据对象
|
||||
*/
|
||||
export const handleTagClick = (
|
||||
// modelAbility: ModelAbilityItem[],
|
||||
item: ModelAbilityItem,
|
||||
formData: Record<BooleanField, boolean>,
|
||||
): void => {
|
||||
// 切换标签选中状态
|
||||
item.selected = !item.selected;
|
||||
|
||||
// 同步更新formData中的布尔字段
|
||||
formData[item.field] = item.selected;
|
||||
};
|
||||
|
||||
/**
|
||||
* 根据字段获取对应的标签项
|
||||
* @param modelAbility 模型能力数组
|
||||
* @param field 布尔字段名
|
||||
* @returns 标签项 | undefined
|
||||
*/
|
||||
export const getTagByField = (
|
||||
modelAbility: ModelAbilityItem[],
|
||||
field: BooleanField,
|
||||
): ModelAbilityItem | undefined => {
|
||||
return modelAbility.find((tag) => tag.field === field);
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取所有支持的BooleanField数组
|
||||
*/
|
||||
export const getAllBooleanFields = (): BooleanField[] => [
|
||||
'supportThinking',
|
||||
'supportTool',
|
||||
'supportImage',
|
||||
'supportImageB64Only',
|
||||
'supportVideo',
|
||||
'supportAudio',
|
||||
'supportFree',
|
||||
];
|
||||
@@ -0,0 +1,16 @@
|
||||
import { $t } from '@easyflow/locales';
|
||||
|
||||
export const modelTypes = [
|
||||
{
|
||||
label: $t('llmProvider.chatModel'),
|
||||
value: 'chatModel',
|
||||
},
|
||||
{
|
||||
label: $t('llmProvider.embeddingModel'),
|
||||
value: 'embeddingModel',
|
||||
},
|
||||
{
|
||||
label: $t('llmProvider.rerankModel'),
|
||||
value: 'rerankModel',
|
||||
},
|
||||
];
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user