增加 图片上传

This commit is contained in:
ivamp 2024-08-25 06:15:18 +08:00
parent 9bfd461105
commit 43264db8f5
3 changed files with 257 additions and 40 deletions

View File

@ -927,6 +927,65 @@ paths:
summary: 清空公开对话的聊天记录
tags:
- chat_public
/api/v1/chat_public/{chat_id}/images:
post:
consumes:
- application/json
description: 将一个图片添加到聊天记录中
parameters:
- in: path
name: chat_id
required: true
type: integer
- in: formData
name: assistant_token
required: true
type: string
- in: formData
name: guest_id
required: true
type: string
- description: 图片
in: formData
name: image
required: true
type: file
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/rag-new_internal_schema.ResponseBody'
- properties:
data:
$ref: '#/definitions/rag-new_internal_schema.ChatMessageResponse'
type: object
"400":
description: Bad Request
schema:
$ref: '#/definitions/rag-new_internal_schema.ResponseBody'
"404":
description: Not Found
schema:
$ref: '#/definitions/rag-new_internal_schema.ResponseBody'
"409":
description: Conflict
schema:
allOf:
- $ref: '#/definitions/rag-new_internal_schema.ResponseBody'
- properties:
data:
$ref: '#/definitions/rag-new_internal_schema.ChatMessageResponse'
type: object
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/rag-new_internal_schema.ResponseBody'
summary: 添加图片
tags:
- chat_public
/api/v1/chat_public/{chat_id}/messages:
get:
consumes:

View File

@ -209,6 +209,62 @@ export interface ApiV1AssistantsPost200Response {
*/
'success'?: boolean;
}
/**
*
* @export
* @interface ApiV1ChatPublicChatIdImagesPost200Response
*/
export interface ApiV1ChatPublicChatIdImagesPost200Response {
/**
*
* @type {RagNewInternalSchemaChatMessageResponse}
* @memberof ApiV1ChatPublicChatIdImagesPost200Response
*/
'data'?: RagNewInternalSchemaChatMessageResponse;
/**
*
* @type {string}
* @memberof ApiV1ChatPublicChatIdImagesPost200Response
*/
'error'?: string;
/**
*
* @type {string}
* @memberof ApiV1ChatPublicChatIdImagesPost200Response
*/
'message'?: string;
/**
*
* @type {boolean}
* @memberof ApiV1ChatPublicChatIdImagesPost200Response
*/
'success'?: boolean;
}
/**
*
* @export
* @interface ApiV1ChatPublicChatIdImagesPostRequest
*/
export interface ApiV1ChatPublicChatIdImagesPostRequest {
/**
*
* @type {string}
* @memberof ApiV1ChatPublicChatIdImagesPostRequest
*/
'assistant_token': string;
/**
*
* @type {string}
* @memberof ApiV1ChatPublicChatIdImagesPostRequest
*/
'guest_id': string;
/**
*
* @type {File}
* @memberof ApiV1ChatPublicChatIdImagesPostRequest
*/
'image': File;
}
/**
*
* @export
@ -240,37 +296,6 @@ export interface ApiV1ChatPublicChatIdMessagesGet200Response {
*/
'success'?: boolean;
}
/**
*
* @export
* @interface ApiV1ChatPublicChatIdMessagesPost200Response
*/
export interface ApiV1ChatPublicChatIdMessagesPost200Response {
/**
*
* @type {RagNewInternalSchemaChatMessageResponse}
* @memberof ApiV1ChatPublicChatIdMessagesPost200Response
*/
'data'?: RagNewInternalSchemaChatMessageResponse;
/**
*
* @type {string}
* @memberof ApiV1ChatPublicChatIdMessagesPost200Response
*/
'error'?: string;
/**
*
* @type {string}
* @memberof ApiV1ChatPublicChatIdMessagesPost200Response
*/
'message'?: string;
/**
*
* @type {boolean}
* @memberof ApiV1ChatPublicChatIdMessagesPost200Response
*/
'success'?: boolean;
}
/**
*
* @export
@ -2891,7 +2916,7 @@ export const ChatMessageApiFp = function(configuration?: Configuration) {
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiV1ChatsIdImagesPost(id: number, apiV1ChatsIdImagesPostRequest: ApiV1ChatsIdImagesPostRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ApiV1ChatPublicChatIdMessagesPost200Response>> {
async apiV1ChatsIdImagesPost(id: number, apiV1ChatsIdImagesPostRequest: ApiV1ChatsIdImagesPostRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ApiV1ChatPublicChatIdImagesPost200Response>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.apiV1ChatsIdImagesPost(id, apiV1ChatsIdImagesPostRequest, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['ChatMessageApi.apiV1ChatsIdImagesPost']?.[localVarOperationServerIndex]?.url;
@ -2918,7 +2943,7 @@ export const ChatMessageApiFp = function(configuration?: Configuration) {
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiV1ChatsIdMessagesPost(id: number, message: RagNewInternalSchemaChatMessageAddRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ApiV1ChatPublicChatIdMessagesPost200Response>> {
async apiV1ChatsIdMessagesPost(id: number, message: RagNewInternalSchemaChatMessageAddRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ApiV1ChatPublicChatIdImagesPost200Response>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.apiV1ChatsIdMessagesPost(id, message, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['ChatMessageApi.apiV1ChatsIdMessagesPost']?.[localVarOperationServerIndex]?.url;
@ -2932,7 +2957,7 @@ export const ChatMessageApiFp = function(configuration?: Configuration) {
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiV1StreamStreamIdGet(streamId: string, xUserIP?: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ApiV1ChatPublicChatIdMessagesPost200Response>> {
async apiV1StreamStreamIdGet(streamId: string, xUserIP?: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ApiV1ChatPublicChatIdImagesPost200Response>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.apiV1StreamStreamIdGet(streamId, xUserIP, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['ChatMessageApi.apiV1StreamStreamIdGet']?.[localVarOperationServerIndex]?.url;
@ -2966,7 +2991,7 @@ export const ChatMessageApiFactory = function (configuration?: Configuration, ba
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
apiV1ChatsIdImagesPost(id: number, apiV1ChatsIdImagesPostRequest: ApiV1ChatsIdImagesPostRequest, options?: any): AxiosPromise<ApiV1ChatPublicChatIdMessagesPost200Response> {
apiV1ChatsIdImagesPost(id: number, apiV1ChatsIdImagesPostRequest: ApiV1ChatsIdImagesPostRequest, options?: any): AxiosPromise<ApiV1ChatPublicChatIdImagesPost200Response> {
return localVarFp.apiV1ChatsIdImagesPost(id, apiV1ChatsIdImagesPostRequest, options).then((request) => request(axios, basePath));
},
/**
@ -2987,7 +3012,7 @@ export const ChatMessageApiFactory = function (configuration?: Configuration, ba
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
apiV1ChatsIdMessagesPost(id: number, message: RagNewInternalSchemaChatMessageAddRequest, options?: any): AxiosPromise<ApiV1ChatPublicChatIdMessagesPost200Response> {
apiV1ChatsIdMessagesPost(id: number, message: RagNewInternalSchemaChatMessageAddRequest, options?: any): AxiosPromise<ApiV1ChatPublicChatIdImagesPost200Response> {
return localVarFp.apiV1ChatsIdMessagesPost(id, message, options).then((request) => request(axios, basePath));
},
/**
@ -2998,7 +3023,7 @@ export const ChatMessageApiFactory = function (configuration?: Configuration, ba
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
apiV1StreamStreamIdGet(streamId: string, xUserIP?: string, options?: any): AxiosPromise<ApiV1ChatPublicChatIdMessagesPost200Response> {
apiV1StreamStreamIdGet(streamId: string, xUserIP?: string, options?: any): AxiosPromise<ApiV1ChatPublicChatIdImagesPost200Response> {
return localVarFp.apiV1StreamStreamIdGet(streamId, xUserIP, options).then((request) => request(axios, basePath));
},
};
@ -3123,6 +3148,46 @@ export const ChatPublicApiAxiosParamCreator = function (configuration?: Configur
options: localVarRequestOptions,
};
},
/**
*
* @summary
* @param {number} chatId
* @param {ApiV1ChatPublicChatIdImagesPostRequest} apiV1ChatPublicChatIdImagesPostRequest
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
apiV1ChatPublicChatIdImagesPost: async (chatId: number, apiV1ChatPublicChatIdImagesPostRequest: ApiV1ChatPublicChatIdImagesPostRequest, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'chatId' is not null or undefined
assertParamExists('apiV1ChatPublicChatIdImagesPost', 'chatId', chatId)
// verify required parameter 'apiV1ChatPublicChatIdImagesPostRequest' is not null or undefined
assertParamExists('apiV1ChatPublicChatIdImagesPost', 'apiV1ChatPublicChatIdImagesPostRequest', apiV1ChatPublicChatIdImagesPostRequest)
const localVarPath = `/api/v1/chat_public/{chat_id}/images`
.replace(`{${"chat_id"}}`, encodeURIComponent(String(chatId)));
// 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;
localVarHeaderParameter['Content-Type'] = 'application/json';
setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
localVarRequestOptions.data = serializeDataIfNeeded(apiV1ChatPublicChatIdImagesPostRequest, localVarRequestOptions, configuration)
return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @summary
@ -3307,6 +3372,20 @@ export const ChatPublicApiFp = function(configuration?: Configuration) {
const localVarOperationServerBasePath = operationServerMap['ChatPublicApi.apiV1ChatPublicChatIdClearPost']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
*
* @summary
* @param {number} chatId
* @param {ApiV1ChatPublicChatIdImagesPostRequest} apiV1ChatPublicChatIdImagesPostRequest
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiV1ChatPublicChatIdImagesPost(chatId: number, apiV1ChatPublicChatIdImagesPostRequest: ApiV1ChatPublicChatIdImagesPostRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ApiV1ChatPublicChatIdImagesPost200Response>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.apiV1ChatPublicChatIdImagesPost(chatId, apiV1ChatPublicChatIdImagesPostRequest, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['ChatPublicApi.apiV1ChatPublicChatIdImagesPost']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
*
* @summary
@ -3330,7 +3409,7 @@ export const ChatPublicApiFp = function(configuration?: Configuration) {
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async apiV1ChatPublicChatIdMessagesPost(chatId: number, schemaAddPublicChatMessageRequest: RagNewInternalSchemaAddPublicChatMessageRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ApiV1ChatPublicChatIdMessagesPost200Response>> {
async apiV1ChatPublicChatIdMessagesPost(chatId: number, schemaAddPublicChatMessageRequest: RagNewInternalSchemaAddPublicChatMessageRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ApiV1ChatPublicChatIdImagesPost200Response>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.apiV1ChatPublicChatIdMessagesPost(chatId, schemaAddPublicChatMessageRequest, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['ChatPublicApi.apiV1ChatPublicChatIdMessagesPost']?.[localVarOperationServerIndex]?.url;
@ -3383,6 +3462,17 @@ export const ChatPublicApiFactory = function (configuration?: Configuration, bas
apiV1ChatPublicChatIdClearPost(chatId: number, schemaGetPublicChatMessageRequest: RagNewInternalSchemaGetPublicChatMessageRequest, options?: any): AxiosPromise<void> {
return localVarFp.apiV1ChatPublicChatIdClearPost(chatId, schemaGetPublicChatMessageRequest, options).then((request) => request(axios, basePath));
},
/**
*
* @summary
* @param {number} chatId
* @param {ApiV1ChatPublicChatIdImagesPostRequest} apiV1ChatPublicChatIdImagesPostRequest
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
apiV1ChatPublicChatIdImagesPost(chatId: number, apiV1ChatPublicChatIdImagesPostRequest: ApiV1ChatPublicChatIdImagesPostRequest, options?: any): AxiosPromise<ApiV1ChatPublicChatIdImagesPost200Response> {
return localVarFp.apiV1ChatPublicChatIdImagesPost(chatId, apiV1ChatPublicChatIdImagesPostRequest, options).then((request) => request(axios, basePath));
},
/**
*
* @summary
@ -3403,7 +3493,7 @@ export const ChatPublicApiFactory = function (configuration?: Configuration, bas
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
apiV1ChatPublicChatIdMessagesPost(chatId: number, schemaAddPublicChatMessageRequest: RagNewInternalSchemaAddPublicChatMessageRequest, options?: any): AxiosPromise<ApiV1ChatPublicChatIdMessagesPost200Response> {
apiV1ChatPublicChatIdMessagesPost(chatId: number, schemaAddPublicChatMessageRequest: RagNewInternalSchemaAddPublicChatMessageRequest, options?: any): AxiosPromise<ApiV1ChatPublicChatIdImagesPost200Response> {
return localVarFp.apiV1ChatPublicChatIdMessagesPost(chatId, schemaAddPublicChatMessageRequest, options).then((request) => request(axios, basePath));
},
/**
@ -3449,6 +3539,19 @@ export class ChatPublicApi extends BaseAPI {
return ChatPublicApiFp(this.configuration).apiV1ChatPublicChatIdClearPost(chatId, schemaGetPublicChatMessageRequest, options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @summary
* @param {number} chatId
* @param {ApiV1ChatPublicChatIdImagesPostRequest} apiV1ChatPublicChatIdImagesPostRequest
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof ChatPublicApi
*/
public apiV1ChatPublicChatIdImagesPost(chatId: number, apiV1ChatPublicChatIdImagesPostRequest: ApiV1ChatPublicChatIdImagesPostRequest, options?: RawAxiosRequestConfig) {
return ChatPublicApiFp(this.configuration).apiV1ChatPublicChatIdImagesPost(chatId, apiV1ChatPublicChatIdImagesPostRequest, options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @summary

View File

@ -12,7 +12,7 @@
<div class="font-weight-black">
<div v-if="message.role == 'assistant'">AI</div>
<div v-else-if="message.role == 'system'">系统</div>
<div v-else-if="message.role == 'image'" class="text-right">图片</div>
<div v-else-if="message.role == 'user'" class="text-right">用户</div>
<div v-else>
@ -32,6 +32,12 @@
<div v-else-if="message.role == 'user'" class="text-right">
<vue-markdown :source="message.content" />
</div>
<div v-else-if="message.role == 'image'" class="text-right">
<img
:src="imageBaseUrl + '/' + message.content + '/download'"
width="30%"
/>
</div>
<div v-else>
{{ message.content }}
</div>
@ -61,7 +67,17 @@
label="输入消息"
@keyup.enter="sendMessage"
></v-text-field>
<v-file-input v-model="fileUpload" label="选择图片"></v-file-input>
<v-btn color="primary" @click="sendMessage">发送</v-btn>
<v-btn
class="ml-2"
color="primary"
:loading="uploading"
@click="uploadImage"
>上传图片</v-btn
>
<v-btn class="ml-2" color="primary" @click="clearMessages">清空</v-btn>
</div>
</div>
@ -78,6 +94,7 @@ import {
RagNewInternalSchemaGetPublicChatMessageRequest,
} from "@/api";
import { usePublicChatStore } from "@/stores/public_chat";
import config from "@/config/config";
const publicChatStore = usePublicChatStore();
@ -87,6 +104,9 @@ if (publicChatStore.guest_id === "") {
const chatId = ref();
const uploading = ref(false);
const imageBaseUrl = config.backend + "/api/v1/files";
//
const queries = new URLSearchParams(window.location.search);
const requiredQuries = ["assistant_token"];
@ -119,6 +139,7 @@ const input = ref("");
const toolName = ref("");
const toolError = ref(false);
const toolCalling = ref(false);
const fileUpload = ref();
function sendMessage() {
if (input.value !== "") {
@ -264,5 +285,39 @@ const createChat = () => {
});
};
const uploadImage = () => {
if (!fileUpload.value) {
return;
}
uploading.value = true;
api.ChatPublic.apiV1ChatPublicChatIdImagesPost(
chatId.value,
{
image: fileUpload.value,
assistant_token: publicChatInfo.value.assistant_token,
guest_id: publicChatInfo.value.guest_id,
},
{
headers: {
"Content-Type": "multipart/form-data",
},
},
)
.then((r) => {
//
if (r.status === 200 || r.status === 201) {
fileUpload.value = null;
getMessages();
}
})
.catch((err) => {
alert(err.response.data.message);
})
.finally(() => {
uploading.value = false;
});
};
createChat();
</script>