feat(ai): 添加 AI 对话聊天和 API 密钥管理功能
- 新增 AI 对话聊天管理页面,包括对话列表和消息列表 - 新增 API 密钥管理页面,包括密钥列表和表单 - 添加相关 API 接口和数据模型 - 集成表单和表格组件,实现基本的 CRUD 操作
This commit is contained in:
277
apps/web-antd/src/views/ai/model/chatRole/data.ts
Normal file
277
apps/web-antd/src/views/ai/model/chatRole/data.ts
Normal file
@@ -0,0 +1,277 @@
|
||||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { getSimpleKnowledgeList } from '#/api/ai/knowledge/knowledge';
|
||||
import { getModelSimpleList } from '#/api/ai/model/model';
|
||||
import { getToolSimpleList } from '#/api/ai/model/tool';
|
||||
import {
|
||||
AiModelTypeEnum,
|
||||
CommonStatusEnum,
|
||||
DICT_TYPE,
|
||||
getDictOptions,
|
||||
} from '#/utils';
|
||||
/** 新增/修改的表单 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'id',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'formType',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'name',
|
||||
label: '角色名称',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'ImageUpload',
|
||||
fieldName: 'avatar',
|
||||
label: '角色头像',
|
||||
componentProps: {
|
||||
maxSize: 1,
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'modelId',
|
||||
label: '绑定模型',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择绑定模型',
|
||||
api: () => getModelSimpleList(AiModelTypeEnum.CHAT),
|
||||
labelField: 'name',
|
||||
valueField: 'id',
|
||||
allowClear: true,
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['formType'],
|
||||
show: (values) => {
|
||||
return values.formType === 'create' || values.formType === 'update';
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'category',
|
||||
label: '角色类别',
|
||||
rules: 'required',
|
||||
dependencies: {
|
||||
triggerFields: ['formType'],
|
||||
show: (values) => {
|
||||
return values.formType === 'create' || values.formType === 'update';
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Textarea',
|
||||
fieldName: 'description',
|
||||
label: '角色描述',
|
||||
componentProps: {
|
||||
placeholder: '请输入角色描述',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'systemMessage',
|
||||
label: '角色设定',
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入角色设定',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'knowledgeIds',
|
||||
label: '引用知识库',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择引用知识库',
|
||||
api: getSimpleKnowledgeList,
|
||||
labelField: 'name',
|
||||
mode: 'multiple',
|
||||
valueField: 'id',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'toolIds',
|
||||
label: '引用工具',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择引用工具',
|
||||
api: getToolSimpleList,
|
||||
mode: 'multiple',
|
||||
labelField: 'name',
|
||||
valueField: 'id',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'publicStatus',
|
||||
label: '是否公开',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING, 'boolean'),
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
defaultValue: true,
|
||||
dependencies: {
|
||||
triggerFields: ['formType'],
|
||||
show: (values) => {
|
||||
return values.formType === 'create' || values.formType === 'update';
|
||||
},
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'sort',
|
||||
label: '角色排序',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
controlsPosition: 'right',
|
||||
placeholder: '请输入角色排序',
|
||||
class: 'w-full',
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['formType'],
|
||||
show: (values) => {
|
||||
return values.formType === 'create' || values.formType === 'update';
|
||||
},
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '开启状态',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['formType'],
|
||||
show: (values) => {
|
||||
return values.formType === 'create' || values.formType === 'update';
|
||||
},
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '角色名称',
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
fieldName: 'category',
|
||||
label: '角色类别',
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
fieldName: 'publicStatus',
|
||||
label: '是否公开',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择是否公开',
|
||||
options: getDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING, 'boolean'),
|
||||
allowClear: true,
|
||||
},
|
||||
defaultValue: true,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'name',
|
||||
title: '角色名称',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
title: '绑定模型',
|
||||
field: 'modelName',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
title: '角色头像',
|
||||
slots: { default: 'avatar' },
|
||||
minWidth: 140,
|
||||
},
|
||||
{
|
||||
title: '角色类别',
|
||||
field: 'category',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
title: '角色描述',
|
||||
field: 'description',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
title: '角色设定',
|
||||
field: 'systemMessage',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
title: '知识库',
|
||||
slots: { default: 'knowledgeIds' },
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
title: '工具',
|
||||
slots: { default: 'toolIds' },
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'publicStatus',
|
||||
title: '是否公开',
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
|
||||
},
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
title: '角色排序',
|
||||
field: 'sort',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 130,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user