committed by
GitHub
97 changed files with 4029 additions and 69 deletions
@ -0,0 +1,15 @@ |
|||
<script lang="ts" setup> |
|||
import { Page } from '@vben/common-ui'; |
|||
|
|||
import { AIToolDefinitionTable } from '@abp/ai-management'; |
|||
|
|||
defineOptions({ |
|||
name: 'Vben5AIToolDefinitions', |
|||
}); |
|||
</script> |
|||
|
|||
<template> |
|||
<Page> |
|||
<AIToolDefinitionTable /> |
|||
</Page> |
|||
</template> |
|||
@ -1,3 +1,4 @@ |
|||
export { useAIToolsApi } from './useAIToolsApi'; |
|||
export { useChatsApi } from './useChatsApi'; |
|||
export { useConversationsApi } from './useConversationsApi'; |
|||
export { useWorkspaceDefinitionsApi } from './useWorkspaceDefinitionsApi'; |
|||
|
|||
@ -0,0 +1,114 @@ |
|||
import type { ListResultDto, PagedResultDto } from '@abp/core'; |
|||
|
|||
import type { |
|||
AIToolDefinitionRecordCreateDto, |
|||
AIToolDefinitionRecordDto, |
|||
AIToolDefinitionRecordGetPagedListInput, |
|||
AIToolDefinitionRecordUpdateDto, |
|||
AIToolProviderDto, |
|||
} from '../types/tools'; |
|||
|
|||
import { useRequest } from '@abp/request'; |
|||
|
|||
export function useAIToolsApi() { |
|||
const { cancel, request } = useRequest(); |
|||
|
|||
/** |
|||
* 获取AI工具详情 |
|||
* @param id AI工具id |
|||
* @returns AI工具详情 |
|||
*/ |
|||
function getApi(id: string): Promise<AIToolDefinitionRecordDto> { |
|||
return request<AIToolDefinitionRecordDto>( |
|||
`/api/ai-management/tools/${id}`, |
|||
{ |
|||
method: 'GET', |
|||
}, |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* 获取AI工具分页列表 |
|||
* @param input 查询过滤参数 |
|||
* @returns AI工具分页列表 |
|||
*/ |
|||
function getPagedListApi( |
|||
input?: AIToolDefinitionRecordGetPagedListInput, |
|||
): Promise<PagedResultDto<AIToolDefinitionRecordDto>> { |
|||
return request<PagedResultDto<AIToolDefinitionRecordDto>>( |
|||
'/api/ai-management/tools', |
|||
{ |
|||
method: 'GET', |
|||
params: input, |
|||
}, |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* 获取可用AI工具提供者列表 |
|||
* @returns AI工具提供者列表 |
|||
*/ |
|||
function getAvailableProviderListApi(): Promise< |
|||
ListResultDto<AIToolProviderDto> |
|||
> { |
|||
return request<ListResultDto<AIToolProviderDto>>( |
|||
'/api/ai-management/tools/available-providers', |
|||
{ |
|||
method: 'GET', |
|||
}, |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* 删除AI工具 |
|||
* @param id AI工具id |
|||
*/ |
|||
function deleteApi(id: string): Promise<void> { |
|||
return request(`/api/ai-management/tools/${id}`, { |
|||
method: 'DELETE', |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* 新增AI工具 |
|||
* @param input 参数 |
|||
* @returns AI工具详情 |
|||
*/ |
|||
function createApi( |
|||
input: AIToolDefinitionRecordCreateDto, |
|||
): Promise<AIToolDefinitionRecordDto> { |
|||
return request<AIToolDefinitionRecordDto>(`/api/ai-management/tools`, { |
|||
data: input, |
|||
method: 'POST', |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* 编辑AI工具 |
|||
* @param id AI工具id |
|||
* @param input 参数 |
|||
* @returns AI工具详情 |
|||
*/ |
|||
function updateApi( |
|||
id: string, |
|||
input: AIToolDefinitionRecordUpdateDto, |
|||
): Promise<AIToolDefinitionRecordDto> { |
|||
return request<AIToolDefinitionRecordDto>( |
|||
`/api/ai-management/tools/${id}`, |
|||
{ |
|||
data: input, |
|||
method: 'PUT', |
|||
}, |
|||
); |
|||
} |
|||
|
|||
return { |
|||
cancel, |
|||
createApi, |
|||
deleteApi, |
|||
getApi, |
|||
getAvailableProviderListApi, |
|||
getPagedListApi, |
|||
updateApi, |
|||
}; |
|||
} |
|||
@ -1,2 +1,3 @@ |
|||
export { default as Conversations } from './conversations/index.vue'; |
|||
export { default as AIToolDefinitionTable } from './tools/AIToolDefinitionTable.vue'; |
|||
export { default as WorkspaceDefinitionTable } from './workspaces/WorkspaceDefinitionTable.vue'; |
|||
|
|||
@ -0,0 +1,321 @@ |
|||
<script setup lang="ts"> |
|||
import type { PropertyInfo } from '@abp/ui'; |
|||
import type { FormInstance } from 'ant-design-vue/lib/form'; |
|||
import type { |
|||
DefaultOptionType, |
|||
SelectProps, |
|||
SelectValue, |
|||
} from 'ant-design-vue/lib/select'; |
|||
|
|||
import type { |
|||
AIToolDefinitionRecordDto, |
|||
AIToolProviderDto, |
|||
} from '../../types/tools'; |
|||
|
|||
import { computed, nextTick, ref, useTemplateRef, watch } from 'vue'; |
|||
|
|||
import { useVbenModal } from '@vben/common-ui'; |
|||
import { $t } from '@vben/locales'; |
|||
|
|||
import { useAuthorization } from '@abp/core'; |
|||
import { LocalizableInput, PropertyTable, useMessage } from '@abp/ui'; |
|||
import { |
|||
Checkbox, |
|||
Form, |
|||
FormItemRest, |
|||
Input, |
|||
InputNumber, |
|||
Select, |
|||
Tabs, |
|||
} from 'ant-design-vue'; |
|||
|
|||
import { useAIToolsApi } from '../../api/useAIToolsApi'; |
|||
import { AIToolDefinitionPermissions } from '../../constants/permissions'; |
|||
|
|||
const emit = defineEmits<{ |
|||
(event: 'change', data: AIToolDefinitionVto): void; |
|||
}>(); |
|||
const FormItem = Form.Item; |
|||
const TabPane = Tabs.TabPane; |
|||
|
|||
type AIToolDefinitionVto = Omit<AIToolDefinitionRecordDto, 'creationTime'> & { |
|||
apiKey?: string; |
|||
}; |
|||
|
|||
// 默认表单数据 |
|||
const defaultModel: AIToolDefinitionVto = { |
|||
id: '', |
|||
name: '', |
|||
isEnabled: true, |
|||
isGlobal: false, |
|||
isSystem: false, |
|||
provider: '', |
|||
extraProperties: {}, |
|||
}; |
|||
|
|||
const message = useMessage(); |
|||
const { isGranted } = useAuthorization(); |
|||
const { createApi, updateApi, getApi, getAvailableProviderListApi } = |
|||
useAIToolsApi(); |
|||
// 表单 |
|||
const form = useTemplateRef<FormInstance>('formEl'); |
|||
// 表单数据 |
|||
const formModel = ref<AIToolDefinitionVto>({ ...defaultModel }); |
|||
// 工具提供者选项 |
|||
const aiToolProviders = ref<AIToolProviderDto[]>([]); |
|||
const currentAIToolProvider = ref<AIToolProviderDto>(); |
|||
const getAIToolOptions = computed<NonNullable<SelectProps['options']>>(() => { |
|||
return aiToolProviders.value.map((provider) => { |
|||
return { |
|||
label: provider.name, |
|||
value: provider.name, |
|||
properties: provider.properties, |
|||
}; |
|||
}); |
|||
}); |
|||
// 表单允许编辑 |
|||
const getIsAllowUpdate = computed<boolean>(() => { |
|||
if (formModel.value.id) { |
|||
if (formModel.value.isSystem) { |
|||
return false; |
|||
} |
|||
return isGranted(AIToolDefinitionPermissions.Update); |
|||
} |
|||
return isGranted(AIToolDefinitionPermissions.Create); |
|||
}); |
|||
|
|||
watch( |
|||
() => getIsAllowUpdate.value, |
|||
(allowUpdate) => { |
|||
nextTick(() => { |
|||
modalApi.setState({ showConfirmButton: allowUpdate }); |
|||
}); |
|||
}, |
|||
); |
|||
|
|||
// 工作区编辑模态框 |
|||
const [Modal, modalApi] = useVbenModal({ |
|||
title: $t('AIManagement.Tools:New'), |
|||
class: 'w-1/2', |
|||
closeOnClickModal: false, |
|||
closeOnPressEscape: false, |
|||
fullscreenButton: false, |
|||
onConfirm: onSubmit, |
|||
async onOpenChange(isOpen) { |
|||
isOpen && (await onInit()); |
|||
}, |
|||
}); |
|||
/** 初始化工作区数据 */ |
|||
async function onInit() { |
|||
try { |
|||
modalApi.setState({ |
|||
loading: true, |
|||
title: $t('AIManagement.Tools:New'), |
|||
}); |
|||
await onInitProviderOptions(); |
|||
const { id } = modalApi.getData<AIToolDefinitionVto>(); |
|||
if (!id) { |
|||
formModel.value = { ...defaultModel }; |
|||
currentAIToolProvider.value = undefined; |
|||
return; |
|||
} |
|||
const dto = await getApi(id); |
|||
formModel.value = dto; |
|||
currentAIToolProvider.value = aiToolProviders.value.find( |
|||
(p) => p.name === dto.provider, |
|||
); |
|||
modalApi.setState({ |
|||
title: $t('AIManagement.Tools:Edit'), |
|||
}); |
|||
} finally { |
|||
modalApi.setState({ |
|||
loading: false, |
|||
}); |
|||
} |
|||
} |
|||
/** 初始化模型选项 */ |
|||
async function onInitProviderOptions() { |
|||
const { items } = await getAvailableProviderListApi(); |
|||
aiToolProviders.value = items; |
|||
} |
|||
|
|||
function onProviderChange(_: SelectValue, option: DefaultOptionType) { |
|||
const provider = option as AIToolProviderDto; |
|||
currentAIToolProvider.value = provider; |
|||
if (provider) { |
|||
const propertites: Record<string, any> = {}; |
|||
provider.properties.forEach((prop) => { |
|||
propertites[prop.name] = ''; |
|||
}); |
|||
formModel.value.extraProperties ??= {}; |
|||
formModel.value.extraProperties = propertites; |
|||
} |
|||
} |
|||
|
|||
function onPropChange(key: string, prop: PropertyInfo) { |
|||
const propertites = formModel.value.extraProperties ?? {}; |
|||
propertites[key] = {}; |
|||
propertites[key][prop.key] = prop.value; |
|||
formModel.value.extraProperties = propertites; |
|||
} |
|||
function onPropDelete(key: string, prop: PropertyInfo) { |
|||
const propertites = formModel.value.extraProperties ?? {}; |
|||
propertites[key] = {}; |
|||
delete propertites[key][prop.key]; |
|||
formModel.value.extraProperties = propertites; |
|||
} |
|||
|
|||
/** 提交表单 */ |
|||
async function onSubmit() { |
|||
await form.value?.validate(); |
|||
try { |
|||
modalApi.setState({ submitting: true }); |
|||
const vto = await (formModel.value.id |
|||
? updateApi(formModel.value.id, formModel.value) |
|||
: createApi(formModel.value)); |
|||
formModel.value = vto; |
|||
message.success($t('AbpUi.SavedSuccessfully')); |
|||
emit('change', vto); |
|||
modalApi.close(); |
|||
} finally { |
|||
modalApi.setState({ submitting: false }); |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
<template> |
|||
<Modal> |
|||
<Form |
|||
:model="formModel" |
|||
ref="formEl" |
|||
:label-col="{ span: 6 }" |
|||
:wrapper-col="{ span: 18 }" |
|||
:disabled="!getIsAllowUpdate" |
|||
scroll-to-first-error |
|||
> |
|||
<Tabs> |
|||
<TabPane key="basic" :tab="$t('AIManagement.BasicInfo')" force-render> |
|||
<FormItem |
|||
:label="$t('AIManagement.DisplayName:IsEnabled')" |
|||
name="isEnabled" |
|||
> |
|||
<Checkbox v-model:checked="formModel.isEnabled"> |
|||
{{ $t('AIManagement.DisplayName:IsEnabled') }} |
|||
</Checkbox> |
|||
</FormItem> |
|||
<FormItem |
|||
:label="$t('AIManagement.DisplayName:IsGlobal')" |
|||
name="isEnabled" |
|||
> |
|||
<Checkbox v-model:checked="formModel.isGlobal"> |
|||
{{ $t('AIManagement.DisplayName:IsGlobal') }} |
|||
</Checkbox> |
|||
</FormItem> |
|||
<FormItem |
|||
:label="$t('AIManagement.DisplayName:ToolProvider')" |
|||
name="provider" |
|||
required |
|||
> |
|||
<Select |
|||
:options="getAIToolOptions" |
|||
v-model:value="formModel.provider" |
|||
@change="onProviderChange" |
|||
/> |
|||
</FormItem> |
|||
<FormItem |
|||
:label="$t('AIManagement.DisplayName:Name')" |
|||
name="name" |
|||
required |
|||
> |
|||
<Input v-model:value="formModel.name" /> |
|||
</FormItem> |
|||
<FormItem |
|||
:label="$t('AIManagement.DisplayName:Description')" |
|||
name="description" |
|||
> |
|||
<LocalizableInput v-model:value="formModel.description" /> |
|||
</FormItem> |
|||
</TabPane> |
|||
<TabPane |
|||
v-if="currentAIToolProvider" |
|||
key="propertites" |
|||
:tab="$t('AIManagement.Propertites')" |
|||
force-render |
|||
> |
|||
<div class="h-[500px] overflow-y-auto rounded bg-gray-50 p-4"> |
|||
<template |
|||
v-for="prop in currentAIToolProvider.properties" |
|||
:key="prop.name" |
|||
> |
|||
<FormItem |
|||
v-if="prop.valueType === 'String'" |
|||
:extra="prop.description" |
|||
:label="prop.displayName" |
|||
:name="['extraProperties', prop.name]" |
|||
:required="prop.required" |
|||
> |
|||
<Input v-model:value="formModel.extraProperties[prop.name]" /> |
|||
</FormItem> |
|||
<FormItem |
|||
v-if="prop.valueType === 'Number'" |
|||
:extra="prop.description" |
|||
:label="prop.displayName" |
|||
:name="['extraProperties', prop.name]" |
|||
:required="prop.required" |
|||
> |
|||
<InputNumber |
|||
class="w-full" |
|||
:min="0" |
|||
v-model:value="formModel.extraProperties[prop.name]" |
|||
/> |
|||
</FormItem> |
|||
<FormItem |
|||
v-else-if="prop.valueType === 'Boolean'" |
|||
:extra="prop.description" |
|||
:label="prop.displayName" |
|||
:name="['extraProperties', prop.name]" |
|||
:required="prop.required" |
|||
> |
|||
<Checkbox |
|||
v-model:checked="formModel.extraProperties[prop.name]" |
|||
> |
|||
{{ prop.displayName }} |
|||
</Checkbox> |
|||
</FormItem> |
|||
<FormItem |
|||
v-else-if="prop.valueType === 'Select'" |
|||
:extra="prop.description" |
|||
:label="prop.displayName" |
|||
:name="['extraProperties', prop.name]" |
|||
:required="prop.required" |
|||
> |
|||
<Select |
|||
class="w-full" |
|||
:options="prop.options" |
|||
:field-names="{ label: 'name', value: 'value' }" |
|||
v-model:value="formModel.extraProperties[prop.name]" |
|||
/> |
|||
</FormItem> |
|||
<FormItem |
|||
v-else-if="prop.valueType === 'Dictionary'" |
|||
:extra="prop.description" |
|||
:label="prop.displayName" |
|||
:name="['extraProperties', prop.name]" |
|||
> |
|||
<FormItemRest> |
|||
<PropertyTable |
|||
:data="formModel.extraProperties[prop.name]" |
|||
@change="(data) => onPropChange(prop.name, data)" |
|||
@delete="(data) => onPropDelete(prop.name, data)" |
|||
/> |
|||
</FormItemRest> |
|||
</FormItem> |
|||
</template> |
|||
</div> |
|||
</TabPane> |
|||
</Tabs> |
|||
</Form> |
|||
</Modal> |
|||
</template> |
|||
|
|||
<style scoped></style> |
|||
@ -0,0 +1,236 @@ |
|||
<script setup lang="ts"> |
|||
import type { VxeGridProps } from '@abp/ui'; |
|||
|
|||
import type { VbenFormProps } from '@vben/common-ui'; |
|||
|
|||
import type { AIToolDefinitionRecordDto } from '../../types/tools'; |
|||
|
|||
import { defineAsyncComponent, h } from 'vue'; |
|||
|
|||
import { useVbenModal } from '@vben/common-ui'; |
|||
import { $t } from '@vben/locales'; |
|||
|
|||
import { |
|||
useAuthorization, |
|||
useLocalization, |
|||
useLocalizationSerializer, |
|||
} from '@abp/core'; |
|||
import { useVbenVxeGrid } from '@abp/ui'; |
|||
import { |
|||
CheckOutlined, |
|||
CloseOutlined, |
|||
DeleteOutlined, |
|||
EditOutlined, |
|||
PlusOutlined, |
|||
} from '@ant-design/icons-vue'; |
|||
import { Button, message, Modal } from 'ant-design-vue'; |
|||
|
|||
import { useAIToolsApi } from '../../api/useAIToolsApi'; |
|||
import { AIToolDefinitionPermissions } from '../../constants/permissions'; |
|||
|
|||
defineOptions({ |
|||
name: 'WorkspaceDefinitionTable', |
|||
}); |
|||
const { deleteApi, getPagedListApi } = useAIToolsApi(); |
|||
const { isGranted } = useAuthorization(); |
|||
const { Lr } = useLocalization(); |
|||
const { deserialize: deserializeLocalizableString } = |
|||
useLocalizationSerializer(); |
|||
|
|||
const formOptions: VbenFormProps = { |
|||
// 默认展开 |
|||
collapsed: true, |
|||
collapsedRows: 2, |
|||
schema: [ |
|||
{ |
|||
component: 'Input', |
|||
fieldName: 'filter', |
|||
formItemClass: 'col-span-2 items-baseline', |
|||
label: $t('AbpUi.Search'), |
|||
}, |
|||
], |
|||
// 控制表单是否显示折叠按钮 |
|||
showCollapseButton: true, |
|||
// 按下回车时是否提交表单 |
|||
submitOnEnter: true, |
|||
wrapperClass: 'grid-cols-4', |
|||
}; |
|||
|
|||
const gridOptions: VxeGridProps<AIToolDefinitionRecordDto> = { |
|||
columns: [ |
|||
{ |
|||
align: 'left', |
|||
field: 'name', |
|||
sortable: true, |
|||
title: $t('AIManagement.DisplayName:Name'), |
|||
}, |
|||
{ |
|||
align: 'left', |
|||
field: 'provider', |
|||
sortable: true, |
|||
title: $t('AIManagement.DisplayName:ToolProvider'), |
|||
width: 150, |
|||
}, |
|||
{ |
|||
align: 'left', |
|||
field: 'description', |
|||
formatter: ({ row }) => { |
|||
if (!row.description) { |
|||
return ''; |
|||
} |
|||
const localizableString = deserializeLocalizableString(row.description); |
|||
return Lr(localizableString.resourceName, localizableString.name); |
|||
}, |
|||
sortable: true, |
|||
title: $t('AIManagement.DisplayName:Description'), |
|||
width: 180, |
|||
}, |
|||
{ |
|||
align: 'left', |
|||
field: 'isEnabled', |
|||
slots: { default: 'isEnabled' }, |
|||
sortable: true, |
|||
title: $t('AIManagement.DisplayName:IsEnabled'), |
|||
width: 150, |
|||
}, |
|||
{ |
|||
align: 'left', |
|||
field: 'isGlobal', |
|||
slots: { default: 'isGlobal' }, |
|||
sortable: true, |
|||
title: $t('AIManagement.DisplayName:IsGlobal'), |
|||
width: 150, |
|||
}, |
|||
{ |
|||
field: 'actions', |
|||
fixed: 'right', |
|||
slots: { default: 'actions' }, |
|||
title: $t('AbpUi.Actions'), |
|||
width: 220, |
|||
visible: isGranted([ |
|||
AIToolDefinitionPermissions.Default, |
|||
AIToolDefinitionPermissions.Delete, |
|||
]), |
|||
}, |
|||
], |
|||
exportConfig: {}, |
|||
keepSource: true, |
|||
proxyConfig: { |
|||
ajax: { |
|||
query: async ({ page, sort }, formValues) => { |
|||
const sorting = sort.order ? `${sort.field} ${sort.order}` : undefined; |
|||
return await getPagedListApi({ |
|||
sorting, |
|||
maxResultCount: page.pageSize, |
|||
skipCount: (page.currentPage - 1) * page.pageSize, |
|||
...formValues, |
|||
}); |
|||
}, |
|||
}, |
|||
response: { |
|||
total: 'totalCount', |
|||
list: 'items', |
|||
}, |
|||
}, |
|||
sortConfig: { |
|||
remote: true, |
|||
allowBtn: true, |
|||
}, |
|||
toolbarConfig: { |
|||
custom: true, |
|||
export: true, |
|||
// import: true, |
|||
refresh: { |
|||
code: 'query', |
|||
}, |
|||
zoom: true, |
|||
}, |
|||
}; |
|||
|
|||
const [Grid, gridApi] = useVbenVxeGrid<AIToolDefinitionRecordDto>({ |
|||
formOptions, |
|||
gridOptions, |
|||
}); |
|||
|
|||
const [AIToolDefinitionModal, modalApi] = useVbenModal({ |
|||
connectedComponent: defineAsyncComponent( |
|||
() => import('./AIToolDefinitionModal.vue'), |
|||
), |
|||
}); |
|||
|
|||
function onCreate() { |
|||
modalApi.setData({}); |
|||
modalApi.open(); |
|||
} |
|||
|
|||
function onUpdate(row: AIToolDefinitionRecordDto) { |
|||
modalApi.setData(row); |
|||
modalApi.open(); |
|||
} |
|||
|
|||
async function onDelete(row: AIToolDefinitionRecordDto) { |
|||
Modal.confirm({ |
|||
centered: true, |
|||
content: $t('AbpUi.ItemWillBeDeletedMessage'), |
|||
onOk: async () => { |
|||
await deleteApi(row.id); |
|||
message.success($t('AbpUi.DeletedSuccessfully')); |
|||
gridApi.query(); |
|||
}, |
|||
title: $t('AbpUi.AreYouSure'), |
|||
}); |
|||
} |
|||
</script> |
|||
|
|||
<template> |
|||
<Grid :table-title="$t('AIManagement.Tools')"> |
|||
<template #toolbar-tools> |
|||
<Button |
|||
v-access:code="[AIToolDefinitionPermissions.Create]" |
|||
:icon="h(PlusOutlined)" |
|||
type="primary" |
|||
@click="onCreate" |
|||
> |
|||
{{ $t('AIManagement.Tools:New') }} |
|||
</Button> |
|||
</template> |
|||
<template #isEnabled="{ row }"> |
|||
<div class="flex flex-row justify-center"> |
|||
<CheckOutlined v-if="row.isEnabled" class="text-green-500" /> |
|||
<CloseOutlined v-else class="text-red-500" /> |
|||
</div> |
|||
</template> |
|||
<template #isGlobal="{ row }"> |
|||
<div class="flex flex-row justify-center"> |
|||
<CheckOutlined v-if="row.isGlobal" class="text-green-500" /> |
|||
<CloseOutlined v-else class="text-red-500" /> |
|||
</div> |
|||
</template> |
|||
<template #actions="{ row }"> |
|||
<div class="flex flex-row"> |
|||
<Button |
|||
v-access:code="[AIToolDefinitionPermissions.Default]" |
|||
:icon="h(EditOutlined)" |
|||
block |
|||
type="link" |
|||
@click="onUpdate(row)" |
|||
> |
|||
{{ $t('AbpUi.Edit') }} |
|||
</Button> |
|||
<Button |
|||
v-access:code="[AIToolDefinitionPermissions.Delete]" |
|||
:icon="h(DeleteOutlined)" |
|||
block |
|||
danger |
|||
type="link" |
|||
@click="onDelete(row)" |
|||
> |
|||
{{ $t('AbpUi.Delete') }} |
|||
</Button> |
|||
</div> |
|||
</template> |
|||
</Grid> |
|||
<AIToolDefinitionModal @change="() => gridApi.query()" /> |
|||
</template> |
|||
|
|||
<style lang="scss" scoped></style> |
|||
@ -1,3 +1,4 @@ |
|||
export * from './chats'; |
|||
export * from './conversations'; |
|||
export * from './tools'; |
|||
export * from './workspaces'; |
|||
|
|||
@ -0,0 +1,61 @@ |
|||
import type { |
|||
ExtensibleAuditedEntityDto, |
|||
ExtensibleObject, |
|||
IHasConcurrencyStamp, |
|||
NameValue, |
|||
PagedAndSortedResultRequestDto, |
|||
} from '@abp/core'; |
|||
|
|||
interface AIToolDefinitionRecordDto |
|||
extends ExtensibleAuditedEntityDto<string>, IHasConcurrencyStamp { |
|||
description?: string; |
|||
isEnabled: boolean; |
|||
isGlobal: boolean; |
|||
isSystem: boolean; |
|||
name: string; |
|||
provider: string; |
|||
stateCheckers?: string; |
|||
} |
|||
|
|||
interface AIToolDefinitionRecordCreateOrUpdateDto extends ExtensibleObject { |
|||
description?: string; |
|||
isEnabled: boolean; |
|||
isGlobal: boolean; |
|||
provider: string; |
|||
stateCheckers?: string; |
|||
} |
|||
|
|||
interface AIToolDefinitionRecordCreateDto extends AIToolDefinitionRecordCreateOrUpdateDto { |
|||
name: string; |
|||
} |
|||
|
|||
interface AIToolDefinitionRecordUpdateDto |
|||
extends AIToolDefinitionRecordCreateOrUpdateDto, IHasConcurrencyStamp {} |
|||
|
|||
interface AIToolDefinitionRecordGetPagedListInput extends PagedAndSortedResultRequestDto { |
|||
filter?: string; |
|||
isEnabled?: boolean; |
|||
provider?: string; |
|||
} |
|||
|
|||
interface AIToolPropertyDescriptorDto { |
|||
description?: string; |
|||
displayName: string; |
|||
name: string; |
|||
options: NameValue<any>[]; |
|||
required: boolean; |
|||
valueType: string; |
|||
} |
|||
|
|||
interface AIToolProviderDto { |
|||
name: string; |
|||
properties: AIToolPropertyDescriptorDto[]; |
|||
} |
|||
|
|||
export type { |
|||
AIToolDefinitionRecordCreateDto, |
|||
AIToolDefinitionRecordDto, |
|||
AIToolDefinitionRecordGetPagedListInput, |
|||
AIToolDefinitionRecordUpdateDto, |
|||
AIToolProviderDto, |
|||
}; |
|||
@ -0,0 +1,376 @@ |
|||
// <auto-generated />
|
|||
using System; |
|||
using LINGYUN.Abp.MicroService.AIService; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Infrastructure; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
|||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace LINGYUN.Abp.MicroService.AIService.Migrations |
|||
{ |
|||
[DbContext(typeof(AIServiceMigrationsDbContext))] |
|||
[Migration("20260327051206_Add-AI-Tool-Definition-Record")] |
|||
partial class AddAIToolDefinitionRecord |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void BuildTargetModel(ModelBuilder modelBuilder) |
|||
{ |
|||
#pragma warning disable 612, 618
|
|||
modelBuilder |
|||
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.PostgreSql) |
|||
.HasAnnotation("ProductVersion", "10.0.0") |
|||
.HasAnnotation("Relational:MaxIdentifierLength", 63); |
|||
|
|||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); |
|||
|
|||
modelBuilder.Entity("LINGYUN.Abp.AIManagement.Chats.ConversationRecord", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<DateTime>("CreatedAt") |
|||
.HasColumnType("timestamp with time zone"); |
|||
|
|||
b.Property<DateTime>("CreationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("CreationTime"); |
|||
|
|||
b.Property<Guid?>("CreatorId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("CreatorId"); |
|||
|
|||
b.Property<DateTime>("ExpiredAt") |
|||
.HasColumnType("timestamp with time zone"); |
|||
|
|||
b.Property<DateTime?>("LastModificationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("LastModificationTime"); |
|||
|
|||
b.Property<Guid?>("LastModifierId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("LastModifierId"); |
|||
|
|||
b.Property<string>("Name") |
|||
.IsRequired() |
|||
.HasMaxLength(50) |
|||
.HasColumnType("character varying(50)"); |
|||
|
|||
b.Property<Guid?>("TenantId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("TenantId"); |
|||
|
|||
b.Property<DateTime?>("UpdateAt") |
|||
.HasColumnType("timestamp with time zone"); |
|||
|
|||
b.Property<string>("Workspace") |
|||
.IsRequired() |
|||
.HasMaxLength(64) |
|||
.HasColumnType("character varying(64)"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.ToTable("AbpAIConversations", (string)null); |
|||
}); |
|||
|
|||
modelBuilder.Entity("LINGYUN.Abp.AIManagement.Chats.TextChatMessageRecord", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<string>("ConcurrencyStamp") |
|||
.IsConcurrencyToken() |
|||
.IsRequired() |
|||
.HasMaxLength(40) |
|||
.HasColumnType("character varying(40)") |
|||
.HasColumnName("ConcurrencyStamp"); |
|||
|
|||
b.Property<string>("Content") |
|||
.IsRequired() |
|||
.HasMaxLength(1024) |
|||
.HasColumnType("character varying(1024)"); |
|||
|
|||
b.Property<Guid?>("ConversationId") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<DateTime>("CreatedAt") |
|||
.HasColumnType("timestamp with time zone"); |
|||
|
|||
b.Property<DateTime>("CreationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("CreationTime"); |
|||
|
|||
b.Property<Guid?>("CreatorId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("CreatorId"); |
|||
|
|||
b.Property<string>("ExtraProperties") |
|||
.IsRequired() |
|||
.HasColumnType("text") |
|||
.HasColumnName("ExtraProperties"); |
|||
|
|||
b.Property<DateTime?>("LastModificationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("LastModificationTime"); |
|||
|
|||
b.Property<Guid?>("LastModifierId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("LastModifierId"); |
|||
|
|||
b.Property<DateTime?>("ReplyAt") |
|||
.HasColumnType("timestamp with time zone"); |
|||
|
|||
b.Property<string>("ReplyMessage") |
|||
.HasColumnType("text"); |
|||
|
|||
b.Property<string>("Role") |
|||
.IsRequired() |
|||
.HasMaxLength(20) |
|||
.HasColumnType("character varying(20)"); |
|||
|
|||
b.Property<Guid?>("TenantId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("TenantId"); |
|||
|
|||
b.Property<Guid?>("UserId") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<string>("Workspace") |
|||
.IsRequired() |
|||
.HasMaxLength(64) |
|||
.HasColumnType("character varying(64)"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.HasIndex("TenantId", "ConversationId"); |
|||
|
|||
b.ToTable("AbpAITextChatMessages", (string)null); |
|||
}); |
|||
|
|||
modelBuilder.Entity("LINGYUN.Abp.AIManagement.Tokens.TokenUsageRecord", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<long?>("CachedInputTokenCount") |
|||
.HasColumnType("bigint"); |
|||
|
|||
b.Property<Guid?>("ConversationId") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<DateTime>("CreationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("CreationTime"); |
|||
|
|||
b.Property<Guid?>("CreatorId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("CreatorId"); |
|||
|
|||
b.Property<long?>("InputTokenCount") |
|||
.HasColumnType("bigint"); |
|||
|
|||
b.Property<DateTime?>("LastModificationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("LastModificationTime"); |
|||
|
|||
b.Property<Guid?>("LastModifierId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("LastModifierId"); |
|||
|
|||
b.Property<Guid?>("MessageId") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<long?>("OutputTokenCount") |
|||
.HasColumnType("bigint"); |
|||
|
|||
b.Property<long?>("ReasoningTokenCount") |
|||
.HasColumnType("bigint"); |
|||
|
|||
b.Property<Guid?>("TenantId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("TenantId"); |
|||
|
|||
b.Property<long?>("TotalTokenCount") |
|||
.HasColumnType("bigint"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.HasIndex("TenantId", "ConversationId"); |
|||
|
|||
b.ToTable("AbpAITokenUsages", (string)null); |
|||
}); |
|||
|
|||
modelBuilder.Entity("LINGYUN.Abp.AIManagement.Tools.AIToolDefinitionRecord", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<string>("ConcurrencyStamp") |
|||
.IsConcurrencyToken() |
|||
.IsRequired() |
|||
.HasMaxLength(40) |
|||
.HasColumnType("character varying(40)") |
|||
.HasColumnName("ConcurrencyStamp"); |
|||
|
|||
b.Property<DateTime>("CreationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("CreationTime"); |
|||
|
|||
b.Property<Guid?>("CreatorId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("CreatorId"); |
|||
|
|||
b.Property<string>("Description") |
|||
.HasMaxLength(128) |
|||
.HasColumnType("character varying(128)"); |
|||
|
|||
b.Property<string>("ExtraProperties") |
|||
.IsRequired() |
|||
.HasColumnType("text") |
|||
.HasColumnName("ExtraProperties"); |
|||
|
|||
b.Property<bool>("IsEnabled") |
|||
.HasColumnType("boolean"); |
|||
|
|||
b.Property<bool>("IsSystem") |
|||
.HasColumnType("boolean"); |
|||
|
|||
b.Property<DateTime?>("LastModificationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("LastModificationTime"); |
|||
|
|||
b.Property<Guid?>("LastModifierId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("LastModifierId"); |
|||
|
|||
b.Property<string>("Name") |
|||
.IsRequired() |
|||
.HasMaxLength(64) |
|||
.HasColumnType("character varying(64)"); |
|||
|
|||
b.Property<string>("Provider") |
|||
.IsRequired() |
|||
.HasMaxLength(20) |
|||
.HasColumnType("character varying(20)"); |
|||
|
|||
b.Property<string>("StateCheckers") |
|||
.HasMaxLength(256) |
|||
.HasColumnType("character varying(256)"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.HasIndex("Name") |
|||
.IsUnique(); |
|||
|
|||
b.ToTable("AbpAIAIToolDefinitionRecords", (string)null); |
|||
}); |
|||
|
|||
modelBuilder.Entity("LINGYUN.Abp.AIManagement.Workspaces.WorkspaceDefinitionRecord", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<string>("ApiBaseUrl") |
|||
.HasMaxLength(128) |
|||
.HasColumnType("character varying(128)"); |
|||
|
|||
b.Property<string>("ApiKey") |
|||
.HasMaxLength(64) |
|||
.HasColumnType("character varying(64)"); |
|||
|
|||
b.Property<string>("ConcurrencyStamp") |
|||
.IsConcurrencyToken() |
|||
.IsRequired() |
|||
.HasMaxLength(40) |
|||
.HasColumnType("character varying(40)") |
|||
.HasColumnName("ConcurrencyStamp"); |
|||
|
|||
b.Property<DateTime>("CreationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("CreationTime"); |
|||
|
|||
b.Property<Guid?>("CreatorId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("CreatorId"); |
|||
|
|||
b.Property<string>("Description") |
|||
.HasMaxLength(128) |
|||
.HasColumnType("character varying(128)"); |
|||
|
|||
b.Property<string>("DisplayName") |
|||
.IsRequired() |
|||
.HasMaxLength(128) |
|||
.HasColumnType("character varying(128)"); |
|||
|
|||
b.Property<string>("ExtraProperties") |
|||
.IsRequired() |
|||
.HasColumnType("text") |
|||
.HasColumnName("ExtraProperties"); |
|||
|
|||
b.Property<float?>("FrequencyPenalty") |
|||
.HasColumnType("real"); |
|||
|
|||
b.Property<string>("Instructions") |
|||
.HasMaxLength(512) |
|||
.HasColumnType("character varying(512)"); |
|||
|
|||
b.Property<bool>("IsEnabled") |
|||
.HasColumnType("boolean"); |
|||
|
|||
b.Property<bool>("IsSystem") |
|||
.HasColumnType("boolean"); |
|||
|
|||
b.Property<DateTime?>("LastModificationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("LastModificationTime"); |
|||
|
|||
b.Property<Guid?>("LastModifierId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("LastModifierId"); |
|||
|
|||
b.Property<int?>("MaxOutputTokens") |
|||
.HasColumnType("integer"); |
|||
|
|||
b.Property<string>("ModelName") |
|||
.IsRequired() |
|||
.HasMaxLength(64) |
|||
.HasColumnType("character varying(64)"); |
|||
|
|||
b.Property<string>("Name") |
|||
.IsRequired() |
|||
.HasMaxLength(64) |
|||
.HasColumnType("character varying(64)"); |
|||
|
|||
b.Property<float?>("PresencePenalty") |
|||
.HasColumnType("real"); |
|||
|
|||
b.Property<string>("Provider") |
|||
.IsRequired() |
|||
.HasMaxLength(20) |
|||
.HasColumnType("character varying(20)"); |
|||
|
|||
b.Property<string>("StateCheckers") |
|||
.HasMaxLength(256) |
|||
.HasColumnType("character varying(256)"); |
|||
|
|||
b.Property<string>("SystemPrompt") |
|||
.HasMaxLength(512) |
|||
.HasColumnType("character varying(512)"); |
|||
|
|||
b.Property<float?>("Temperature") |
|||
.HasColumnType("real"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.HasIndex("Name") |
|||
.IsUnique(); |
|||
|
|||
b.ToTable("AbpAIWorkspaceDefinitions", (string)null); |
|||
}); |
|||
#pragma warning restore 612, 618
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace LINGYUN.Abp.MicroService.AIService.Migrations |
|||
{ |
|||
/// <inheritdoc />
|
|||
public partial class AddAIToolDefinitionRecord : Migration |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.CreateTable( |
|||
name: "AbpAIAIToolDefinitionRecords", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uuid", nullable: false), |
|||
Name = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false), |
|||
Provider = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false), |
|||
Description = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true), |
|||
IsEnabled = table.Column<bool>(type: "boolean", nullable: false), |
|||
IsSystem = table.Column<bool>(type: "boolean", nullable: false), |
|||
StateCheckers = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true), |
|||
ExtraProperties = table.Column<string>(type: "text", nullable: false), |
|||
ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false), |
|||
CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false), |
|||
CreatorId = table.Column<Guid>(type: "uuid", nullable: true), |
|||
LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true), |
|||
LastModifierId = table.Column<Guid>(type: "uuid", nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_AbpAIAIToolDefinitionRecords", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_AbpAIAIToolDefinitionRecords_Name", |
|||
table: "AbpAIAIToolDefinitionRecords", |
|||
column: "Name", |
|||
unique: true); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "AbpAIAIToolDefinitionRecords"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,380 @@ |
|||
// <auto-generated />
|
|||
using System; |
|||
using LINGYUN.Abp.MicroService.AIService; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Infrastructure; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
|||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace LINGYUN.Abp.MicroService.AIService.Migrations |
|||
{ |
|||
[DbContext(typeof(AIServiceMigrationsDbContext))] |
|||
[Migration("20260327065840_Add-Tools-To-Workspace-Record")] |
|||
partial class AddToolsToWorkspaceRecord |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void BuildTargetModel(ModelBuilder modelBuilder) |
|||
{ |
|||
#pragma warning disable 612, 618
|
|||
modelBuilder |
|||
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.PostgreSql) |
|||
.HasAnnotation("ProductVersion", "10.0.0") |
|||
.HasAnnotation("Relational:MaxIdentifierLength", 63); |
|||
|
|||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); |
|||
|
|||
modelBuilder.Entity("LINGYUN.Abp.AIManagement.Chats.ConversationRecord", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<DateTime>("CreatedAt") |
|||
.HasColumnType("timestamp with time zone"); |
|||
|
|||
b.Property<DateTime>("CreationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("CreationTime"); |
|||
|
|||
b.Property<Guid?>("CreatorId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("CreatorId"); |
|||
|
|||
b.Property<DateTime>("ExpiredAt") |
|||
.HasColumnType("timestamp with time zone"); |
|||
|
|||
b.Property<DateTime?>("LastModificationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("LastModificationTime"); |
|||
|
|||
b.Property<Guid?>("LastModifierId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("LastModifierId"); |
|||
|
|||
b.Property<string>("Name") |
|||
.IsRequired() |
|||
.HasMaxLength(50) |
|||
.HasColumnType("character varying(50)"); |
|||
|
|||
b.Property<Guid?>("TenantId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("TenantId"); |
|||
|
|||
b.Property<DateTime?>("UpdateAt") |
|||
.HasColumnType("timestamp with time zone"); |
|||
|
|||
b.Property<string>("Workspace") |
|||
.IsRequired() |
|||
.HasMaxLength(64) |
|||
.HasColumnType("character varying(64)"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.ToTable("AbpAIConversations", (string)null); |
|||
}); |
|||
|
|||
modelBuilder.Entity("LINGYUN.Abp.AIManagement.Chats.TextChatMessageRecord", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<string>("ConcurrencyStamp") |
|||
.IsConcurrencyToken() |
|||
.IsRequired() |
|||
.HasMaxLength(40) |
|||
.HasColumnType("character varying(40)") |
|||
.HasColumnName("ConcurrencyStamp"); |
|||
|
|||
b.Property<string>("Content") |
|||
.IsRequired() |
|||
.HasMaxLength(1024) |
|||
.HasColumnType("character varying(1024)"); |
|||
|
|||
b.Property<Guid?>("ConversationId") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<DateTime>("CreatedAt") |
|||
.HasColumnType("timestamp with time zone"); |
|||
|
|||
b.Property<DateTime>("CreationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("CreationTime"); |
|||
|
|||
b.Property<Guid?>("CreatorId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("CreatorId"); |
|||
|
|||
b.Property<string>("ExtraProperties") |
|||
.IsRequired() |
|||
.HasColumnType("text") |
|||
.HasColumnName("ExtraProperties"); |
|||
|
|||
b.Property<DateTime?>("LastModificationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("LastModificationTime"); |
|||
|
|||
b.Property<Guid?>("LastModifierId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("LastModifierId"); |
|||
|
|||
b.Property<DateTime?>("ReplyAt") |
|||
.HasColumnType("timestamp with time zone"); |
|||
|
|||
b.Property<string>("ReplyMessage") |
|||
.HasColumnType("text"); |
|||
|
|||
b.Property<string>("Role") |
|||
.IsRequired() |
|||
.HasMaxLength(20) |
|||
.HasColumnType("character varying(20)"); |
|||
|
|||
b.Property<Guid?>("TenantId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("TenantId"); |
|||
|
|||
b.Property<Guid?>("UserId") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<string>("Workspace") |
|||
.IsRequired() |
|||
.HasMaxLength(64) |
|||
.HasColumnType("character varying(64)"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.HasIndex("TenantId", "ConversationId"); |
|||
|
|||
b.ToTable("AbpAITextChatMessages", (string)null); |
|||
}); |
|||
|
|||
modelBuilder.Entity("LINGYUN.Abp.AIManagement.Tokens.TokenUsageRecord", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<long?>("CachedInputTokenCount") |
|||
.HasColumnType("bigint"); |
|||
|
|||
b.Property<Guid?>("ConversationId") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<DateTime>("CreationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("CreationTime"); |
|||
|
|||
b.Property<Guid?>("CreatorId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("CreatorId"); |
|||
|
|||
b.Property<long?>("InputTokenCount") |
|||
.HasColumnType("bigint"); |
|||
|
|||
b.Property<DateTime?>("LastModificationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("LastModificationTime"); |
|||
|
|||
b.Property<Guid?>("LastModifierId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("LastModifierId"); |
|||
|
|||
b.Property<Guid?>("MessageId") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<long?>("OutputTokenCount") |
|||
.HasColumnType("bigint"); |
|||
|
|||
b.Property<long?>("ReasoningTokenCount") |
|||
.HasColumnType("bigint"); |
|||
|
|||
b.Property<Guid?>("TenantId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("TenantId"); |
|||
|
|||
b.Property<long?>("TotalTokenCount") |
|||
.HasColumnType("bigint"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.HasIndex("TenantId", "ConversationId"); |
|||
|
|||
b.ToTable("AbpAITokenUsages", (string)null); |
|||
}); |
|||
|
|||
modelBuilder.Entity("LINGYUN.Abp.AIManagement.Tools.AIToolDefinitionRecord", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<string>("ConcurrencyStamp") |
|||
.IsConcurrencyToken() |
|||
.IsRequired() |
|||
.HasMaxLength(40) |
|||
.HasColumnType("character varying(40)") |
|||
.HasColumnName("ConcurrencyStamp"); |
|||
|
|||
b.Property<DateTime>("CreationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("CreationTime"); |
|||
|
|||
b.Property<Guid?>("CreatorId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("CreatorId"); |
|||
|
|||
b.Property<string>("Description") |
|||
.HasMaxLength(128) |
|||
.HasColumnType("character varying(128)"); |
|||
|
|||
b.Property<string>("ExtraProperties") |
|||
.IsRequired() |
|||
.HasColumnType("text") |
|||
.HasColumnName("ExtraProperties"); |
|||
|
|||
b.Property<bool>("IsEnabled") |
|||
.HasColumnType("boolean"); |
|||
|
|||
b.Property<bool>("IsSystem") |
|||
.HasColumnType("boolean"); |
|||
|
|||
b.Property<DateTime?>("LastModificationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("LastModificationTime"); |
|||
|
|||
b.Property<Guid?>("LastModifierId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("LastModifierId"); |
|||
|
|||
b.Property<string>("Name") |
|||
.IsRequired() |
|||
.HasMaxLength(64) |
|||
.HasColumnType("character varying(64)"); |
|||
|
|||
b.Property<string>("Provider") |
|||
.IsRequired() |
|||
.HasMaxLength(20) |
|||
.HasColumnType("character varying(20)"); |
|||
|
|||
b.Property<string>("StateCheckers") |
|||
.HasMaxLength(256) |
|||
.HasColumnType("character varying(256)"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.HasIndex("Name") |
|||
.IsUnique(); |
|||
|
|||
b.ToTable("AbpAIAIToolDefinitionRecords", (string)null); |
|||
}); |
|||
|
|||
modelBuilder.Entity("LINGYUN.Abp.AIManagement.Workspaces.WorkspaceDefinitionRecord", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<string>("ApiBaseUrl") |
|||
.HasMaxLength(128) |
|||
.HasColumnType("character varying(128)"); |
|||
|
|||
b.Property<string>("ApiKey") |
|||
.HasMaxLength(64) |
|||
.HasColumnType("character varying(64)"); |
|||
|
|||
b.Property<string>("ConcurrencyStamp") |
|||
.IsConcurrencyToken() |
|||
.IsRequired() |
|||
.HasMaxLength(40) |
|||
.HasColumnType("character varying(40)") |
|||
.HasColumnName("ConcurrencyStamp"); |
|||
|
|||
b.Property<DateTime>("CreationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("CreationTime"); |
|||
|
|||
b.Property<Guid?>("CreatorId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("CreatorId"); |
|||
|
|||
b.Property<string>("Description") |
|||
.HasMaxLength(128) |
|||
.HasColumnType("character varying(128)"); |
|||
|
|||
b.Property<string>("DisplayName") |
|||
.IsRequired() |
|||
.HasMaxLength(128) |
|||
.HasColumnType("character varying(128)"); |
|||
|
|||
b.Property<string>("ExtraProperties") |
|||
.IsRequired() |
|||
.HasColumnType("text") |
|||
.HasColumnName("ExtraProperties"); |
|||
|
|||
b.Property<float?>("FrequencyPenalty") |
|||
.HasColumnType("real"); |
|||
|
|||
b.Property<string>("Instructions") |
|||
.HasMaxLength(512) |
|||
.HasColumnType("character varying(512)"); |
|||
|
|||
b.Property<bool>("IsEnabled") |
|||
.HasColumnType("boolean"); |
|||
|
|||
b.Property<bool>("IsSystem") |
|||
.HasColumnType("boolean"); |
|||
|
|||
b.Property<DateTime?>("LastModificationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("LastModificationTime"); |
|||
|
|||
b.Property<Guid?>("LastModifierId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("LastModifierId"); |
|||
|
|||
b.Property<int?>("MaxOutputTokens") |
|||
.HasColumnType("integer"); |
|||
|
|||
b.Property<string>("ModelName") |
|||
.IsRequired() |
|||
.HasMaxLength(64) |
|||
.HasColumnType("character varying(64)"); |
|||
|
|||
b.Property<string>("Name") |
|||
.IsRequired() |
|||
.HasMaxLength(64) |
|||
.HasColumnType("character varying(64)"); |
|||
|
|||
b.Property<float?>("PresencePenalty") |
|||
.HasColumnType("real"); |
|||
|
|||
b.Property<string>("Provider") |
|||
.IsRequired() |
|||
.HasMaxLength(20) |
|||
.HasColumnType("character varying(20)"); |
|||
|
|||
b.Property<string>("StateCheckers") |
|||
.HasMaxLength(256) |
|||
.HasColumnType("character varying(256)"); |
|||
|
|||
b.Property<string>("SystemPrompt") |
|||
.HasMaxLength(512) |
|||
.HasColumnType("character varying(512)"); |
|||
|
|||
b.Property<float?>("Temperature") |
|||
.HasColumnType("real"); |
|||
|
|||
b.Property<string>("Tools") |
|||
.HasMaxLength(128) |
|||
.HasColumnType("character varying(128)"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.HasIndex("Name") |
|||
.IsUnique(); |
|||
|
|||
b.ToTable("AbpAIWorkspaceDefinitions", (string)null); |
|||
}); |
|||
#pragma warning restore 612, 618
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace LINGYUN.Abp.MicroService.AIService.Migrations |
|||
{ |
|||
/// <inheritdoc />
|
|||
public partial class AddToolsToWorkspaceRecord : Migration |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AddColumn<string>( |
|||
name: "Tools", |
|||
table: "AbpAIWorkspaceDefinitions", |
|||
type: "character varying(128)", |
|||
maxLength: 128, |
|||
nullable: true); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropColumn( |
|||
name: "Tools", |
|||
table: "AbpAIWorkspaceDefinitions"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,383 @@ |
|||
// <auto-generated />
|
|||
using System; |
|||
using LINGYUN.Abp.MicroService.AIService; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Infrastructure; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
|||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace LINGYUN.Abp.MicroService.AIService.Migrations |
|||
{ |
|||
[DbContext(typeof(AIServiceMigrationsDbContext))] |
|||
[Migration("20260327071051_Add-IsGlobal-To-AITool-Record")] |
|||
partial class AddIsGlobalToAIToolRecord |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void BuildTargetModel(ModelBuilder modelBuilder) |
|||
{ |
|||
#pragma warning disable 612, 618
|
|||
modelBuilder |
|||
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.PostgreSql) |
|||
.HasAnnotation("ProductVersion", "10.0.0") |
|||
.HasAnnotation("Relational:MaxIdentifierLength", 63); |
|||
|
|||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); |
|||
|
|||
modelBuilder.Entity("LINGYUN.Abp.AIManagement.Chats.ConversationRecord", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<DateTime>("CreatedAt") |
|||
.HasColumnType("timestamp with time zone"); |
|||
|
|||
b.Property<DateTime>("CreationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("CreationTime"); |
|||
|
|||
b.Property<Guid?>("CreatorId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("CreatorId"); |
|||
|
|||
b.Property<DateTime>("ExpiredAt") |
|||
.HasColumnType("timestamp with time zone"); |
|||
|
|||
b.Property<DateTime?>("LastModificationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("LastModificationTime"); |
|||
|
|||
b.Property<Guid?>("LastModifierId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("LastModifierId"); |
|||
|
|||
b.Property<string>("Name") |
|||
.IsRequired() |
|||
.HasMaxLength(50) |
|||
.HasColumnType("character varying(50)"); |
|||
|
|||
b.Property<Guid?>("TenantId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("TenantId"); |
|||
|
|||
b.Property<DateTime?>("UpdateAt") |
|||
.HasColumnType("timestamp with time zone"); |
|||
|
|||
b.Property<string>("Workspace") |
|||
.IsRequired() |
|||
.HasMaxLength(64) |
|||
.HasColumnType("character varying(64)"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.ToTable("AbpAIConversations", (string)null); |
|||
}); |
|||
|
|||
modelBuilder.Entity("LINGYUN.Abp.AIManagement.Chats.TextChatMessageRecord", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<string>("ConcurrencyStamp") |
|||
.IsConcurrencyToken() |
|||
.IsRequired() |
|||
.HasMaxLength(40) |
|||
.HasColumnType("character varying(40)") |
|||
.HasColumnName("ConcurrencyStamp"); |
|||
|
|||
b.Property<string>("Content") |
|||
.IsRequired() |
|||
.HasMaxLength(1024) |
|||
.HasColumnType("character varying(1024)"); |
|||
|
|||
b.Property<Guid?>("ConversationId") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<DateTime>("CreatedAt") |
|||
.HasColumnType("timestamp with time zone"); |
|||
|
|||
b.Property<DateTime>("CreationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("CreationTime"); |
|||
|
|||
b.Property<Guid?>("CreatorId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("CreatorId"); |
|||
|
|||
b.Property<string>("ExtraProperties") |
|||
.IsRequired() |
|||
.HasColumnType("text") |
|||
.HasColumnName("ExtraProperties"); |
|||
|
|||
b.Property<DateTime?>("LastModificationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("LastModificationTime"); |
|||
|
|||
b.Property<Guid?>("LastModifierId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("LastModifierId"); |
|||
|
|||
b.Property<DateTime?>("ReplyAt") |
|||
.HasColumnType("timestamp with time zone"); |
|||
|
|||
b.Property<string>("ReplyMessage") |
|||
.HasColumnType("text"); |
|||
|
|||
b.Property<string>("Role") |
|||
.IsRequired() |
|||
.HasMaxLength(20) |
|||
.HasColumnType("character varying(20)"); |
|||
|
|||
b.Property<Guid?>("TenantId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("TenantId"); |
|||
|
|||
b.Property<Guid?>("UserId") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<string>("Workspace") |
|||
.IsRequired() |
|||
.HasMaxLength(64) |
|||
.HasColumnType("character varying(64)"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.HasIndex("TenantId", "ConversationId"); |
|||
|
|||
b.ToTable("AbpAITextChatMessages", (string)null); |
|||
}); |
|||
|
|||
modelBuilder.Entity("LINGYUN.Abp.AIManagement.Tokens.TokenUsageRecord", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<long?>("CachedInputTokenCount") |
|||
.HasColumnType("bigint"); |
|||
|
|||
b.Property<Guid?>("ConversationId") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<DateTime>("CreationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("CreationTime"); |
|||
|
|||
b.Property<Guid?>("CreatorId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("CreatorId"); |
|||
|
|||
b.Property<long?>("InputTokenCount") |
|||
.HasColumnType("bigint"); |
|||
|
|||
b.Property<DateTime?>("LastModificationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("LastModificationTime"); |
|||
|
|||
b.Property<Guid?>("LastModifierId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("LastModifierId"); |
|||
|
|||
b.Property<Guid?>("MessageId") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<long?>("OutputTokenCount") |
|||
.HasColumnType("bigint"); |
|||
|
|||
b.Property<long?>("ReasoningTokenCount") |
|||
.HasColumnType("bigint"); |
|||
|
|||
b.Property<Guid?>("TenantId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("TenantId"); |
|||
|
|||
b.Property<long?>("TotalTokenCount") |
|||
.HasColumnType("bigint"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.HasIndex("TenantId", "ConversationId"); |
|||
|
|||
b.ToTable("AbpAITokenUsages", (string)null); |
|||
}); |
|||
|
|||
modelBuilder.Entity("LINGYUN.Abp.AIManagement.Tools.AIToolDefinitionRecord", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<string>("ConcurrencyStamp") |
|||
.IsConcurrencyToken() |
|||
.IsRequired() |
|||
.HasMaxLength(40) |
|||
.HasColumnType("character varying(40)") |
|||
.HasColumnName("ConcurrencyStamp"); |
|||
|
|||
b.Property<DateTime>("CreationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("CreationTime"); |
|||
|
|||
b.Property<Guid?>("CreatorId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("CreatorId"); |
|||
|
|||
b.Property<string>("Description") |
|||
.HasMaxLength(128) |
|||
.HasColumnType("character varying(128)"); |
|||
|
|||
b.Property<string>("ExtraProperties") |
|||
.IsRequired() |
|||
.HasColumnType("text") |
|||
.HasColumnName("ExtraProperties"); |
|||
|
|||
b.Property<bool>("IsEnabled") |
|||
.HasColumnType("boolean"); |
|||
|
|||
b.Property<bool>("IsGlobal") |
|||
.HasColumnType("boolean"); |
|||
|
|||
b.Property<bool>("IsSystem") |
|||
.HasColumnType("boolean"); |
|||
|
|||
b.Property<DateTime?>("LastModificationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("LastModificationTime"); |
|||
|
|||
b.Property<Guid?>("LastModifierId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("LastModifierId"); |
|||
|
|||
b.Property<string>("Name") |
|||
.IsRequired() |
|||
.HasMaxLength(64) |
|||
.HasColumnType("character varying(64)"); |
|||
|
|||
b.Property<string>("Provider") |
|||
.IsRequired() |
|||
.HasMaxLength(20) |
|||
.HasColumnType("character varying(20)"); |
|||
|
|||
b.Property<string>("StateCheckers") |
|||
.HasMaxLength(256) |
|||
.HasColumnType("character varying(256)"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.HasIndex("Name") |
|||
.IsUnique(); |
|||
|
|||
b.ToTable("AbpAIAIToolDefinitionRecords", (string)null); |
|||
}); |
|||
|
|||
modelBuilder.Entity("LINGYUN.Abp.AIManagement.Workspaces.WorkspaceDefinitionRecord", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<string>("ApiBaseUrl") |
|||
.HasMaxLength(128) |
|||
.HasColumnType("character varying(128)"); |
|||
|
|||
b.Property<string>("ApiKey") |
|||
.HasMaxLength(64) |
|||
.HasColumnType("character varying(64)"); |
|||
|
|||
b.Property<string>("ConcurrencyStamp") |
|||
.IsConcurrencyToken() |
|||
.IsRequired() |
|||
.HasMaxLength(40) |
|||
.HasColumnType("character varying(40)") |
|||
.HasColumnName("ConcurrencyStamp"); |
|||
|
|||
b.Property<DateTime>("CreationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("CreationTime"); |
|||
|
|||
b.Property<Guid?>("CreatorId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("CreatorId"); |
|||
|
|||
b.Property<string>("Description") |
|||
.HasMaxLength(128) |
|||
.HasColumnType("character varying(128)"); |
|||
|
|||
b.Property<string>("DisplayName") |
|||
.IsRequired() |
|||
.HasMaxLength(128) |
|||
.HasColumnType("character varying(128)"); |
|||
|
|||
b.Property<string>("ExtraProperties") |
|||
.IsRequired() |
|||
.HasColumnType("text") |
|||
.HasColumnName("ExtraProperties"); |
|||
|
|||
b.Property<float?>("FrequencyPenalty") |
|||
.HasColumnType("real"); |
|||
|
|||
b.Property<string>("Instructions") |
|||
.HasMaxLength(512) |
|||
.HasColumnType("character varying(512)"); |
|||
|
|||
b.Property<bool>("IsEnabled") |
|||
.HasColumnType("boolean"); |
|||
|
|||
b.Property<bool>("IsSystem") |
|||
.HasColumnType("boolean"); |
|||
|
|||
b.Property<DateTime?>("LastModificationTime") |
|||
.HasColumnType("timestamp with time zone") |
|||
.HasColumnName("LastModificationTime"); |
|||
|
|||
b.Property<Guid?>("LastModifierId") |
|||
.HasColumnType("uuid") |
|||
.HasColumnName("LastModifierId"); |
|||
|
|||
b.Property<int?>("MaxOutputTokens") |
|||
.HasColumnType("integer"); |
|||
|
|||
b.Property<string>("ModelName") |
|||
.IsRequired() |
|||
.HasMaxLength(64) |
|||
.HasColumnType("character varying(64)"); |
|||
|
|||
b.Property<string>("Name") |
|||
.IsRequired() |
|||
.HasMaxLength(64) |
|||
.HasColumnType("character varying(64)"); |
|||
|
|||
b.Property<float?>("PresencePenalty") |
|||
.HasColumnType("real"); |
|||
|
|||
b.Property<string>("Provider") |
|||
.IsRequired() |
|||
.HasMaxLength(20) |
|||
.HasColumnType("character varying(20)"); |
|||
|
|||
b.Property<string>("StateCheckers") |
|||
.HasMaxLength(256) |
|||
.HasColumnType("character varying(256)"); |
|||
|
|||
b.Property<string>("SystemPrompt") |
|||
.HasMaxLength(512) |
|||
.HasColumnType("character varying(512)"); |
|||
|
|||
b.Property<float?>("Temperature") |
|||
.HasColumnType("real"); |
|||
|
|||
b.Property<string>("Tools") |
|||
.HasMaxLength(128) |
|||
.HasColumnType("character varying(128)"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.HasIndex("Name") |
|||
.IsUnique(); |
|||
|
|||
b.ToTable("AbpAIWorkspaceDefinitions", (string)null); |
|||
}); |
|||
#pragma warning restore 612, 618
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace LINGYUN.Abp.MicroService.AIService.Migrations |
|||
{ |
|||
/// <inheritdoc />
|
|||
public partial class AddIsGlobalToAIToolRecord : Migration |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AddColumn<bool>( |
|||
name: "IsGlobal", |
|||
table: "AbpAIAIToolDefinitionRecords", |
|||
type: "boolean", |
|||
nullable: false, |
|||
defaultValue: false); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropColumn( |
|||
name: "IsGlobal", |
|||
table: "AbpAIAIToolDefinitionRecords"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,6 +1,10 @@ |
|||
{ |
|||
"culture": "en", |
|||
"texts": { |
|||
"Tools:GetApplicationConfiguration": "Get Application Configuration" |
|||
"Tools:GetApplicationConfiguration": "Get Application Configuration", |
|||
"HttpAITool:Endpoint": "Endpoint", |
|||
"HttpAITool:Method": "Method", |
|||
"HttpAITool:Headers": "Headers", |
|||
"HttpAITool:CurrentAccessToken": "Use the current user token" |
|||
} |
|||
} |
|||
@ -1,6 +1,10 @@ |
|||
{ |
|||
"culture": "zh-Hans", |
|||
"texts": { |
|||
"Tools:GetApplicationConfiguration": "获取应用程序配置" |
|||
"Tools:GetApplicationConfiguration": "获取应用程序配置", |
|||
"HttpAITool:Endpoint": "请求地址", |
|||
"HttpAITool:Method": "请求方法", |
|||
"HttpAITool:Headers": "请求头", |
|||
"HttpAITool:CurrentAccessToken": "使用当前用户Token" |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
{ |
|||
"culture": "en", |
|||
"texts": { |
|||
"McpAITool:Endpoint": "Endpoint", |
|||
"McpAITool:Headers": "Headers", |
|||
"McpAITool:TransportMode": "Transport Mode", |
|||
"McpAITool:TransportModeDesc": "The transport mode to use for the connection. The default is: Auto Detect.", |
|||
"McpAITool:ConnectionTimeout": "Connection Timeout", |
|||
"McpAITool:ConnectionTimeoutDesc": "The timeout used to establish the initial connection to the SSE server. The default is 30 seconds.", |
|||
"McpAITool:MaxReconnectionAttempts": "Max Reconnection Attempts", |
|||
"McpAITool:MaxReconnectionAttemptsDesc": "The maximum number of reconnection attempts. The default is 5.", |
|||
"McpAITool:CurrentAccessToken": "Use the current user token" |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
{ |
|||
"culture": "zh-Hans", |
|||
"texts": { |
|||
"McpAITool:Endpoint": "请求地址", |
|||
"McpAITool:Headers": "请求头", |
|||
"McpAITool:TransportMode": "传输方式", |
|||
"McpAITool:TransportModeDesc": "连接所采用的传输方式, 默认: Auto Detect.", |
|||
"McpAITool:ConnectionTimeout": "超时时间", |
|||
"McpAITool:ConnectionTimeoutDesc": "用于建立与 SSE 服务器初始连接的超时时间, 默认: 30秒.", |
|||
"McpAITool:MaxReconnectionAttempts": "最大重连次数", |
|||
"McpAITool:MaxReconnectionAttemptsDesc": "最大重连次数, 默认: 5次.", |
|||
"McpAITool:CurrentAccessToken": "使用当前用户Token" |
|||
} |
|||
} |
|||
@ -0,0 +1,120 @@ |
|||
using System.Collections.Generic; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace LINGYUN.Abp.AI.Tools; |
|||
|
|||
public enum PropertyValueType |
|||
{ |
|||
String = 0, |
|||
Number = 1, |
|||
Boolean = 2, |
|||
Dictionary = 3, |
|||
Select = 4, |
|||
} |
|||
|
|||
public class AIToolPropertyDescriptor |
|||
{ |
|||
public string Name { get; } |
|||
public bool Required { get; } |
|||
public PropertyValueType ValueType { get; } |
|||
public List<NameValue<object>> Options { get; } |
|||
public ILocalizableString DisplayName { get; } |
|||
public ILocalizableString? Description { get; } |
|||
private AIToolPropertyDescriptor( |
|||
string name, |
|||
PropertyValueType valueType, |
|||
ILocalizableString displayName, |
|||
ILocalizableString? description = null, |
|||
bool required = false) |
|||
{ |
|||
Name = name; |
|||
ValueType = valueType; |
|||
DisplayName = displayName; |
|||
Description = description; |
|||
Required = required; |
|||
|
|||
Options = new List<NameValue<object>>(); |
|||
} |
|||
|
|||
public static AIToolPropertyDescriptor CreateStringProperty( |
|||
string name, |
|||
ILocalizableString displayName, |
|||
ILocalizableString? description = null, |
|||
bool required = false) |
|||
{ |
|||
return new AIToolPropertyDescriptor( |
|||
name, |
|||
PropertyValueType.String, |
|||
displayName, |
|||
description, |
|||
required); |
|||
} |
|||
|
|||
public static AIToolPropertyDescriptor CreateNumberProperty( |
|||
string name, |
|||
ILocalizableString displayName, |
|||
ILocalizableString? description = null, |
|||
bool required = false) |
|||
{ |
|||
return new AIToolPropertyDescriptor( |
|||
name, |
|||
PropertyValueType.Number, |
|||
displayName, |
|||
description, |
|||
required); |
|||
} |
|||
|
|||
public static AIToolPropertyDescriptor CreateBoolProperty( |
|||
string name, |
|||
ILocalizableString displayName, |
|||
ILocalizableString? description = null, |
|||
bool required = false) |
|||
{ |
|||
return new AIToolPropertyDescriptor( |
|||
name, |
|||
PropertyValueType.Boolean, |
|||
displayName, |
|||
description, |
|||
required); |
|||
} |
|||
|
|||
public static AIToolPropertyDescriptor CreateDictionaryProperty( |
|||
string name, |
|||
ILocalizableString displayName, |
|||
ILocalizableString? description = null) |
|||
{ |
|||
return new AIToolPropertyDescriptor( |
|||
name, |
|||
PropertyValueType.Dictionary, |
|||
displayName, |
|||
description); |
|||
} |
|||
|
|||
public static AIToolPropertyDescriptor CreateSelectProperty( |
|||
string name, |
|||
ILocalizableString displayName, |
|||
List<NameValue<object>> options, |
|||
ILocalizableString? description = null, |
|||
bool required = false) |
|||
{ |
|||
var propertyDescriptor = new AIToolPropertyDescriptor( |
|||
name, |
|||
PropertyValueType.Select, |
|||
displayName, |
|||
description, |
|||
required); |
|||
|
|||
foreach (var option in options) |
|||
{ |
|||
propertyDescriptor.WithOption(option.Name, option.Value); |
|||
} |
|||
|
|||
return propertyDescriptor; |
|||
} |
|||
|
|||
public void WithOption(string name, object value) |
|||
{ |
|||
Options.Add(new NameValue<object>(name, value)); |
|||
} |
|||
} |
|||
@ -1,13 +1,16 @@ |
|||
using Volo.Abp.Collections; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.Collections; |
|||
|
|||
namespace LINGYUN.Abp.AI.Tools; |
|||
public class AbpAIToolsOptions |
|||
{ |
|||
public ITypeList<IAIToolDefinitionProvider> DefinitionProviders { get; } |
|||
public ITypeList<IAIToolProvider> AIToolProviders { get; } |
|||
public HashSet<string> DeletedAITools { get; } |
|||
public AbpAIToolsOptions() |
|||
{ |
|||
DefinitionProviders = new TypeList<IAIToolDefinitionProvider>(); |
|||
AIToolProviders = new TypeList<IAIToolProvider>(); |
|||
DeletedAITools = new HashSet<string>(); |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,10 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools.Dtos; |
|||
public class AIToolDefinitionRecordCreateDto : AIToolDefinitionRecordCreateOrUpdateDto |
|||
{ |
|||
[Required] |
|||
[DynamicStringLength(typeof(AIToolDefinitionRecordConsts), nameof(AIToolDefinitionRecordConsts.MaxNameLength))] |
|||
public string Name { get; set; } |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.ObjectExtending; |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools.Dtos; |
|||
public abstract class AIToolDefinitionRecordCreateOrUpdateDto : ExtensibleObject |
|||
{ |
|||
[Required] |
|||
[DynamicStringLength(typeof(AIToolDefinitionRecordConsts), nameof(AIToolDefinitionRecordConsts.MaxProviderLength))] |
|||
public string Provider { get; set; } |
|||
|
|||
[DynamicStringLength(typeof(AIToolDefinitionRecordConsts), nameof(AIToolDefinitionRecordConsts.MaxDescriptionLength))] |
|||
public string? Description { get; set; } |
|||
|
|||
public bool IsEnabled { get; set; } |
|||
|
|||
public bool IsGlobal { get; set; } |
|||
|
|||
[DynamicStringLength(typeof(AIToolDefinitionRecordConsts), nameof(AIToolDefinitionRecordConsts.MaxStateCheckersLength))] |
|||
public string? StateCheckers { get; set; } |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools.Dtos; |
|||
|
|||
[Serializable] |
|||
public class AIToolDefinitionRecordDto : ExtensibleAuditedEntityDto<Guid>, IHasConcurrencyStamp |
|||
{ |
|||
public string Name { get; set; } |
|||
|
|||
public string Provider { get; set; } |
|||
|
|||
public string? Description { get; set; } |
|||
|
|||
public bool IsEnabled { get; set; } |
|||
|
|||
public bool IsSystem { get; set; } |
|||
|
|||
public bool IsGlobal { get; set; } |
|||
|
|||
public string? StateCheckers { get; set; } |
|||
|
|||
public string ConcurrencyStamp { get; set; } |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools.Dtos; |
|||
|
|||
[Serializable] |
|||
public class AIToolDefinitionRecordGetPagedListInput : PagedAndSortedResultRequestDto |
|||
{ |
|||
public string? Filter { get; set; } |
|||
|
|||
public bool? IsEnabled { get; set; } |
|||
|
|||
public string? Provider { get; set; } |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools.Dtos; |
|||
public class AIToolDefinitionRecordUpdateDto : AIToolDefinitionRecordCreateOrUpdateDto, IHasConcurrencyStamp |
|||
{ |
|||
[Required] |
|||
[StringLength(40)] |
|||
public string ConcurrencyStamp { get; set; } |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System.Collections.Generic; |
|||
using Volo.Abp; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools.Dtos; |
|||
public class AIToolPropertyDescriptorDto |
|||
{ |
|||
public string Name { get; set; } |
|||
public bool Required { get; set; } |
|||
public string ValueType { get; set; } |
|||
public List<NameValue<object>> Options { get; set; } |
|||
public string DisplayName { get; set; } |
|||
public string? Description { get; set; } |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
namespace LINGYUN.Abp.AIManagement.Tools.Dtos; |
|||
public class AIToolProviderDto |
|||
{ |
|||
public string Name { get; } |
|||
public AIToolPropertyDescriptorDto[] Properties { get; } |
|||
public AIToolProviderDto(string name, AIToolPropertyDescriptorDto[] properties) |
|||
{ |
|||
Name = name; |
|||
Properties = properties; |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using LINGYUN.Abp.AIManagement.Tools.Dtos; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools; |
|||
public interface IAIToolDefinitionAppService : |
|||
ICrudAppService< |
|||
AIToolDefinitionRecordDto, |
|||
Guid, |
|||
AIToolDefinitionRecordGetPagedListInput, |
|||
AIToolDefinitionRecordCreateDto, |
|||
AIToolDefinitionRecordUpdateDto> |
|||
{ |
|||
Task<ListResultDto<AIToolProviderDto>> GetAvailableProvidersAsync(); |
|||
} |
|||
2
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/Dtos/WorkspaceDefinitionRecordGetListInput.cs → aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/Dtos/WorkspaceDefinitionRecordGetPagedListInput.cs
2
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/Dtos/WorkspaceDefinitionRecordGetListInput.cs → aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/Dtos/WorkspaceDefinitionRecordGetPagedListInput.cs
@ -0,0 +1,168 @@ |
|||
using LINGYUN.Abp.AI.Tools; |
|||
using LINGYUN.Abp.AIManagement.Localization; |
|||
using LINGYUN.Abp.AIManagement.Permissions; |
|||
using LINGYUN.Abp.AIManagement.Tools.Dtos; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Options; |
|||
using System; |
|||
using System.Collections.Immutable; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools; |
|||
public class AIToolDefinitionAppService : |
|||
CrudAppService< |
|||
AIToolDefinitionRecord, |
|||
AIToolDefinitionRecordDto, |
|||
Guid, |
|||
AIToolDefinitionRecordGetPagedListInput, |
|||
AIToolDefinitionRecordCreateDto, |
|||
AIToolDefinitionRecordUpdateDto>, |
|||
IAIToolDefinitionAppService |
|||
{ |
|||
protected AbpAIToolsOptions AIToolsOptions { get; } |
|||
protected IAIToolDefinitionRecordRepository AIToolDefinitionRecordRepository { get; } |
|||
|
|||
public AIToolDefinitionAppService( |
|||
IOptions<AbpAIToolsOptions> aiToolsOptions, |
|||
IAIToolDefinitionRecordRepository repository) |
|||
: base(repository) |
|||
{ |
|||
AIToolsOptions = aiToolsOptions.Value; |
|||
AIToolDefinitionRecordRepository = repository; |
|||
|
|||
LocalizationResource = typeof(AIManagementResource); |
|||
ObjectMapperContext = typeof(AbpAIManagementApplicationModule); |
|||
|
|||
CreatePolicyName = AIManagementPermissionNames.AIToolDefinition.Create; |
|||
UpdatePolicyName = AIManagementPermissionNames.AIToolDefinition.Update; |
|||
DeletePolicyName = AIManagementPermissionNames.AIToolDefinition.Delete; |
|||
GetListPolicyName = AIManagementPermissionNames.AIToolDefinition.Default; |
|||
GetPolicyName = AIManagementPermissionNames.AIToolDefinition.Default; |
|||
} |
|||
|
|||
public virtual Task<ListResultDto<AIToolProviderDto>> GetAvailableProvidersAsync() |
|||
{ |
|||
var providers = AIToolsOptions.AIToolProviders |
|||
.Select(LazyServiceProvider.GetRequiredService) |
|||
.OfType<IAIToolProvider>() |
|||
.Select(provider => |
|||
{ |
|||
var properties = provider.GetPropertites(); |
|||
|
|||
return new AIToolProviderDto( |
|||
provider.Name, |
|||
properties.Select(prop => |
|||
{ |
|||
var property = new AIToolPropertyDescriptorDto |
|||
{ |
|||
Name = prop.Name, |
|||
Options = prop.Options, |
|||
Required = prop.Required, |
|||
ValueType = prop.ValueType.ToString(), |
|||
DisplayName = prop.DisplayName.Localize(StringLocalizerFactory), |
|||
}; |
|||
if (prop.Description != null) |
|||
{ |
|||
property.Description = prop.Description.Localize(StringLocalizerFactory); |
|||
} |
|||
|
|||
return property; |
|||
}).ToArray()); |
|||
}); |
|||
|
|||
return Task.FromResult(new ListResultDto<AIToolProviderDto>(providers.ToImmutableArray())); |
|||
} |
|||
|
|||
protected async override Task DeleteByIdAsync(Guid id) |
|||
{ |
|||
var aiTool = await Repository.GetAsync(id); |
|||
|
|||
if (aiTool.IsSystem) |
|||
{ |
|||
throw new BusinessException( |
|||
AIManagementErrorCodes.AITool.SystemAIToolNotAllowedToBeDeleted, |
|||
$"System AITool {aiTool.Name} is not allowed to be deleted!") |
|||
.WithData("AITool", aiTool.Name); |
|||
} |
|||
|
|||
await Repository.DeleteAsync(aiTool); |
|||
} |
|||
|
|||
protected async override Task<IQueryable<AIToolDefinitionRecord>> CreateFilteredQueryAsync(AIToolDefinitionRecordGetPagedListInput input) |
|||
{ |
|||
var queryable = await base.CreateFilteredQueryAsync(input); |
|||
|
|||
return queryable |
|||
.WhereIf(input.IsEnabled.HasValue, x => x.IsEnabled == input.IsEnabled) |
|||
.WhereIf(!input.Provider.IsNullOrWhiteSpace(), x => x.Provider == input.Provider) |
|||
.WhereIf(!input.Filter.IsNullOrWhiteSpace(), x => x.Provider.Contains(input.Filter!) || |
|||
x.Name.Contains(input.Filter!) || x.Description!.Contains(input.Filter!)); |
|||
} |
|||
|
|||
protected async override Task<AIToolDefinitionRecord> MapToEntityAsync(AIToolDefinitionRecordCreateDto createInput) |
|||
{ |
|||
if (await AIToolDefinitionRecordRepository.FindByNameAsync(createInput.Name) != null) |
|||
{ |
|||
throw new AIToolAlreadyExistsException(createInput.Name); |
|||
} |
|||
|
|||
var entity = new AIToolDefinitionRecord( |
|||
GuidGenerator.Create(), |
|||
createInput.Name, |
|||
createInput.Provider, |
|||
createInput.Description, |
|||
createInput.StateCheckers) |
|||
{ |
|||
IsEnabled = createInput.IsEnabled, |
|||
IsGlobal = createInput.IsGlobal, |
|||
}; |
|||
|
|||
if (!entity.HasSameExtraProperties(createInput)) |
|||
{ |
|||
entity.ExtraProperties.Clear(); |
|||
|
|||
foreach (var property in createInput.ExtraProperties) |
|||
{ |
|||
entity.ExtraProperties.Add(property.Key, property.Value); |
|||
} |
|||
} |
|||
|
|||
return entity; |
|||
} |
|||
|
|||
protected override void MapToEntity(AIToolDefinitionRecordUpdateDto updateInput, AIToolDefinitionRecord entity) |
|||
{ |
|||
if (entity.Description != updateInput.Description) |
|||
{ |
|||
entity.Description = updateInput.Description; |
|||
} |
|||
|
|||
if (entity.IsEnabled != updateInput.IsEnabled) |
|||
{ |
|||
entity.IsEnabled = updateInput.IsEnabled; |
|||
} |
|||
|
|||
if (entity.IsGlobal != updateInput.IsGlobal) |
|||
{ |
|||
entity.IsGlobal = updateInput.IsGlobal; |
|||
} |
|||
|
|||
if (!entity.HasSameExtraProperties(updateInput)) |
|||
{ |
|||
entity.ExtraProperties.Clear(); |
|||
|
|||
foreach (var property in updateInput.ExtraProperties) |
|||
{ |
|||
entity.ExtraProperties.Add(property.Key, property.Value); |
|||
} |
|||
} |
|||
|
|||
entity.SetConcurrencyStampIfNotNull(updateInput.ConcurrencyStamp); |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using Volo.Abp; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools; |
|||
public class AIToolAlreadyExistsException : BusinessException |
|||
{ |
|||
public string AITool { get; } |
|||
public AIToolAlreadyExistsException(string aiTool) |
|||
: base( |
|||
AIManagementErrorCodes.AITool.NameAlreadyExists, |
|||
$"A AITool named {aiTool} already exists!") |
|||
{ |
|||
AITool = aiTool; |
|||
|
|||
WithData(nameof(AITool), aiTool); |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
namespace LINGYUN.Abp.AIManagement.Tools; |
|||
public static class AIToolDefinitionRecordConsts |
|||
{ |
|||
public static int MaxNameLength { get; set; } = 64; |
|||
public static int MaxProviderLength { get; set; } = 20; |
|||
public static int MaxDescriptionLength { get; set; } = 128; |
|||
public static int MaxStateCheckersLength { get; set; } = 256; |
|||
} |
|||
@ -0,0 +1,134 @@ |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.Domain.Entities.Auditing; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools; |
|||
public class AIToolDefinitionRecord : AuditedAggregateRoot<Guid> |
|||
{ |
|||
public string Name { get; private set; } |
|||
|
|||
public string Provider { get; private set; } |
|||
|
|||
public string? Description { get; set; } |
|||
|
|||
public bool IsEnabled { get; set; } |
|||
|
|||
public bool IsSystem { get; set; } |
|||
|
|||
public bool IsGlobal { get; set; } |
|||
|
|||
public string? StateCheckers { get; set; } |
|||
protected AIToolDefinitionRecord() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public AIToolDefinitionRecord( |
|||
[NotNull] Guid id, |
|||
[NotNull] string name, |
|||
[NotNull] string provider, |
|||
[CanBeNull] string? description = null, |
|||
[CanBeNull] string? stateCheckers = null) |
|||
: base(id) |
|||
{ |
|||
Name = Check.NotNullOrWhiteSpace(name, nameof(name), AIToolDefinitionRecordConsts.MaxNameLength); |
|||
Provider = Check.NotNullOrWhiteSpace(provider, nameof(provider), AIToolDefinitionRecordConsts.MaxProviderLength); |
|||
Description = Check.Length(description, nameof(description), AIToolDefinitionRecordConsts.MaxDescriptionLength); |
|||
StateCheckers = Check.Length(stateCheckers, nameof(stateCheckers), AIToolDefinitionRecordConsts.MaxStateCheckersLength); |
|||
} |
|||
|
|||
public bool HasSameData(AIToolDefinitionRecord otherAITool) |
|||
{ |
|||
if (Name != otherAITool.Name) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
if (Provider != otherAITool.Provider) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
if (Description != otherAITool.Description) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
if (IsEnabled != otherAITool.IsEnabled) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
if (IsSystem != otherAITool.IsSystem) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
if (IsGlobal != otherAITool.IsGlobal) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
if (StateCheckers != otherAITool.StateCheckers) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
if (!this.HasSameExtraProperties(otherAITool)) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
public void Patch(AIToolDefinitionRecord otherAITool) |
|||
{ |
|||
if (Name != otherAITool.Name) |
|||
{ |
|||
Name = otherAITool.Name; |
|||
} |
|||
|
|||
if (Provider != otherAITool.Provider) |
|||
{ |
|||
Provider = otherAITool.Provider; |
|||
} |
|||
|
|||
if (Description != otherAITool.Description) |
|||
{ |
|||
Description = otherAITool.Description; |
|||
} |
|||
|
|||
if (IsEnabled != otherAITool.IsEnabled) |
|||
{ |
|||
IsEnabled = otherAITool.IsEnabled; |
|||
} |
|||
|
|||
if (IsSystem != otherAITool.IsSystem) |
|||
{ |
|||
IsSystem = otherAITool.IsSystem; |
|||
} |
|||
|
|||
if (IsGlobal != otherAITool.IsGlobal) |
|||
{ |
|||
IsGlobal = otherAITool.IsGlobal; |
|||
} |
|||
|
|||
if (StateCheckers != otherAITool.StateCheckers) |
|||
{ |
|||
StateCheckers = otherAITool.StateCheckers; |
|||
} |
|||
|
|||
if (!this.HasSameExtraProperties(otherAITool)) |
|||
{ |
|||
ExtraProperties.Clear(); |
|||
|
|||
foreach (var property in otherAITool.ExtraProperties) |
|||
{ |
|||
ExtraProperties.Add(property.Key, property.Value); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,68 @@ |
|||
using LINGYUN.Abp.AI.Tools; |
|||
using System.Collections.Generic; |
|||
using System.Globalization; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Guids; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.SimpleStateChecking; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools; |
|||
public class AIToolDefinitionSerializer : IAIToolDefinitionSerializer, ITransientDependency |
|||
{ |
|||
protected IGuidGenerator GuidGenerator { get; } |
|||
protected ISimpleStateCheckerSerializer StateCheckerSerializer { get; } |
|||
protected ILocalizableStringSerializer LocalizableStringSerializer { get; } |
|||
|
|||
public AIToolDefinitionSerializer( |
|||
IGuidGenerator guidGenerator, |
|||
ISimpleStateCheckerSerializer stateCheckerSerializer, |
|||
ILocalizableStringSerializer localizableStringSerializer) |
|||
{ |
|||
GuidGenerator = guidGenerator; |
|||
StateCheckerSerializer = stateCheckerSerializer; |
|||
LocalizableStringSerializer = localizableStringSerializer; |
|||
} |
|||
|
|||
public async virtual Task<AIToolDefinitionRecord[]> SerializeAsync(IEnumerable<AIToolDefinition> definitions) |
|||
{ |
|||
var records = new List<AIToolDefinitionRecord>(); |
|||
foreach (var aiToolDef in definitions) |
|||
{ |
|||
records.Add(await SerializeAsync(aiToolDef)); |
|||
} |
|||
|
|||
return records.ToArray(); |
|||
} |
|||
|
|||
public virtual Task<AIToolDefinitionRecord> SerializeAsync(AIToolDefinition definition) |
|||
{ |
|||
using (CultureHelper.Use(CultureInfo.InvariantCulture)) |
|||
{ |
|||
var aiToolRecord = new AIToolDefinitionRecord( |
|||
GuidGenerator.Create(), |
|||
definition.Name, |
|||
definition.Provider, |
|||
definition.Description != null ? LocalizableStringSerializer.Serialize(definition.Description) : null, |
|||
SerializeStateCheckers(definition.StateCheckers)) |
|||
{ |
|||
IsGlobal = definition.IsGlobal, |
|||
IsEnabled = definition.IsEnabled, |
|||
IsSystem = true, |
|||
}; |
|||
|
|||
foreach (var property in definition.Properties) |
|||
{ |
|||
aiToolRecord.SetProperty(property.Key, property.Value); |
|||
} |
|||
|
|||
return Task.FromResult(aiToolRecord); |
|||
} |
|||
} |
|||
|
|||
protected virtual string? SerializeStateCheckers(List<ISimpleStateChecker<AIToolDefinition>> stateCheckers) |
|||
{ |
|||
return StateCheckerSerializer.Serialize(stateCheckers); |
|||
} |
|||
} |
|||
@ -0,0 +1,138 @@ |
|||
using LINGYUN.Abp.AI.Tools; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Hosting; |
|||
using Microsoft.Extensions.Logging; |
|||
using Microsoft.Extensions.Logging.Abstractions; |
|||
using Microsoft.Extensions.Options; |
|||
using Polly; |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Threading; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools; |
|||
public class AIToolDynamicInitializer : ITransientDependency |
|||
{ |
|||
public ILogger<AIToolDynamicInitializer> Logger { get; set; } |
|||
|
|||
protected IServiceProvider ServiceProvider { get; } |
|||
|
|||
public AIToolDynamicInitializer(IServiceProvider serviceProvider) |
|||
{ |
|||
Logger = NullLogger<AIToolDynamicInitializer>.Instance; |
|||
|
|||
ServiceProvider = serviceProvider; |
|||
} |
|||
|
|||
public virtual Task InitializeAsync(bool runInBackground, CancellationToken cancellationToken = default) |
|||
{ |
|||
var options = ServiceProvider.GetRequiredService<IOptions<AIManagementOptions>>().Value; |
|||
|
|||
if (!options.SaveStaticAIToolsToDatabase && !options.IsDynamicAIToolStoreEnabled) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
if (runInBackground) |
|||
{ |
|||
var applicationLifetime = ServiceProvider.GetService<IHostApplicationLifetime>(); |
|||
Task.Run(async () => |
|||
{ |
|||
if (cancellationToken == default && applicationLifetime?.ApplicationStopping != null) |
|||
{ |
|||
cancellationToken = applicationLifetime.ApplicationStopping; |
|||
} |
|||
await ExecuteInitializationAsync(options, cancellationToken); |
|||
}, cancellationToken); |
|||
|
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
return ExecuteInitializationAsync(options, cancellationToken); |
|||
} |
|||
|
|||
protected virtual async Task ExecuteInitializationAsync(AIManagementOptions options, CancellationToken cancellationToken) |
|||
{ |
|||
try |
|||
{ |
|||
var cancellationTokenProvider = ServiceProvider.GetRequiredService<ICancellationTokenProvider>(); |
|||
using (cancellationTokenProvider.Use(cancellationToken)) |
|||
{ |
|||
if (cancellationTokenProvider.Token.IsCancellationRequested) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
await SaveStaticAIToolsToDatabaseAsync(options, cancellationToken); |
|||
|
|||
if (cancellationTokenProvider.Token.IsCancellationRequested) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
await PreCacheDynamicAIToolsAsync(options); |
|||
} |
|||
} |
|||
catch |
|||
{ |
|||
// No need to log here since inner calls log
|
|||
} |
|||
} |
|||
|
|||
protected virtual async Task SaveStaticAIToolsToDatabaseAsync( |
|||
AIManagementOptions options, |
|||
CancellationToken cancellationToken) |
|||
{ |
|||
if (!options.SaveStaticAIToolsToDatabase) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
var staticAIToolSaver = ServiceProvider.GetRequiredService<IStaticAIToolSaver>(); |
|||
|
|||
await Policy |
|||
.Handle<Exception>(ex => ex is not OperationCanceledException) |
|||
.WaitAndRetryAsync( |
|||
8, |
|||
retryAttempt => TimeSpan.FromSeconds( |
|||
Volo.Abp.RandomHelper.GetRandom( |
|||
(int)Math.Pow(2, retryAttempt) * 8, |
|||
(int)Math.Pow(2, retryAttempt) * 12) |
|||
) |
|||
) |
|||
.ExecuteAsync(async _ => |
|||
{ |
|||
try |
|||
{ |
|||
await staticAIToolSaver.SaveAsync(); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Logger.LogException(ex); |
|||
throw; // Polly will catch it
|
|||
} |
|||
}, cancellationToken); |
|||
} |
|||
|
|||
protected virtual async Task PreCacheDynamicAIToolsAsync(AIManagementOptions options) |
|||
{ |
|||
if (!options.IsDynamicAIToolStoreEnabled) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
var dynamicAIToolDefinitionStore = ServiceProvider.GetRequiredService<IDynamicAIToolDefinitionStore>(); |
|||
|
|||
try |
|||
{ |
|||
// Pre-cache AITools, so first request doesn't wait
|
|||
await dynamicAIToolDefinitionStore.GetAllAsync(); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Logger.LogException(ex); |
|||
throw; // It will be cached in Initialize()
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,160 @@ |
|||
using JetBrains.Annotations; |
|||
using LINGYUN.Abp.AI.Tools; |
|||
using Microsoft.Extensions.Caching.Distributed; |
|||
using Microsoft.Extensions.Options; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.DistributedLocking; |
|||
using Volo.Abp.Threading; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools; |
|||
|
|||
[Dependency(ReplaceServices = true)] |
|||
public class DynamicAIToolDefinitionStore : IDynamicAIToolDefinitionStore, ITransientDependency |
|||
{ |
|||
protected IAIToolDefinitionRecordRepository AIToolDefinitionRecordRepository { get; } |
|||
protected IAIToolDefinitionSerializer AIToolDefinitionSerializer { get; } |
|||
protected IDynamicAIToolDefinitionStoreInMemoryCache StoreCache { get; } |
|||
protected IDistributedCache DistributedCache { get; } |
|||
protected IAbpDistributedLock DistributedLock { get; } |
|||
public AIManagementOptions AIManagementOptions { get; } |
|||
protected AbpDistributedCacheOptions CacheOptions { get; } |
|||
|
|||
public DynamicAIToolDefinitionStore( |
|||
IAIToolDefinitionRecordRepository aiToolDefinitionRecordRepository, |
|||
IAIToolDefinitionSerializer aiToolDefinitionSerializer, |
|||
IDynamicAIToolDefinitionStoreInMemoryCache storeCache, |
|||
IDistributedCache distributedCache, |
|||
IOptions<AbpDistributedCacheOptions> cacheOptions, |
|||
IOptions<AIManagementOptions> aiManagementOptions, |
|||
IAbpDistributedLock distributedLock) |
|||
{ |
|||
AIToolDefinitionRecordRepository = aiToolDefinitionRecordRepository; |
|||
AIToolDefinitionSerializer = aiToolDefinitionSerializer; |
|||
StoreCache = storeCache; |
|||
DistributedCache = distributedCache; |
|||
DistributedLock = distributedLock; |
|||
AIManagementOptions = aiManagementOptions.Value; |
|||
CacheOptions = cacheOptions.Value; |
|||
} |
|||
|
|||
public async virtual Task<IReadOnlyList<AIToolDefinition>> GetAllAsync() |
|||
{ |
|||
if (!AIManagementOptions.IsDynamicAIToolStoreEnabled) |
|||
{ |
|||
return Array.Empty<AIToolDefinition>(); |
|||
} |
|||
|
|||
using (await StoreCache.SyncSemaphore.LockAsync()) |
|||
{ |
|||
await EnsureCacheIsUptoDateAsync(); |
|||
return StoreCache.GetAITools(); |
|||
} |
|||
} |
|||
|
|||
public async virtual Task<AIToolDefinition> GetAsync([NotNull] string name) |
|||
{ |
|||
Check.NotNull(name, nameof(name)); |
|||
|
|||
return await GetOrNullAsync(name) ?? throw new AbpException("Undefined AITool: " + name); |
|||
} |
|||
|
|||
public async virtual Task<AIToolDefinition?> GetOrNullAsync([NotNull] string name) |
|||
{ |
|||
Check.NotNull(name, nameof(name)); |
|||
|
|||
if (!AIManagementOptions.IsDynamicAIToolStoreEnabled) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
using (await StoreCache.SyncSemaphore.LockAsync()) |
|||
{ |
|||
await EnsureCacheIsUptoDateAsync(); |
|||
return StoreCache.GetAIToolOrNull(name); |
|||
} |
|||
} |
|||
protected virtual async Task EnsureCacheIsUptoDateAsync() |
|||
{ |
|||
if (StoreCache.LastCheckTime.HasValue && |
|||
DateTime.Now.Subtract(StoreCache.LastCheckTime.Value).TotalSeconds < 30) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
var stampInDistributedCache = await GetOrSetStampInDistributedCache(); |
|||
|
|||
if (stampInDistributedCache == StoreCache.CacheStamp) |
|||
{ |
|||
StoreCache.LastCheckTime = DateTime.Now; |
|||
return; |
|||
} |
|||
|
|||
await UpdateInMemoryStoreCache(); |
|||
|
|||
StoreCache.CacheStamp = stampInDistributedCache; |
|||
StoreCache.LastCheckTime = DateTime.Now; |
|||
} |
|||
|
|||
protected virtual async Task UpdateInMemoryStoreCache() |
|||
{ |
|||
var workspaces = await AIToolDefinitionRecordRepository.GetListAsync(); |
|||
|
|||
await StoreCache.FillAsync(workspaces); |
|||
} |
|||
|
|||
protected virtual async Task<string> GetOrSetStampInDistributedCache() |
|||
{ |
|||
var cacheKey = GetCommonStampCacheKey(); |
|||
|
|||
var stampInDistributedCache = await DistributedCache.GetStringAsync(cacheKey); |
|||
if (stampInDistributedCache != null) |
|||
{ |
|||
return stampInDistributedCache; |
|||
} |
|||
|
|||
await using (var commonLockHandle = await DistributedLock |
|||
.TryAcquireAsync(GetCommonDistributedLockKey(), TimeSpan.FromMinutes(2))) |
|||
{ |
|||
if (commonLockHandle == null) |
|||
{ |
|||
throw new AbpException( |
|||
"Could not acquire distributed lock for AITool definition common stamp check!" |
|||
); |
|||
} |
|||
|
|||
stampInDistributedCache = await DistributedCache.GetStringAsync(cacheKey); |
|||
if (stampInDistributedCache != null) |
|||
{ |
|||
return stampInDistributedCache; |
|||
} |
|||
|
|||
stampInDistributedCache = Guid.NewGuid().ToString(); |
|||
|
|||
await DistributedCache.SetStringAsync( |
|||
cacheKey, |
|||
stampInDistributedCache, |
|||
new DistributedCacheEntryOptions |
|||
{ |
|||
SlidingExpiration = TimeSpan.FromDays(30) |
|||
} |
|||
); |
|||
} |
|||
|
|||
return stampInDistributedCache; |
|||
} |
|||
|
|||
protected virtual string GetCommonStampCacheKey() |
|||
{ |
|||
return $"{CacheOptions.KeyPrefix}_AbpInMemoryAIToolCacheStamp"; |
|||
} |
|||
|
|||
protected virtual string GetCommonDistributedLockKey() |
|||
{ |
|||
return $"{CacheOptions.KeyPrefix}_Common_AbpAIToolUpdateLock"; |
|||
} |
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
using Microsoft.Extensions.Caching.Distributed; |
|||
using Microsoft.Extensions.Options; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities.Events; |
|||
using Volo.Abp.EventBus; |
|||
using Volo.Abp.Threading; |
|||
using Volo.Abp.Timing; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools; |
|||
public class DynamicAIToolDefinitionStoreCacheInvalidator : |
|||
ILocalEventHandler<EntityChangedEventData<AIToolDefinitionRecord>>, |
|||
ITransientDependency |
|||
{ |
|||
private readonly IDynamicAIToolDefinitionStoreInMemoryCache _storeCache; |
|||
|
|||
private readonly IClock _clock; |
|||
private readonly IDistributedCache _distributedCache; |
|||
private readonly AbpDistributedCacheOptions _cacheOptions; |
|||
|
|||
public DynamicAIToolDefinitionStoreCacheInvalidator( |
|||
IClock clock, |
|||
IDistributedCache distributedCache, |
|||
IDynamicAIToolDefinitionStoreInMemoryCache storeCache, |
|||
IOptions<AbpDistributedCacheOptions> cacheOptions) |
|||
{ |
|||
_storeCache = storeCache; |
|||
_clock = clock; |
|||
_distributedCache = distributedCache; |
|||
_cacheOptions = cacheOptions.Value; |
|||
} |
|||
|
|||
public async virtual Task HandleEventAsync(EntityChangedEventData<AIToolDefinitionRecord> eventData) |
|||
{ |
|||
await RemoveStampInDistributedCacheAsync(); |
|||
} |
|||
|
|||
protected async virtual Task RemoveStampInDistributedCacheAsync() |
|||
{ |
|||
using (await _storeCache.SyncSemaphore.LockAsync()) |
|||
{ |
|||
var cacheKey = GetCommonStampCacheKey(); |
|||
|
|||
await _distributedCache.RemoveAsync(cacheKey); |
|||
|
|||
_storeCache.CacheStamp = Guid.NewGuid().ToString(); |
|||
_storeCache.LastCheckTime = _clock.Now.AddMinutes(-5); |
|||
} |
|||
} |
|||
|
|||
protected virtual string GetCommonStampCacheKey() |
|||
{ |
|||
return $"{_cacheOptions.KeyPrefix}_AbpInMemoryAIToolCacheStamp"; |
|||
} |
|||
} |
|||
@ -0,0 +1,81 @@ |
|||
using LINGYUN.Abp.AI.Tools; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.SimpleStateChecking; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools; |
|||
public class DynamicAIToolDefinitionStoreInMemoryCache : IDynamicAIToolDefinitionStoreInMemoryCache, ISingletonDependency |
|||
{ |
|||
public string CacheStamp { get; set; } |
|||
protected IDictionary<string, AIToolDefinition> AIToolDefinitions { get; } |
|||
protected ISimpleStateCheckerSerializer StateCheckerSerializer { get; } |
|||
protected ILocalizableStringSerializer LocalizableStringSerializer { get; } |
|||
|
|||
public SemaphoreSlim SyncSemaphore { get; } = new(1, 1); |
|||
|
|||
public DateTime? LastCheckTime { get; set; } |
|||
|
|||
public DynamicAIToolDefinitionStoreInMemoryCache( |
|||
ISimpleStateCheckerSerializer stateCheckerSerializer, |
|||
ILocalizableStringSerializer localizableStringSerializer) |
|||
{ |
|||
StateCheckerSerializer = stateCheckerSerializer; |
|||
LocalizableStringSerializer = localizableStringSerializer; |
|||
|
|||
AIToolDefinitions = new Dictionary<string, AIToolDefinition>(); |
|||
} |
|||
|
|||
public Task FillAsync(List<AIToolDefinitionRecord> tools) |
|||
{ |
|||
AIToolDefinitions.Clear(); |
|||
|
|||
foreach (var tool in tools) |
|||
{ |
|||
var toolDef = new AIToolDefinition( |
|||
tool.Name, |
|||
tool.Provider, |
|||
!tool.Description.IsNullOrWhiteSpace() ? LocalizableStringSerializer.Deserialize(tool.Description) : null) |
|||
{ |
|||
IsEnabled = tool.IsEnabled, |
|||
IsGlobal = tool.IsGlobal, |
|||
}; |
|||
|
|||
if (!tool.StateCheckers.IsNullOrWhiteSpace()) |
|||
{ |
|||
var checkers = StateCheckerSerializer |
|||
.DeserializeArray( |
|||
tool.StateCheckers, |
|||
toolDef |
|||
); |
|||
toolDef.StateCheckers.AddRange(checkers); |
|||
} |
|||
|
|||
foreach (var property in tool.ExtraProperties) |
|||
{ |
|||
if (property.Value != null) |
|||
{ |
|||
toolDef.WithProperty(property.Key, property.Value); |
|||
} |
|||
} |
|||
|
|||
AIToolDefinitions[tool.Name] = toolDef; |
|||
} |
|||
|
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public AIToolDefinition? GetAIToolOrNull(string name) |
|||
{ |
|||
return AIToolDefinitions.GetOrDefault(name); |
|||
} |
|||
|
|||
public IReadOnlyList<AIToolDefinition> GetAITools() |
|||
{ |
|||
return AIToolDefinitions.Values.ToList(); |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools; |
|||
public interface IAIToolDefinitionRecordRepository : IRepository<AIToolDefinitionRecord, Guid> |
|||
{ |
|||
Task<AIToolDefinitionRecord?> FindByNameAsync( |
|||
string name, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using LINGYUN.Abp.AI.Tools; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools; |
|||
public interface IAIToolDefinitionSerializer |
|||
{ |
|||
Task<AIToolDefinitionRecord[]> SerializeAsync(IEnumerable<AIToolDefinition> definitions); |
|||
|
|||
Task<AIToolDefinitionRecord> SerializeAsync(AIToolDefinition definition); |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using LINGYUN.Abp.AI.Tools; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools; |
|||
public interface IDynamicAIToolDefinitionStoreInMemoryCache |
|||
{ |
|||
string CacheStamp { get; set; } |
|||
|
|||
SemaphoreSlim SyncSemaphore { get; } |
|||
|
|||
DateTime? LastCheckTime { get; set; } |
|||
|
|||
Task FillAsync(List<AIToolDefinitionRecord> tools); |
|||
|
|||
AIToolDefinition? GetAIToolOrNull(string name); |
|||
|
|||
IReadOnlyList<AIToolDefinition> GetAITools(); |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools; |
|||
public interface IStaticAIToolSaver |
|||
{ |
|||
Task SaveAsync(); |
|||
} |
|||
@ -0,0 +1,241 @@ |
|||
using LINGYUN.Abp.AI.Tools; |
|||
using Microsoft.Extensions.Caching.Distributed; |
|||
using Microsoft.Extensions.Options; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Text.Json; |
|||
using System.Text.Json.Serialization.Metadata; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.DistributedLocking; |
|||
using Volo.Abp.Guids; |
|||
using Volo.Abp.Json.SystemTextJson.Modifiers; |
|||
using Volo.Abp.Threading; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools; |
|||
public class StaticAIToolSaver : IStaticAIToolSaver, ITransientDependency |
|||
{ |
|||
protected IStaticAIToolDefinitionStore StaticStore { get; } |
|||
protected IAIToolDefinitionRecordRepository AIToolDefinitionRecordRepository { get; } |
|||
protected IAIToolDefinitionSerializer AIToolDefinitionSerializer { get; } |
|||
protected IDistributedCache Cache { get; } |
|||
protected IApplicationInfoAccessor ApplicationInfoAccessor { get; } |
|||
protected IAbpDistributedLock DistributedLock { get; } |
|||
protected AbpAIToolsOptions AIToolOptions { get; } |
|||
protected ICancellationTokenProvider CancellationTokenProvider { get; } |
|||
protected AbpDistributedCacheOptions CacheOptions { get; } |
|||
protected IUnitOfWorkManager UnitOfWorkManager { get; } |
|||
protected IGuidGenerator GuidGenerator { get; } |
|||
|
|||
public StaticAIToolSaver( |
|||
IStaticAIToolDefinitionStore staticStore, |
|||
IAIToolDefinitionRecordRepository aiToolDefinitionRecordRepository, |
|||
IAIToolDefinitionSerializer aiToolDefinitionSerializer, |
|||
IDistributedCache cache, |
|||
IOptions<AbpDistributedCacheOptions> cacheOptions, |
|||
IApplicationInfoAccessor applicationInfoAccessor, |
|||
IAbpDistributedLock distributedLock, |
|||
IOptions<AbpAIToolsOptions> aiToolOptions, |
|||
ICancellationTokenProvider cancellationTokenProvider, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
IGuidGenerator guidGenerator) |
|||
{ |
|||
StaticStore = staticStore; |
|||
AIToolDefinitionRecordRepository = aiToolDefinitionRecordRepository; |
|||
AIToolDefinitionSerializer = aiToolDefinitionSerializer; |
|||
Cache = cache; |
|||
ApplicationInfoAccessor = applicationInfoAccessor; |
|||
DistributedLock = distributedLock; |
|||
CancellationTokenProvider = cancellationTokenProvider; |
|||
AIToolOptions = aiToolOptions.Value; |
|||
CacheOptions = cacheOptions.Value; |
|||
UnitOfWorkManager = unitOfWorkManager; |
|||
GuidGenerator = guidGenerator; |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public async Task SaveAsync() |
|||
{ |
|||
await using var applicationLockHandle = await DistributedLock.TryAcquireAsync( |
|||
GetApplicationDistributedLockKey() |
|||
); |
|||
|
|||
if (applicationLockHandle == null) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
var cacheKey = GetApplicationHashCacheKey(); |
|||
var cachedHash = await Cache.GetStringAsync(cacheKey, CancellationTokenProvider.Token); |
|||
|
|||
var aiTools = await AIToolDefinitionSerializer.SerializeAsync(await StaticStore.GetAllAsync()); |
|||
var currentHash = CalculateHash(aiTools, AIToolOptions.DeletedAITools); |
|||
|
|||
if (cachedHash == currentHash) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
await using (var commonLockHandle = await DistributedLock.TryAcquireAsync( |
|||
GetCommonDistributedLockKey(), |
|||
TimeSpan.FromMinutes(5))) |
|||
{ |
|||
if (commonLockHandle == null) |
|||
{ |
|||
/* It will re-try */ |
|||
throw new AbpException("Could not acquire distributed lock for saving static AITool!"); |
|||
} |
|||
|
|||
using (var unitOfWork = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true)) |
|||
{ |
|||
try |
|||
{ |
|||
var hasChangesInAITools = await UpdateChangedAIToolsAsync(aiTools); |
|||
|
|||
if (hasChangesInAITools) |
|||
{ |
|||
await Cache.SetStringAsync( |
|||
GetCommonStampCacheKey(), |
|||
Guid.NewGuid().ToString(), |
|||
new DistributedCacheEntryOptions |
|||
{ |
|||
SlidingExpiration = TimeSpan.FromDays(30) |
|||
}, |
|||
CancellationTokenProvider.Token |
|||
); |
|||
} |
|||
} |
|||
catch |
|||
{ |
|||
try |
|||
{ |
|||
await unitOfWork.RollbackAsync(); |
|||
} |
|||
catch |
|||
{ |
|||
/* ignored */ |
|||
} |
|||
|
|||
throw; |
|||
} |
|||
|
|||
await unitOfWork.CompleteAsync(); |
|||
} |
|||
} |
|||
|
|||
await Cache.SetStringAsync( |
|||
cacheKey, |
|||
currentHash, |
|||
new DistributedCacheEntryOptions |
|||
{ |
|||
SlidingExpiration = TimeSpan.FromDays(30) |
|||
}, |
|||
CancellationTokenProvider.Token |
|||
); |
|||
} |
|||
|
|||
private async Task<bool> UpdateChangedAIToolsAsync(AIToolDefinitionRecord[] aiToolRecords) |
|||
{ |
|||
var newRecords = new List<AIToolDefinitionRecord>(); |
|||
var changedRecords = new List<AIToolDefinitionRecord>(); |
|||
|
|||
var aiToolRecordsInDatabase = (await AIToolDefinitionRecordRepository.GetListAsync()).ToDictionary(x => x.Name); |
|||
|
|||
foreach (var record in aiToolRecords) |
|||
{ |
|||
var aiToolRecordInDatabase = aiToolRecordsInDatabase.GetOrDefault(record.Name); |
|||
if (aiToolRecordInDatabase == null) |
|||
{ |
|||
/* New group */ |
|||
newRecords.Add(record); |
|||
continue; |
|||
} |
|||
|
|||
if (record.HasSameData(aiToolRecordInDatabase)) |
|||
{ |
|||
/* Not changed */ |
|||
continue; |
|||
} |
|||
|
|||
/* Changed */ |
|||
aiToolRecordInDatabase.Patch(record); |
|||
changedRecords.Add(aiToolRecordInDatabase); |
|||
} |
|||
|
|||
/* Deleted */ |
|||
var deletedRecords = new List<AIToolDefinitionRecord>(); |
|||
|
|||
if (AIToolOptions.DeletedAITools.Any()) |
|||
{ |
|||
deletedRecords.AddRange(aiToolRecordsInDatabase.Values.Where(x => AIToolOptions.DeletedAITools.Contains(x.Name))); |
|||
} |
|||
|
|||
if (newRecords.Any()) |
|||
{ |
|||
await AIToolDefinitionRecordRepository.InsertManyAsync(newRecords); |
|||
} |
|||
|
|||
if (changedRecords.Any()) |
|||
{ |
|||
await AIToolDefinitionRecordRepository.UpdateManyAsync(changedRecords); |
|||
} |
|||
|
|||
if (deletedRecords.Any()) |
|||
{ |
|||
await AIToolDefinitionRecordRepository.DeleteManyAsync(deletedRecords); |
|||
} |
|||
|
|||
return newRecords.Any() || changedRecords.Any() || deletedRecords.Any(); |
|||
} |
|||
|
|||
private string GetApplicationDistributedLockKey() |
|||
{ |
|||
return $"{CacheOptions.KeyPrefix}_{ApplicationInfoAccessor.ApplicationName}_AbpAIToolUpdateLock"; |
|||
} |
|||
|
|||
private string GetCommonDistributedLockKey() |
|||
{ |
|||
return $"{CacheOptions.KeyPrefix}_Common_AbpAIToolUpdateLock"; |
|||
} |
|||
|
|||
private string GetApplicationHashCacheKey() |
|||
{ |
|||
return $"{CacheOptions.KeyPrefix}_{ApplicationInfoAccessor.ApplicationName}_AbpAIToolsHash"; |
|||
} |
|||
|
|||
private string GetCommonStampCacheKey() |
|||
{ |
|||
return $"{CacheOptions.KeyPrefix}_AbpInMemoryAIToolCacheStamp"; |
|||
} |
|||
|
|||
private string CalculateHash(AIToolDefinitionRecord[] aiToolRecords, IEnumerable<string> deletedAITool) |
|||
{ |
|||
var jsonSerializerOptions = new JsonSerializerOptions |
|||
{ |
|||
TypeInfoResolver = new DefaultJsonTypeInfoResolver |
|||
{ |
|||
Modifiers = |
|||
{ |
|||
new AbpIgnorePropertiesModifiers<AIToolDefinitionRecord, Guid>().CreateModifyAction(x => x.Id), |
|||
} |
|||
} |
|||
}; |
|||
|
|||
var stringBuilder = new StringBuilder(); |
|||
|
|||
stringBuilder.Append("AITools:"); |
|||
stringBuilder.AppendLine(JsonSerializer.Serialize(aiToolRecords, jsonSerializerOptions)); |
|||
|
|||
stringBuilder.Append("DeletedAITool:"); |
|||
stringBuilder.Append(deletedAITool.JoinAsString(",")); |
|||
|
|||
return stringBuilder |
|||
.ToString() |
|||
.ToMd5(); |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
using LINGYUN.Abp.AIManagement.Tools; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using System; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.EntityFrameworkCore; |
|||
public class EfCoreAIToolDefinitionRecordRepository : |
|||
EfCoreRepository<IAIManagementDbContext, AIToolDefinitionRecord, Guid>, |
|||
IAIToolDefinitionRecordRepository |
|||
{ |
|||
public EfCoreAIToolDefinitionRecordRepository( |
|||
IDbContextProvider<IAIManagementDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public async virtual Task<AIToolDefinitionRecord?> FindByNameAsync(string name, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetQueryableAsync()) |
|||
.Where(x => x.Name == name) |
|||
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
using LINGYUN.Abp.AIManagement.Permissions; |
|||
using LINGYUN.Abp.AIManagement.Tools.Dtos; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Tools; |
|||
|
|||
[Controller] |
|||
[RemoteService(Name = AIManagementRemoteServiceConsts.RemoteServiceName)] |
|||
[Area(AIManagementRemoteServiceConsts.ModuleName)] |
|||
[Route($"api/{AIManagementRemoteServiceConsts.ModuleName}/tools")] |
|||
[Authorize(AIManagementPermissionNames.AIToolDefinition.Default)] |
|||
public class AIToolDefinitionController : AbpControllerBase, IAIToolDefinitionAppService |
|||
{ |
|||
private readonly IAIToolDefinitionAppService _service; |
|||
public AIToolDefinitionController(IAIToolDefinitionAppService service) |
|||
{ |
|||
_service = service; |
|||
} |
|||
|
|||
[HttpPost] |
|||
[Authorize(AIManagementPermissionNames.AIToolDefinition.Create)] |
|||
public virtual Task<AIToolDefinitionRecordDto> CreateAsync(AIToolDefinitionRecordCreateDto input) |
|||
{ |
|||
return _service.CreateAsync(input); |
|||
} |
|||
|
|||
[HttpDelete("{id}")] |
|||
[Authorize(AIManagementPermissionNames.AIToolDefinition.Delete)] |
|||
public virtual Task DeleteAsync(Guid id) |
|||
{ |
|||
return _service.DeleteAsync(id); |
|||
} |
|||
|
|||
[HttpGet("{id}")] |
|||
public virtual Task<AIToolDefinitionRecordDto> GetAsync(Guid id) |
|||
{ |
|||
return _service.GetAsync(id); |
|||
} |
|||
|
|||
[HttpGet("available-providers")] |
|||
public virtual Task<ListResultDto<AIToolProviderDto>> GetAvailableProvidersAsync() |
|||
{ |
|||
return _service.GetAvailableProvidersAsync(); |
|||
} |
|||
|
|||
[HttpGet] |
|||
public virtual Task<PagedResultDto<AIToolDefinitionRecordDto>> GetListAsync(AIToolDefinitionRecordGetPagedListInput input) |
|||
{ |
|||
return _service.GetListAsync(input); |
|||
} |
|||
|
|||
[HttpPut("{id}")] |
|||
[Authorize(AIManagementPermissionNames.AIToolDefinition.Update)] |
|||
public virtual Task<AIToolDefinitionRecordDto> UpdateAsync(Guid id, AIToolDefinitionRecordUpdateDto input) |
|||
{ |
|||
return _service.UpdateAsync(id, input); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue