This commit is contained in:
ivamp 2024-08-16 21:35:43 +08:00
parent 96a3f67f43
commit 456b6281af
3 changed files with 415 additions and 50 deletions

View File

@ -8,8 +8,7 @@ definitions:
disable_default_prompt:
type: boolean
id:
example: "0"
type: string
type: integer
name:
type: string
prompt:
@ -22,13 +21,11 @@ definitions:
rag-new_internal_entity.AssistantShare:
properties:
assistant_id:
example: "0"
type: string
type: integer
created_at:
type: string
id:
example: "0"
type: string
type: integer
token:
type: string
updated_at:
@ -41,8 +38,7 @@ definitions:
created_at:
type: string
id:
example: "0"
type: string
type: integer
tool_id:
type: integer
updated_at:
@ -53,26 +49,22 @@ definitions:
assistant:
$ref: '#/definitions/rag-new_internal_entity.Assistant'
assistant_id:
example: "0"
type: string
type: integer
created_at:
type: string
id:
example: "0"
type: string
type: integer
tool:
$ref: '#/definitions/rag-new_internal_entity.Tool'
tool_id:
example: "0"
type: string
type: integer
updated_at:
type: string
type: object
rag-new_internal_entity.Chat:
properties:
assistant_id:
example: "0"
type: string
type: integer
created_at:
type: string
expired_at:
@ -80,8 +72,7 @@ definitions:
guest_id:
type: string
id:
example: "0"
type: string
type: integer
name:
type: string
owner:
@ -102,8 +93,7 @@ definitions:
created_at:
type: string
id:
example: "0"
type: string
type: integer
prompt_tokens:
type: integer
role:
@ -126,8 +116,7 @@ definitions:
discovery_url:
type: string
id:
example: "0"
type: string
type: integer
name:
type: string
updated_at:
@ -188,8 +177,7 @@ definitions:
rag-new_internal_schema.ChatCreateRequest:
properties:
assistant_id:
example: "0"
type: string
type: integer
name:
maxLength: 255
type: string
@ -254,6 +242,65 @@ definitions:
- assistant_token
- guest_id
type: object
rag-new_internal_schema.OpenAIChatCompletionRequest:
properties:
max_tokens:
description: Optional
type: integer
messages:
description: Required
items:
$ref: '#/definitions/rag-new_internal_schema.OpenAIChatCompletionRequestMessage'
type: array
model:
description: Required
type: string
"n":
description: Optional
type: integer
stream:
description: Optional
type: boolean
temperature:
description: Optional
type: number
top_p:
description: Optional
type: number
type: object
rag-new_internal_schema.OpenAIChatCompletionRequestMessage:
properties:
content:
description: Required
type: string
role:
description: Required
type: string
type: object
rag-new_internal_schema.OpenAIChatCompletionResponse:
properties:
choices:
items:
$ref: '#/definitions/rag-new_internal_schema.OpenAIChatCompletionResponseChoice'
type: array
created:
type: integer
id:
type: string
model:
type: string
object:
type: string
usage:
$ref: '#/definitions/rag-new_internal_schema.TokenUsage'
type: object
rag-new_internal_schema.OpenAIChatCompletionResponseChoice:
properties:
index:
type: integer
message:
$ref: '#/definitions/rag-new_internal_schema.OpenAIChatCompletionRequestMessage'
type: object
rag-new_internal_schema.ResponseBody:
properties:
data: {}
@ -264,6 +311,15 @@ definitions:
success:
type: boolean
type: object
rag-new_internal_schema.TokenUsage:
properties:
completion_tokens:
type: integer
prompt_tokens:
type: integer
total_tokens:
type: integer
type: object
rag-new_internal_schema.ToolCreateRequest:
properties:
api_key:
@ -359,6 +415,43 @@ info:
title: Leaflow Amber
version: "1.0"
paths:
/api/openai-compatible/v1/chat/completions:
post:
consumes:
- application/json
description: 兼容 OpenAI Chat Completion 接口,认证需要使用 Assistant Share Token
parameters:
- description: Chat
in: body
name: chat
required: true
schema:
$ref: '#/definitions/rag-new_internal_schema.OpenAIChatCompletionRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/rag-new_internal_schema.ResponseBody'
- properties:
data:
$ref: '#/definitions/rag-new_internal_schema.OpenAIChatCompletionResponse'
type: object
"400":
description: Bad Request
schema:
$ref: '#/definitions/rag-new_internal_schema.ResponseBody'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/rag-new_internal_schema.ResponseBody'
security:
- ApiKeyAuth: []
summary: OpenAI Chat Completion
tags:
- chat
/api/v1/assistants:
get:
consumes:

View File

@ -333,6 +333,37 @@ export interface ApiV1ChatPublicPost200Response {
*/
'success'?: boolean;
}
/**
*
* @export
* @interface ApiV1OpenaiCompatibleCompletionPost200Response
*/
export interface ApiV1OpenaiCompatibleCompletionPost200Response {
/**
*
* @type {RagNewInternalSchemaOpenAIChatCompletionResponse}
* @memberof ApiV1OpenaiCompatibleCompletionPost200Response
*/
'data'?: RagNewInternalSchemaOpenAIChatCompletionResponse;
/**
*
* @type {string}
* @memberof ApiV1OpenaiCompatibleCompletionPost200Response
*/
'error'?: string;
/**
*
* @type {string}
* @memberof ApiV1OpenaiCompatibleCompletionPost200Response
*/
'message'?: string;
/**
*
* @type {boolean}
* @memberof ApiV1OpenaiCompatibleCompletionPost200Response
*/
'success'?: boolean;
}
/**
*
* @export
@ -452,10 +483,10 @@ export interface RagNewInternalEntityAssistant {
'disable_default_prompt'?: boolean;
/**
*
* @type {string}
* @type {number}
* @memberof RagNewInternalEntityAssistant
*/
'id'?: string;
'id'?: number;
/**
*
* @type {string}
@ -489,10 +520,10 @@ export interface RagNewInternalEntityAssistant {
export interface RagNewInternalEntityAssistantShare {
/**
*
* @type {string}
* @type {number}
* @memberof RagNewInternalEntityAssistantShare
*/
'assistant_id'?: string;
'assistant_id'?: number;
/**
*
* @type {string}
@ -501,10 +532,10 @@ export interface RagNewInternalEntityAssistantShare {
'created_at'?: string;
/**
*
* @type {string}
* @type {number}
* @memberof RagNewInternalEntityAssistantShare
*/
'id'?: string;
'id'?: number;
/**
*
* @type {string}
@ -538,10 +569,10 @@ export interface RagNewInternalEntityAssistantTool {
'created_at'?: string;
/**
*
* @type {string}
* @type {number}
* @memberof RagNewInternalEntityAssistantTool
*/
'id'?: string;
'id'?: number;
/**
*
* @type {number}
@ -569,10 +600,10 @@ export interface RagNewInternalEntityAssistantToolType {
'assistant'?: RagNewInternalEntityAssistant;
/**
*
* @type {string}
* @type {number}
* @memberof RagNewInternalEntityAssistantToolType
*/
'assistant_id'?: string;
'assistant_id'?: number;
/**
*
* @type {string}
@ -581,10 +612,10 @@ export interface RagNewInternalEntityAssistantToolType {
'created_at'?: string;
/**
*
* @type {string}
* @type {number}
* @memberof RagNewInternalEntityAssistantToolType
*/
'id'?: string;
'id'?: number;
/**
*
* @type {RagNewInternalEntityTool}
@ -593,10 +624,10 @@ export interface RagNewInternalEntityAssistantToolType {
'tool'?: RagNewInternalEntityTool;
/**
*
* @type {string}
* @type {number}
* @memberof RagNewInternalEntityAssistantToolType
*/
'tool_id'?: string;
'tool_id'?: number;
/**
*
* @type {string}
@ -612,10 +643,10 @@ export interface RagNewInternalEntityAssistantToolType {
export interface RagNewInternalEntityChat {
/**
*
* @type {string}
* @type {number}
* @memberof RagNewInternalEntityChat
*/
'assistant_id'?: string;
'assistant_id'?: number;
/**
*
* @type {string}
@ -636,10 +667,10 @@ export interface RagNewInternalEntityChat {
'guest_id'?: string;
/**
*
* @type {string}
* @type {number}
* @memberof RagNewInternalEntityChat
*/
'id'?: string;
'id'?: number;
/**
*
* @type {string}
@ -697,10 +728,10 @@ export interface RagNewInternalEntityChatMessage {
'created_at'?: string;
/**
*
* @type {string}
* @type {number}
* @memberof RagNewInternalEntityChatMessage
*/
'id'?: string;
'id'?: number;
/**
*
* @type {number}
@ -764,10 +795,10 @@ export interface RagNewInternalEntityTool {
'discovery_url'?: string;
/**
*
* @type {string}
* @type {number}
* @memberof RagNewInternalEntityTool
*/
'id'?: string;
'id'?: number;
/**
*
* @type {string}
@ -882,10 +913,10 @@ export interface RagNewInternalSchemaAssistantUpdateRequest {
export interface RagNewInternalSchemaChatCreateRequest {
/**
*
* @type {string}
* @type {number}
* @memberof RagNewInternalSchemaChatCreateRequest
*/
'assistant_id': string;
'assistant_id': number;
/**
*
* @type {string}
@ -1013,6 +1044,174 @@ export interface RagNewInternalSchemaGetPublicChatMessageRequest {
*/
'guest_id': string;
}
/**
*
* @export
* @interface RagNewInternalSchemaOpenAIChatCompletionRequest
*/
export interface RagNewInternalSchemaOpenAIChatCompletionRequest {
/**
* Optional
* @type {number}
* @memberof RagNewInternalSchemaOpenAIChatCompletionRequest
*/
'max_tokens'?: number;
/**
* Required
* @type {Array<RagNewInternalSchemaOpenAIChatCompletionRequestMessage>}
* @memberof RagNewInternalSchemaOpenAIChatCompletionRequest
*/
'messages'?: Array<RagNewInternalSchemaOpenAIChatCompletionRequestMessage>;
/**
* Required
* @type {string}
* @memberof RagNewInternalSchemaOpenAIChatCompletionRequest
*/
'model'?: string;
/**
* Optional
* @type {number}
* @memberof RagNewInternalSchemaOpenAIChatCompletionRequest
*/
'n'?: number;
/**
* Optional
* @type {boolean}
* @memberof RagNewInternalSchemaOpenAIChatCompletionRequest
*/
'stream'?: boolean;
/**
* Optional
* @type {number}
* @memberof RagNewInternalSchemaOpenAIChatCompletionRequest
*/
'temperature'?: number;
/**
* Optional
* @type {number}
* @memberof RagNewInternalSchemaOpenAIChatCompletionRequest
*/
'top_p'?: number;
}
/**
*
* @export
* @interface RagNewInternalSchemaOpenAIChatCompletionRequestMessage
*/
export interface RagNewInternalSchemaOpenAIChatCompletionRequestMessage {
/**
* Required
* @type {string}
* @memberof RagNewInternalSchemaOpenAIChatCompletionRequestMessage
*/
'content'?: string;
/**
* Optional
* @type {string}
* @memberof RagNewInternalSchemaOpenAIChatCompletionRequestMessage
*/
'name'?: string;
/**
* Required
* @type {string}
* @memberof RagNewInternalSchemaOpenAIChatCompletionRequestMessage
*/
'role'?: string;
}
/**
*
* @export
* @interface RagNewInternalSchemaOpenAIChatCompletionResponse
*/
export interface RagNewInternalSchemaOpenAIChatCompletionResponse {
/**
*
* @type {Array<RagNewInternalSchemaOpenAIChatCompletionResponseChoicesInner>}
* @memberof RagNewInternalSchemaOpenAIChatCompletionResponse
*/
'choices'?: Array<RagNewInternalSchemaOpenAIChatCompletionResponseChoicesInner>;
/**
*
* @type {number}
* @memberof RagNewInternalSchemaOpenAIChatCompletionResponse
*/
'created'?: number;
/**
*
* @type {string}
* @memberof RagNewInternalSchemaOpenAIChatCompletionResponse
*/
'id'?: string;
/**
*
* @type {string}
* @memberof RagNewInternalSchemaOpenAIChatCompletionResponse
*/
'object'?: string;
/**
*
* @type {RagNewInternalSchemaOpenAIChatCompletionResponseUsage}
* @memberof RagNewInternalSchemaOpenAIChatCompletionResponse
*/
'usage'?: RagNewInternalSchemaOpenAIChatCompletionResponseUsage;
}
/**
*
* @export
* @interface RagNewInternalSchemaOpenAIChatCompletionResponseChoicesInner
*/
export interface RagNewInternalSchemaOpenAIChatCompletionResponseChoicesInner {
/**
*
* @type {string}
* @memberof RagNewInternalSchemaOpenAIChatCompletionResponseChoicesInner
*/
'finish_reason'?: string;
/**
*
* @type {number}
* @memberof RagNewInternalSchemaOpenAIChatCompletionResponseChoicesInner
*/
'index'?: number;
/**
*
* @type {RagNewInternalSchemaOpenAIChatCompletionResponseChoicesInnerMessage}
* @memberof RagNewInternalSchemaOpenAIChatCompletionResponseChoicesInner
*/
'message'?: RagNewInternalSchemaOpenAIChatCompletionResponseChoicesInnerMessage;
}
/**
*
* @export
* @interface RagNewInternalSchemaOpenAIChatCompletionResponseChoicesInnerMessage
*/
export interface RagNewInternalSchemaOpenAIChatCompletionResponseChoicesInnerMessage {
/**
*
* @type {string}
* @memberof RagNewInternalSchemaOpenAIChatCompletionResponseChoicesInnerMessage
*/
'content'?: string;
/**
*
* @type {string}
* @memberof RagNewInternalSchemaOpenAIChatCompletionResponseChoicesInnerMessage
*/
'role'?: string;
}
/**
*
* @export
* @interface RagNewInternalSchemaOpenAIChatCompletionResponseUsage
*/
export interface RagNewInternalSchemaOpenAIChatCompletionResponseUsage {
/**
*
* @type {number}
* @memberof RagNewInternalSchemaOpenAIChatCompletionResponseUsage
*/
'total_tokens'?: number;
}
/**
*
* @export
@ -2214,6 +2413,45 @@ export const ChatApiAxiosParamCreator = function (configuration?: 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(chat, localVarRequestOptions, configuration)
return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
* OpenAI Chat Completion 使 Assistant Share Token
* @summary OpenAI Chat Completion
* @param {RagNewInternalSchemaOpenAIChatCompletionRequest} chat Chat
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
apiV1OpenaiCompatibleCompletionPost: async (chat: RagNewInternalSchemaOpenAIChatCompletionRequest, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'chat' is not null or undefined
assertParamExists('apiV1OpenaiCompatibleCompletionPost', 'chat', chat)
const localVarPath = `/api/v1/openai-compatible/completion`;
// 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);
@ -2275,6 +2513,19 @@ export const ChatApiFp = function(configuration?: Configuration) {
const localVarOperationServerBasePath = operationServerMap['ChatApi.apiV1ChatsPost']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
* OpenAI Chat Completion 使 Assistant Share Token
* @summary OpenAI Chat Completion
* @param {RagNewInternalSchemaOpenAIChatCompletionRequest} chat Chat
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiV1OpenaiCompatibleCompletionPost(chat: RagNewInternalSchemaOpenAIChatCompletionRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ApiV1OpenaiCompatibleCompletionPost200Response>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.apiV1OpenaiCompatibleCompletionPost(chat, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['ChatApi.apiV1OpenaiCompatibleCompletionPost']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
}
};
@ -2315,6 +2566,16 @@ export const ChatApiFactory = function (configuration?: Configuration, basePath?
apiV1ChatsPost(chat: RagNewInternalSchemaChatCreateRequest, options?: any): AxiosPromise<ApiV1ChatPublicPost200Response> {
return localVarFp.apiV1ChatsPost(chat, options).then((request) => request(axios, basePath));
},
/**
* OpenAI Chat Completion 使 Assistant Share Token
* @summary OpenAI Chat Completion
* @param {RagNewInternalSchemaOpenAIChatCompletionRequest} chat Chat
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
apiV1OpenaiCompatibleCompletionPost(chat: RagNewInternalSchemaOpenAIChatCompletionRequest, options?: any): AxiosPromise<ApiV1OpenaiCompatibleCompletionPost200Response> {
return localVarFp.apiV1OpenaiCompatibleCompletionPost(chat, options).then((request) => request(axios, basePath));
},
};
};
@ -2360,6 +2621,18 @@ export class ChatApi extends BaseAPI {
public apiV1ChatsPost(chat: RagNewInternalSchemaChatCreateRequest, options?: RawAxiosRequestConfig) {
return ChatApiFp(this.configuration).apiV1ChatsPost(chat, options).then((request) => request(this.axios, this.basePath));
}
/**
* OpenAI Chat Completion 使 Assistant Share Token
* @summary OpenAI Chat Completion
* @param {RagNewInternalSchemaOpenAIChatCompletionRequest} chat Chat
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof ChatApi
*/
public apiV1OpenaiCompatibleCompletionPost(chat: RagNewInternalSchemaOpenAIChatCompletionRequest, options?: RawAxiosRequestConfig) {
return ChatApiFp(this.configuration).apiV1OpenaiCompatibleCompletionPost(chat, options).then((request) => request(this.axios, this.basePath));
}
}

View File

@ -39,7 +39,6 @@
</template>
<script setup lang="ts">
import Big from "big.js";
import { ref } from "vue";
import { api } from "@/plugins/api";
import {
@ -57,7 +56,7 @@ const chats = ref<ApiV1ChatPublicGet200Response>({});
const dialog = ref(false);
const chat: Ref<RagNewInternalSchemaChatCreateRequest> = ref({
name: "",
assistant_id: Big(assistantId).toString(),
assistant_id: Number(assistantId),
});
const chatStore = useChatStore();