From d0346533a09a4d9eb9270cd8cb502de0d76cef70 Mon Sep 17 00:00:00 2001 From: ivamp Date: Wed, 4 Sep 2024 18:46:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E8=AE=B0=E5=BF=86?= =?UTF-8?q?=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/swagger.yaml | 115 +++++++-- src/api/api.ts | 388 ++++++++++++++++++++++++---- src/pages/assistants/[id]/chats.vue | 4 +- src/pages/assistants/[id]/edit.vue | 22 +- src/pages/tools/validate.vue | 4 +- 5 files changed, 454 insertions(+), 79 deletions(-) diff --git a/api/swagger.yaml b/api/swagger.yaml index 2a7bd01..fb95794 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -7,6 +7,10 @@ definitions: type: string disable_default_prompt: type: boolean + disable_memory: + type: boolean + enable_memory_for_assistant_share: + type: boolean id: example: "0" type: string @@ -53,24 +57,6 @@ definitions: updated_at: type: string type: object - entity.AssistantToolType: - properties: - assistant: - $ref: '#/definitions/entity.Assistant' - assistant_id: - type: integer - created_at: - type: string - id: - example: "0" - type: string - tool: - $ref: '#/definitions/entity.Tool' - tool_id: - type: integer - updated_at: - type: string - type: object entity.Chat: properties: assistant_id: @@ -91,7 +77,6 @@ definitions: updated_at: type: string user_id: - description: Assistant Assistant `json:"assistant"` type: integer type: object entity.ChatMessage: @@ -147,6 +132,20 @@ definitions: url_hash: type: string type: object + entity.Memory: + properties: + content: + type: string + created_at: + type: string + id: + example: "0" + type: string + updated_at: + type: string + user_id: + type: integer + type: object entity.Tool: properties: api_key: @@ -221,6 +220,16 @@ definitions: - true - false type: boolean + disable_memory: + enum: + - true + - false + type: boolean + enable_memory_for_assistant_share: + enum: + - true + - false + type: boolean name: maxLength: 255 type: string @@ -806,7 +815,7 @@ paths: - properties: data: items: - $ref: '#/definitions/entity.AssistantToolType' + $ref: '#/definitions/entity.AssistantTool' type: array type: object "500": @@ -1445,6 +1454,72 @@ paths: summary: 下载文件 tags: - file + /api/v1/memories: + get: + consumes: + - application/json + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/schema.ResponseBody' + - properties: + data: + $ref: '#/definitions/entity.Memory' + type: object + "400": + description: Bad Request + schema: + $ref: '#/definitions/schema.ResponseBody' + security: + - ApiKeyAuth: [] + summary: 获取所有的记忆 + tags: + - memoires + /api/v1/memories/{id}: + delete: + consumes: + - application/json + parameters: + - in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "204": + description: No Content + "400": + description: Bad Request + schema: + $ref: '#/definitions/schema.ResponseBody' + security: + - ApiKeyAuth: [] + summary: 删除指定的记忆 + tags: + - memoires + /api/v1/memories/purge: + post: + consumes: + - application/json + produces: + - application/json + responses: + "204": + description: No Content + "400": + description: Bad Request + schema: + $ref: '#/definitions/schema.ResponseBody' + security: + - ApiKeyAuth: [] + summary: 删除全部记忆 + tags: + - memoires /api/v1/ping: get: consumes: diff --git a/src/api/api.ts b/src/api/api.ts index f28bd53..3cd8584 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -124,10 +124,10 @@ export interface ApiV1AssistantsIdSharesPost200Response { export interface ApiV1AssistantsIdToolsGet200Response { /** * - * @type {Array} + * @type {Array} * @memberof ApiV1AssistantsIdToolsGet200Response */ - 'data'?: Array; + 'data'?: Array; /** * * @type {string} @@ -383,6 +383,37 @@ export interface ApiV1ChatsIdImagesPostRequest { */ 'image'?: File; } +/** + * + * @export + * @interface ApiV1MemoriesGet200Response + */ +export interface ApiV1MemoriesGet200Response { + /** + * + * @type {EntityMemory} + * @memberof ApiV1MemoriesGet200Response + */ + 'data'?: EntityMemory; + /** + * + * @type {string} + * @memberof ApiV1MemoriesGet200Response + */ + 'error'?: string; + /** + * + * @type {string} + * @memberof ApiV1MemoriesGet200Response + */ + 'message'?: string; + /** + * + * @type {boolean} + * @memberof ApiV1MemoriesGet200Response + */ + 'success'?: boolean; +} /** * * @export @@ -500,6 +531,18 @@ export interface EntityAssistant { * @memberof EntityAssistant */ 'disable_default_prompt'?: boolean; + /** + * + * @type {boolean} + * @memberof EntityAssistant + */ + 'disable_memory'?: boolean; + /** + * + * @type {boolean} + * @memberof EntityAssistant + */ + 'enable_memory_for_assistant_share'?: boolean; /** * * @type {string} @@ -623,55 +666,6 @@ export interface EntityAssistantTool { */ 'updated_at'?: string; } -/** - * - * @export - * @interface EntityAssistantToolType - */ -export interface EntityAssistantToolType { - /** - * - * @type {EntityAssistant} - * @memberof EntityAssistantToolType - */ - 'assistant'?: EntityAssistant; - /** - * - * @type {number} - * @memberof EntityAssistantToolType - */ - 'assistant_id'?: number; - /** - * - * @type {string} - * @memberof EntityAssistantToolType - */ - 'created_at'?: string; - /** - * - * @type {string} - * @memberof EntityAssistantToolType - */ - 'id'?: string; - /** - * - * @type {EntityTool} - * @memberof EntityAssistantToolType - */ - 'tool'?: EntityTool; - /** - * - * @type {number} - * @memberof EntityAssistantToolType - */ - 'tool_id'?: number; - /** - * - * @type {string} - * @memberof EntityAssistantToolType - */ - 'updated_at'?: string; -} /** * * @export @@ -727,7 +721,7 @@ export interface EntityChat { */ 'updated_at'?: string; /** - * Assistant Assistant `json:\"assistant\"` + * * @type {number} * @memberof EntityChat */ @@ -873,6 +867,43 @@ export interface EntityFile { */ 'url_hash'?: string; } +/** + * + * @export + * @interface EntityMemory + */ +export interface EntityMemory { + /** + * + * @type {string} + * @memberof EntityMemory + */ + 'content'?: string; + /** + * + * @type {string} + * @memberof EntityMemory + */ + 'created_at'?: string; + /** + * + * @type {string} + * @memberof EntityMemory + */ + 'id'?: string; + /** + * + * @type {string} + * @memberof EntityMemory + */ + 'updated_at'?: string; + /** + * + * @type {number} + * @memberof EntityMemory + */ + 'user_id'?: number; +} /** * * @export @@ -1025,6 +1056,18 @@ export interface SchemaAssistantUpdateRequest { * @memberof SchemaAssistantUpdateRequest */ 'disable_default_prompt'?: boolean; + /** + * + * @type {boolean} + * @memberof SchemaAssistantUpdateRequest + */ + 'disable_memory'?: boolean; + /** + * + * @type {boolean} + * @memberof SchemaAssistantUpdateRequest + */ + 'enable_memory_for_assistant_share'?: boolean; /** * * @type {string} @@ -3861,6 +3904,247 @@ export class FileApi extends BaseAPI { +/** + * MemoiresApi - axios parameter creator + * @export + */ +export const MemoiresApiAxiosParamCreator = function (configuration?: Configuration) { + return { + /** + * + * @summary 获取所有的记忆 + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1MemoriesGet: async (options: RawAxiosRequestConfig = {}): Promise => { + const localVarPath = `/api/v1/memories`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication ApiKeyAuth required + await setApiKeyToObject(localVarHeaderParameter, "Authorization", configuration) + + + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * + * @summary 删除指定的记忆 + * @param {number} id + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1MemoriesIdDelete: async (id: number, options: RawAxiosRequestConfig = {}): Promise => { + // verify required parameter 'id' is not null or undefined + assertParamExists('apiV1MemoriesIdDelete', 'id', id) + const localVarPath = `/api/v1/memories/{id}` + .replace(`{${"id"}}`, encodeURIComponent(String(id))); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'DELETE', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication ApiKeyAuth required + await setApiKeyToObject(localVarHeaderParameter, "Authorization", configuration) + + + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * + * @summary 删除全部记忆 + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1MemoriesPurgePost: async (options: RawAxiosRequestConfig = {}): Promise => { + const localVarPath = `/api/v1/memories/purge`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication ApiKeyAuth required + await setApiKeyToObject(localVarHeaderParameter, "Authorization", configuration) + + + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + } +}; + +/** + * MemoiresApi - functional programming interface + * @export + */ +export const MemoiresApiFp = function(configuration?: Configuration) { + const localVarAxiosParamCreator = MemoiresApiAxiosParamCreator(configuration) + return { + /** + * + * @summary 获取所有的记忆 + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async apiV1MemoriesGet(options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.apiV1MemoriesGet(options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['MemoiresApi.apiV1MemoriesGet']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, + /** + * + * @summary 删除指定的记忆 + * @param {number} id + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async apiV1MemoriesIdDelete(id: number, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.apiV1MemoriesIdDelete(id, options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['MemoiresApi.apiV1MemoriesIdDelete']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, + /** + * + * @summary 删除全部记忆 + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async apiV1MemoriesPurgePost(options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.apiV1MemoriesPurgePost(options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['MemoiresApi.apiV1MemoriesPurgePost']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, + } +}; + +/** + * MemoiresApi - factory interface + * @export + */ +export const MemoiresApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) { + const localVarFp = MemoiresApiFp(configuration) + return { + /** + * + * @summary 获取所有的记忆 + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1MemoriesGet(options?: any): AxiosPromise { + return localVarFp.apiV1MemoriesGet(options).then((request) => request(axios, basePath)); + }, + /** + * + * @summary 删除指定的记忆 + * @param {number} id + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1MemoriesIdDelete(id: number, options?: any): AxiosPromise { + return localVarFp.apiV1MemoriesIdDelete(id, options).then((request) => request(axios, basePath)); + }, + /** + * + * @summary 删除全部记忆 + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1MemoriesPurgePost(options?: any): AxiosPromise { + return localVarFp.apiV1MemoriesPurgePost(options).then((request) => request(axios, basePath)); + }, + }; +}; + +/** + * MemoiresApi - object-oriented interface + * @export + * @class MemoiresApi + * @extends {BaseAPI} + */ +export class MemoiresApi extends BaseAPI { + /** + * + * @summary 获取所有的记忆 + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof MemoiresApi + */ + public apiV1MemoriesGet(options?: RawAxiosRequestConfig) { + return MemoiresApiFp(this.configuration).apiV1MemoriesGet(options).then((request) => request(this.axios, this.basePath)); + } + + /** + * + * @summary 删除指定的记忆 + * @param {number} id + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof MemoiresApi + */ + public apiV1MemoriesIdDelete(id: number, options?: RawAxiosRequestConfig) { + return MemoiresApiFp(this.configuration).apiV1MemoriesIdDelete(id, options).then((request) => request(this.axios, this.basePath)); + } + + /** + * + * @summary 删除全部记忆 + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof MemoiresApi + */ + public apiV1MemoriesPurgePost(options?: RawAxiosRequestConfig) { + return MemoiresApiFp(this.configuration).apiV1MemoriesPurgePost(options).then((request) => request(this.axios, this.basePath)); + } +} + + + /** * PingApi - axios parameter creator * @export diff --git a/src/pages/assistants/[id]/chats.vue b/src/pages/assistants/[id]/chats.vue index 0bd4d71..e250696 100644 --- a/src/pages/assistants/[id]/chats.vue +++ b/src/pages/assistants/[id]/chats.vue @@ -44,7 +44,7 @@ import { api } from "@/plugins/api"; import { ApiV1AssistantsPost200Response, ApiV1ChatPublicGet200Response, - RagNewInternalSchemaChatCreateRequest, + SchemaChatCreateRequest, } from "@/api"; import router from "@/router"; import { useChatStore } from "../../../stores/chat"; @@ -54,7 +54,7 @@ const assistant: Ref = ref({}); const chats = ref({}); const dialog = ref(false); -const chat: Ref = ref({ +const chat: Ref = ref({ name: "", assistant_id: Number(assistantId), }); diff --git a/src/pages/assistants/[id]/edit.vue b/src/pages/assistants/[id]/edit.vue index ec200b8..a1e022a 100644 --- a/src/pages/assistants/[id]/edit.vue +++ b/src/pages/assistants/[id]/edit.vue @@ -30,6 +30,17 @@ v-model="assistant.data.disable_default_prompt" label="禁用默认 Prompt(默认 Prompt 里面包含了用户信息和助理名称等,禁用可以减少 Token 消耗,但是您可能需要做更多的自定义操作)" > + + + 编辑 @@ -102,7 +113,7 @@ import { ApiV1AssistantsIdToolsGet200Response, ApiV1AssistantsPost200Response, ApiV1ToolsGet200Response, - RagNewInternalSchemaAssistantUpdateRequest, + SchemaAssistantUpdateRequest, } from "@/api"; // @ts-ignore @@ -113,6 +124,8 @@ const assistant: Ref = ref({ description: "", prompt: "", disable_default_prompt: false, + disable_memory: false, + enable_memory_for_assistant_share: false, }, }); @@ -157,7 +170,7 @@ function refresh() { getBindedTools(); } -function bindTool(toolId: Number | undefined) { +function bindTool(toolId: Number | String | undefined) { api.Assistant.apiV1AssistantsIdToolsToolIdPost(assistantId, Number(toolId)) .then(() => { refresh(); @@ -169,11 +182,14 @@ function bindTool(toolId: Number | undefined) { } function updateAssistant() { - const assistantUpdate: RagNewInternalSchemaAssistantUpdateRequest = { + const assistantUpdate: SchemaAssistantUpdateRequest = { description: assistant.value.data?.description, name: assistant.value.data?.name, prompt: assistant.value.data?.prompt, disable_default_prompt: assistant.value.data?.disable_default_prompt, + disable_memory: assistant.value.data?.disable_memory, + enable_memory_for_assistant_share: + assistant.value.data?.enable_memory_for_assistant_share, }; api.Assistant.apiV1AssistantsIdPatch(assistantId, assistantUpdate); } diff --git a/src/pages/tools/validate.vue b/src/pages/tools/validate.vue index 57a8e85..2bcf47e 100644 --- a/src/pages/tools/validate.vue +++ b/src/pages/tools/validate.vue @@ -13,7 +13,7 @@