diff --git a/api/swagger.yaml b/api/swagger.yaml index 5650fe9..ca00ed5 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -247,6 +247,24 @@ definitions: user_id: type: string type: object + entity.ScenePrompt: + properties: + assistant: + $ref: '#/definitions/entity.Assistant' + assistant_id: + type: integer + created_at: + type: string + id: + description: Id schema.EntityId `gorm:"primarykey" json:"id,string"` + type: integer + label: + type: string + prompt: + type: string + updated_at: + type: string + type: object entity.Tool: properties: api_key: @@ -269,8 +287,31 @@ definitions: user_id: type: string type: object + page.PagedResult-entity_ChatMessageList: + properties: + count: + type: integer + data: + items: + $ref: '#/definitions/entity.ChatMessageList' + type: array + page: + description: 当前页码 + type: integer + page_size: + description: 每页大小 + type: integer + total_count: + description: 数据总条数 + type: integer + total_pages: + description: 总页数 + type: integer + type: object page.PagedResult-schema_AssistantPublic: properties: + count: + type: integer data: items: $ref: '#/definitions/schema.AssistantPublic' @@ -495,6 +536,18 @@ definitions: required: - name type: object + schema.CreateAssistantScenePromptRequest: + properties: + label: + maxLength: 20 + type: string + prompt: + maxLength: 512 + type: string + required: + - label + - prompt + type: object schema.CurrentUserResponse: properties: ip: @@ -1081,6 +1134,104 @@ paths: summary: 绑定资料库 tags: - assistant + /api/v1/assistants/{id}/scene_prompts: + get: + consumes: + - application/json + parameters: + - in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/schema.ResponseBody' + - properties: + data: + items: + $ref: '#/definitions/entity.ScenePrompt' + type: array + type: object + "400": + description: Bad Request + schema: + $ref: '#/definitions/schema.ResponseBody' + security: + - ApiKeyAuth: [] + summary: 列出当前助理的场景 Prompt + tags: + - assistant + post: + consumes: + - application/json + parameters: + - in: path + name: id + required: true + type: integer + - description: CreateAssistantScenePromptRequest + in: body + name: CreateAssistantScenePromptRequest + required: true + schema: + $ref: '#/definitions/schema.CreateAssistantScenePromptRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/schema.ResponseBody' + - properties: + data: + $ref: '#/definitions/entity.ScenePrompt' + type: object + "400": + description: Bad Request + schema: + $ref: '#/definitions/schema.ResponseBody' + security: + - ApiKeyAuth: [] + summary: 创建场景 Prompt + tags: + - assistant + /api/v1/assistants/{id}/scene_prompts/{scene_id}: + delete: + consumes: + - application/json + parameters: + - in: path + name: id + required: true + type: integer + - in: path + name: scene_id + required: true + type: integer + produces: + - application/json + responses: + "204": + description: No Content + "404": + description: Not Found + schema: + $ref: '#/definitions/schema.ResponseBody' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/schema.ResponseBody' + security: + - ApiKeyAuth: [] + summary: 删除场景 Prompt + tags: + - assistant /api/v1/assistants/{id}/tools: get: consumes: @@ -1920,6 +2071,48 @@ paths: summary: 添加聊天记录 tags: - chat_message + /api/v1/chats/{id}/messages/paginate: + get: + consumes: + - application/json + description: 获取一个对话的所有聊天记录 + parameters: + - in: path + name: id + required: true + type: integer + - in: query + name: page + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/schema.ResponseBody' + - properties: + data: + $ref: '#/definitions/page.PagedResult-entity_ChatMessageList' + type: object + "400": + description: Bad Request + schema: + $ref: '#/definitions/schema.ResponseBody' + "404": + description: Not Found + schema: + $ref: '#/definitions/schema.ResponseBody' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/schema.ResponseBody' + security: + - ApiKeyAuth: [] + summary: 分页获取聊天记录 + tags: + - chat_message /api/v1/files/download/{hash}: get: consumes: diff --git a/src/api/api.ts b/src/api/api.ts index e1f658c..4da98c7 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -147,6 +147,68 @@ export interface ApiV1AssistantsIdKeysPost200Response { */ 'success'?: boolean; } +/** + * + * @export + * @interface ApiV1AssistantsIdScenePromptsGet200Response + */ +export interface ApiV1AssistantsIdScenePromptsGet200Response { + /** + * + * @type {Array} + * @memberof ApiV1AssistantsIdScenePromptsGet200Response + */ + 'data'?: Array; + /** + * + * @type {string} + * @memberof ApiV1AssistantsIdScenePromptsGet200Response + */ + 'error'?: string; + /** + * + * @type {string} + * @memberof ApiV1AssistantsIdScenePromptsGet200Response + */ + 'message'?: string; + /** + * + * @type {boolean} + * @memberof ApiV1AssistantsIdScenePromptsGet200Response + */ + 'success'?: boolean; +} +/** + * + * @export + * @interface ApiV1AssistantsIdScenePromptsPost200Response + */ +export interface ApiV1AssistantsIdScenePromptsPost200Response { + /** + * + * @type {EntityScenePrompt} + * @memberof ApiV1AssistantsIdScenePromptsPost200Response + */ + 'data'?: EntityScenePrompt; + /** + * + * @type {string} + * @memberof ApiV1AssistantsIdScenePromptsPost200Response + */ + 'error'?: string; + /** + * + * @type {string} + * @memberof ApiV1AssistantsIdScenePromptsPost200Response + */ + 'message'?: string; + /** + * + * @type {boolean} + * @memberof ApiV1AssistantsIdScenePromptsPost200Response + */ + 'success'?: boolean; +} /** * * @export @@ -476,6 +538,37 @@ export interface ApiV1ChatsIdMessagesGet200Response { */ 'success'?: boolean; } +/** + * + * @export + * @interface ApiV1ChatsIdMessagesPaginateGet200Response + */ +export interface ApiV1ChatsIdMessagesPaginateGet200Response { + /** + * + * @type {PagePagedResultEntityChatMessageList} + * @memberof ApiV1ChatsIdMessagesPaginateGet200Response + */ + 'data'?: PagePagedResultEntityChatMessageList; + /** + * + * @type {string} + * @memberof ApiV1ChatsIdMessagesPaginateGet200Response + */ + 'error'?: string; + /** + * + * @type {string} + * @memberof ApiV1ChatsIdMessagesPaginateGet200Response + */ + 'message'?: string; + /** + * + * @type {boolean} + * @memberof ApiV1ChatsIdMessagesPaginateGet200Response + */ + 'success'?: boolean; +} /** * * @export @@ -1383,6 +1476,55 @@ export interface EntityMemory { */ 'user_id'?: string; } +/** + * + * @export + * @interface EntityScenePrompt + */ +export interface EntityScenePrompt { + /** + * + * @type {EntityAssistant} + * @memberof EntityScenePrompt + */ + 'assistant'?: EntityAssistant; + /** + * + * @type {number} + * @memberof EntityScenePrompt + */ + 'assistant_id'?: number; + /** + * + * @type {string} + * @memberof EntityScenePrompt + */ + 'created_at'?: string; + /** + * Id schema.EntityId `gorm:\"primarykey\" json:\"id,string\"` + * @type {number} + * @memberof EntityScenePrompt + */ + 'id'?: number; + /** + * + * @type {string} + * @memberof EntityScenePrompt + */ + 'label'?: string; + /** + * + * @type {string} + * @memberof EntityScenePrompt + */ + 'prompt'?: string; + /** + * + * @type {string} + * @memberof EntityScenePrompt + */ + 'updated_at'?: string; +} /** * * @export @@ -1444,12 +1586,61 @@ export interface EntityTool { */ 'user_id'?: string; } +/** + * + * @export + * @interface PagePagedResultEntityChatMessageList + */ +export interface PagePagedResultEntityChatMessageList { + /** + * + * @type {number} + * @memberof PagePagedResultEntityChatMessageList + */ + 'count'?: number; + /** + * + * @type {Array} + * @memberof PagePagedResultEntityChatMessageList + */ + 'data'?: Array; + /** + * 当前页码 + * @type {number} + * @memberof PagePagedResultEntityChatMessageList + */ + 'page'?: number; + /** + * 每页大小 + * @type {number} + * @memberof PagePagedResultEntityChatMessageList + */ + 'page_size'?: number; + /** + * 数据总条数 + * @type {number} + * @memberof PagePagedResultEntityChatMessageList + */ + 'total_count'?: number; + /** + * 总页数 + * @type {number} + * @memberof PagePagedResultEntityChatMessageList + */ + 'total_pages'?: number; +} /** * * @export * @interface PagePagedResultSchemaAssistantPublic */ export interface PagePagedResultSchemaAssistantPublic { + /** + * + * @type {number} + * @memberof PagePagedResultSchemaAssistantPublic + */ + 'count'?: number; /** * * @type {Array} @@ -1830,6 +2021,25 @@ export interface SchemaChatUpdateRequest { */ 'prompt'?: string; } +/** + * + * @export + * @interface SchemaCreateAssistantScenePromptRequest + */ +export interface SchemaCreateAssistantScenePromptRequest { + /** + * + * @type {string} + * @memberof SchemaCreateAssistantScenePromptRequest + */ + 'label': string; + /** + * + * @type {string} + * @memberof SchemaCreateAssistantScenePromptRequest + */ + 'prompt': string; +} /** * * @export @@ -2781,6 +2991,127 @@ export const AssistantApiAxiosParamCreator = function (configuration?: Configura options: localVarRequestOptions, }; }, + /** + * + * @summary 列出当前助理的场景 Prompt + * @param {number} id + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1AssistantsIdScenePromptsGet: async (id: number, options: RawAxiosRequestConfig = {}): Promise => { + // verify required parameter 'id' is not null or undefined + assertParamExists('apiV1AssistantsIdScenePromptsGet', 'id', id) + const localVarPath = `/api/v1/assistants/{id}/scene_prompts` + .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: '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 创建场景 Prompt + * @param {number} id + * @param {SchemaCreateAssistantScenePromptRequest} createAssistantScenePromptRequest CreateAssistantScenePromptRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1AssistantsIdScenePromptsPost: async (id: number, createAssistantScenePromptRequest: SchemaCreateAssistantScenePromptRequest, options: RawAxiosRequestConfig = {}): Promise => { + // verify required parameter 'id' is not null or undefined + assertParamExists('apiV1AssistantsIdScenePromptsPost', 'id', id) + // verify required parameter 'createAssistantScenePromptRequest' is not null or undefined + assertParamExists('apiV1AssistantsIdScenePromptsPost', 'createAssistantScenePromptRequest', createAssistantScenePromptRequest) + const localVarPath = `/api/v1/assistants/{id}/scene_prompts` + .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: 'POST', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication ApiKeyAuth required + await setApiKeyToObject(localVarHeaderParameter, "Authorization", configuration) + + + + localVarHeaderParameter['Content-Type'] = 'application/json'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(createAssistantScenePromptRequest, localVarRequestOptions, configuration) + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * + * @summary 删除场景 Prompt + * @param {number} id + * @param {number} sceneId + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1AssistantsIdScenePromptsSceneIdDelete: async (id: number, sceneId: number, options: RawAxiosRequestConfig = {}): Promise => { + // verify required parameter 'id' is not null or undefined + assertParamExists('apiV1AssistantsIdScenePromptsSceneIdDelete', 'id', id) + // verify required parameter 'sceneId' is not null or undefined + assertParamExists('apiV1AssistantsIdScenePromptsSceneIdDelete', 'sceneId', sceneId) + const localVarPath = `/api/v1/assistants/{id}/scene_prompts/{scene_id}` + .replace(`{${"id"}}`, encodeURIComponent(String(id))) + .replace(`{${"scene_id"}}`, encodeURIComponent(String(sceneId))); + // 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 获取 Assistant 所绑定的 Tool @@ -3193,6 +3524,47 @@ export const AssistantApiFp = function(configuration?: Configuration) { const localVarOperationServerBasePath = operationServerMap['AssistantApi.apiV1AssistantsIdPut']?.[localVarOperationServerIndex]?.url; return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); }, + /** + * + * @summary 列出当前助理的场景 Prompt + * @param {number} id + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async apiV1AssistantsIdScenePromptsGet(id: number, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.apiV1AssistantsIdScenePromptsGet(id, options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['AssistantApi.apiV1AssistantsIdScenePromptsGet']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, + /** + * + * @summary 创建场景 Prompt + * @param {number} id + * @param {SchemaCreateAssistantScenePromptRequest} createAssistantScenePromptRequest CreateAssistantScenePromptRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async apiV1AssistantsIdScenePromptsPost(id: number, createAssistantScenePromptRequest: SchemaCreateAssistantScenePromptRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.apiV1AssistantsIdScenePromptsPost(id, createAssistantScenePromptRequest, options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['AssistantApi.apiV1AssistantsIdScenePromptsPost']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, + /** + * + * @summary 删除场景 Prompt + * @param {number} id + * @param {number} sceneId + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async apiV1AssistantsIdScenePromptsSceneIdDelete(id: number, sceneId: number, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.apiV1AssistantsIdScenePromptsSceneIdDelete(id, sceneId, options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['AssistantApi.apiV1AssistantsIdScenePromptsSceneIdDelete']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, /** * * @summary 获取 Assistant 所绑定的 Tool @@ -3398,6 +3770,38 @@ export const AssistantApiFactory = function (configuration?: Configuration, base apiV1AssistantsIdPut(id: number, assistantUpdateRequest: SchemaAssistantUpdateRequest, options?: RawAxiosRequestConfig): AxiosPromise { return localVarFp.apiV1AssistantsIdPut(id, assistantUpdateRequest, options).then((request) => request(axios, basePath)); }, + /** + * + * @summary 列出当前助理的场景 Prompt + * @param {number} id + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1AssistantsIdScenePromptsGet(id: number, options?: RawAxiosRequestConfig): AxiosPromise { + return localVarFp.apiV1AssistantsIdScenePromptsGet(id, options).then((request) => request(axios, basePath)); + }, + /** + * + * @summary 创建场景 Prompt + * @param {number} id + * @param {SchemaCreateAssistantScenePromptRequest} createAssistantScenePromptRequest CreateAssistantScenePromptRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1AssistantsIdScenePromptsPost(id: number, createAssistantScenePromptRequest: SchemaCreateAssistantScenePromptRequest, options?: RawAxiosRequestConfig): AxiosPromise { + return localVarFp.apiV1AssistantsIdScenePromptsPost(id, createAssistantScenePromptRequest, options).then((request) => request(axios, basePath)); + }, + /** + * + * @summary 删除场景 Prompt + * @param {number} id + * @param {number} sceneId + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1AssistantsIdScenePromptsSceneIdDelete(id: number, sceneId: number, options?: RawAxiosRequestConfig): AxiosPromise { + return localVarFp.apiV1AssistantsIdScenePromptsSceneIdDelete(id, sceneId, options).then((request) => request(axios, basePath)); + }, /** * * @summary 获取 Assistant 所绑定的 Tool @@ -3602,6 +4006,44 @@ export class AssistantApi extends BaseAPI { return AssistantApiFp(this.configuration).apiV1AssistantsIdPut(id, assistantUpdateRequest, options).then((request) => request(this.axios, this.basePath)); } + /** + * + * @summary 列出当前助理的场景 Prompt + * @param {number} id + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AssistantApi + */ + public apiV1AssistantsIdScenePromptsGet(id: number, options?: RawAxiosRequestConfig) { + return AssistantApiFp(this.configuration).apiV1AssistantsIdScenePromptsGet(id, options).then((request) => request(this.axios, this.basePath)); + } + + /** + * + * @summary 创建场景 Prompt + * @param {number} id + * @param {SchemaCreateAssistantScenePromptRequest} createAssistantScenePromptRequest CreateAssistantScenePromptRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AssistantApi + */ + public apiV1AssistantsIdScenePromptsPost(id: number, createAssistantScenePromptRequest: SchemaCreateAssistantScenePromptRequest, options?: RawAxiosRequestConfig) { + return AssistantApiFp(this.configuration).apiV1AssistantsIdScenePromptsPost(id, createAssistantScenePromptRequest, options).then((request) => request(this.axios, this.basePath)); + } + + /** + * + * @summary 删除场景 Prompt + * @param {number} id + * @param {number} sceneId + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AssistantApi + */ + public apiV1AssistantsIdScenePromptsSceneIdDelete(id: number, sceneId: number, options?: RawAxiosRequestConfig) { + return AssistantApiFp(this.configuration).apiV1AssistantsIdScenePromptsSceneIdDelete(id, sceneId, options).then((request) => request(this.axios, this.basePath)); + } + /** * * @summary 获取 Assistant 所绑定的 Tool @@ -4298,6 +4740,48 @@ export const ChatMessageApiAxiosParamCreator = function (configuration?: Configu + 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 {number} [page] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1ChatsIdMessagesPaginateGet: async (id: number, page?: number, options: RawAxiosRequestConfig = {}): Promise => { + // verify required parameter 'id' is not null or undefined + assertParamExists('apiV1ChatsIdMessagesPaginateGet', 'id', id) + const localVarPath = `/api/v1/chats/{id}/messages/paginate` + .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: 'GET', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication ApiKeyAuth required + await setApiKeyToObject(localVarHeaderParameter, "Authorization", configuration) + + if (page !== undefined) { + localVarQueryParameter['page'] = page; + } + + + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; @@ -4439,6 +4923,20 @@ export const ChatMessageApiFp = function(configuration?: Configuration) { const localVarOperationServerBasePath = operationServerMap['ChatMessageApi.apiV1ChatsIdMessagesGet']?.[localVarOperationServerIndex]?.url; return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); }, + /** + * 获取一个对话的所有聊天记录 + * @summary 分页获取聊天记录 + * @param {number} id + * @param {number} [page] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async apiV1ChatsIdMessagesPaginateGet(id: number, page?: number, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.apiV1ChatsIdMessagesPaginateGet(id, page, options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['ChatMessageApi.apiV1ChatsIdMessagesPaginateGet']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, /** * 添加一条消息 * @summary 添加聊天记录 @@ -4508,6 +5006,17 @@ export const ChatMessageApiFactory = function (configuration?: Configuration, ba apiV1ChatsIdMessagesGet(id: number, options?: RawAxiosRequestConfig): AxiosPromise { return localVarFp.apiV1ChatsIdMessagesGet(id, options).then((request) => request(axios, basePath)); }, + /** + * 获取一个对话的所有聊天记录 + * @summary 分页获取聊天记录 + * @param {number} id + * @param {number} [page] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiV1ChatsIdMessagesPaginateGet(id: number, page?: number, options?: RawAxiosRequestConfig): AxiosPromise { + return localVarFp.apiV1ChatsIdMessagesPaginateGet(id, page, options).then((request) => request(axios, basePath)); + }, /** * 添加一条消息 * @summary 添加聊天记录 @@ -4577,6 +5086,19 @@ export class ChatMessageApi extends BaseAPI { return ChatMessageApiFp(this.configuration).apiV1ChatsIdMessagesGet(id, options).then((request) => request(this.axios, this.basePath)); } + /** + * 获取一个对话的所有聊天记录 + * @summary 分页获取聊天记录 + * @param {number} id + * @param {number} [page] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ChatMessageApi + */ + public apiV1ChatsIdMessagesPaginateGet(id: number, page?: number, options?: RawAxiosRequestConfig) { + return ChatMessageApiFp(this.configuration).apiV1ChatsIdMessagesPaginateGet(id, page, options).then((request) => request(this.axios, this.basePath)); + } + /** * 添加一条消息 * @summary 添加聊天记录 diff --git a/src/components/settings/AssistantSettings.vue b/src/components/settings/AssistantSettings.vue index 7df6ef9..5955039 100644 --- a/src/components/settings/AssistantSettings.vue +++ b/src/components/settings/AssistantSettings.vue @@ -168,6 +168,82 @@ + +
+
+
+
+ 场景提示词 + + +
+ Amber 可以根据不同的上下文场景来自动附加系统提示词 +
+
+
+
+ + 新场景提示词 + +
+
+
+ + + + +
+ 创建 +
+
+
+
+ + + +
+
{{ c.prompt }}
+
+ + +
删除后,这条规则将不再生效
+
+
+
+
+
+
+
+
+
@@ -186,7 +262,8 @@ 我们的 API 端点是:{{ config.backend - }}/api/openai-compatible/v1 。密钥为下方的 API Key,OpenAI 格式不支持智能上下文(不支持近乎无限的上下文) + }}/api/openai-compatible/v1 。密钥为下方的 API Key,OpenAI + 格式不支持智能上下文(不支持近乎无限的上下文)
@@ -202,12 +279,20 @@ 等做一个请求限制),来防止 API Key 滥用。
当然,如果您在自己的私有应用中使用,可以忽略此建议。 +
+ !! 注意: Amber Assistant Public API 不需要在前面加 sk- !!
- 我们更新了计费系统,在使用此功能之前,请前往 UserLand 来添加余额。我们正在且长期会处于测试阶段,不会对您发起真实付费(也就是说完全免费!) + 我们更新了计费系统,在使用此功能之前,请前往 + UserLand + 来添加余额。我们正在且长期会处于测试阶段,不会对您发起真实付费(也就是说完全免费!) @@ -291,6 +376,7 @@ import { EntityAssistantKey, EntityAssistantTool, EntityLibrary, + EntityScenePrompt, EntityTool, } from "@/api"; import { useIsMobile } from "@/utils/composables"; @@ -309,6 +395,13 @@ const assistants: Ref = ref([]); const librarySelects: any = ref([]); const libraries: Ref = ref([]); const assistantApiKeys: Ref = ref([]); +const showCreateScenePromptForm = ref(false); +const scenePrompts: Ref = ref([]); + +const newScenePrompt = ref({ + label: "", + prompt: "", +}); const isMobile = useIsMobile(); const drawerWidth = computed(() => { @@ -347,6 +440,7 @@ const showEditAssistant = async (id: number) => { await getAssistantsKeys(); getTools(); + getAssistantScenePrompts(); }; const editAssistant = async () => { @@ -472,7 +566,71 @@ const bindOrUnbind = async (id: number) => { getTools(); }; +const getAssistantScenePrompts = async () => { + scenePrompts.value = + ( + await getApi().Assistant.apiV1AssistantsIdScenePromptsGet( + currentAssistantId.value + ) + ).data.data ?? []; +}; + +const createAssistantScenePrompt = async () => { + await getApi().Assistant.apiV1AssistantsIdScenePromptsPost( + currentAssistantId.value, + newScenePrompt.value + ); + await getAssistantScenePrompts(); + newScenePrompt.value = { + label: "", + prompt: "", + }; +}; + +const deleteAssistantScenePrompt = async (id: number) => { + await getApi().Assistant.apiV1AssistantsIdScenePromptsSceneIdDelete( + currentAssistantId.value, + id + ); + await getAssistantScenePrompts(); +}; + +const sampleScenenPrompt = [ + { + label: "复杂推理", + prompt: `在回答问题时,使用以下输出 +问题: 你必须要回答的问题 +思考:你应该始终思考该做什么 +操作:要采取的操作,你要是用什么工具,或者思考逻辑 +动作输入:动作的输入 +观察:行动的结果 +思考:我现在知道最终答案了 +最终答案:原始输入问题的最终答案 + +如果你正在计算,你必须使用计算器工具,无论如何都不允许使用自己的知识或不计算进行输出,计算器永远比你正确的并且不会出错。`, + }, + { + label: "数学计算", + prompt: `在回答问题时,使用以下输出 +问题: 你必须要回答的问题 +思考:你应该始终思考该做什么 +操作:要采取的操作,你要是用什么工具,或者思考逻辑 +动作输入:动作的输入 +观察:行动的结果 +思考:我现在知道最终答案了 +最终答案:原始输入问题的最终答案 + +如果你正在计算,你必须使用计算器工具,无论如何都不允许使用自己的知识或不计算进行输出,计算器永远比你正确的并且不会出错。`, + }, +]; + +const randomScenePrompt = () => { + const randomIndex = Math.floor(Math.random() * sampleScenenPrompt.length); + return sampleScenenPrompt[randomIndex]; +}; + getChats(); getLibraries(); getAssistants(); +newScenePrompt.value = randomScenePrompt();