diff --git a/api/swagger.yaml b/api/swagger.yaml index b2e6c4a..8907ba7 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -389,6 +389,10 @@ definitions: - assistant - image type: string + variables: + additionalProperties: + type: string + type: object required: - message - role @@ -2103,8 +2107,7 @@ paths: in: header name: X-User-IP type: string - - description: Chat stream id - in: path + - in: path name: stream_id required: true type: string diff --git a/src/api/api.ts b/src/api/api.ts index 91558c6..cb52781 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -1584,6 +1584,12 @@ export interface SchemaChatMessageAddRequest { * @memberof SchemaChatMessageAddRequest */ 'role': SchemaChatMessageAddRequestRoleEnum; + /** + * + * @type {{ [key: string]: string; }} + * @memberof SchemaChatMessageAddRequest + */ + 'variables'?: { [key: string]: string; }; } export const SchemaChatMessageAddRequestRoleEnum = { @@ -3893,7 +3899,7 @@ export const ChatMessageApiAxiosParamCreator = function (configuration?: Configu /** * 将会通过 SSE 的方式来流式传输内容,不建议使用本文档生成的代码来获取,第三方库有更好的解决方案。 * @summary 流式传输文本 - * @param {string} streamId Chat stream id + * @param {string} streamId * @param {string} [xUserIP] 指定聊天中的用户 IP 地址,不指定则自动获取。此 IP 地址只会增加至 Prompt 中,如果不希望增加,请关闭系统自带 Prompt 选项 * @param {*} [options] Override http request option. * @throws {RequiredError} @@ -3996,7 +4002,7 @@ export const ChatMessageApiFp = function(configuration?: Configuration) { /** * 将会通过 SSE 的方式来流式传输内容,不建议使用本文档生成的代码来获取,第三方库有更好的解决方案。 * @summary 流式传输文本 - * @param {string} streamId Chat stream id + * @param {string} streamId * @param {string} [xUserIP] 指定聊天中的用户 IP 地址,不指定则自动获取。此 IP 地址只会增加至 Prompt 中,如果不希望增加,请关闭系统自带 Prompt 选项 * @param {*} [options] Override http request option. * @throws {RequiredError} @@ -4062,7 +4068,7 @@ export const ChatMessageApiFactory = function (configuration?: Configuration, ba /** * 将会通过 SSE 的方式来流式传输内容,不建议使用本文档生成的代码来获取,第三方库有更好的解决方案。 * @summary 流式传输文本 - * @param {string} streamId Chat stream id + * @param {string} streamId * @param {string} [xUserIP] 指定聊天中的用户 IP 地址,不指定则自动获取。此 IP 地址只会增加至 Prompt 中,如果不希望增加,请关闭系统自带 Prompt 选项 * @param {*} [options] Override http request option. * @throws {RequiredError} @@ -4133,7 +4139,7 @@ export class ChatMessageApi extends BaseAPI { /** * 将会通过 SSE 的方式来流式传输内容,不建议使用本文档生成的代码来获取,第三方库有更好的解决方案。 * @summary 流式传输文本 - * @param {string} streamId Chat stream id + * @param {string} streamId * @param {string} [xUserIP] 指定聊天中的用户 IP 地址,不指定则自动获取。此 IP 地址只会增加至 Prompt 中,如果不希望增加,请关闭系统自带 Prompt 选项 * @param {*} [options] Override http request option. * @throws {RequiredError} diff --git a/src/components/chat/Chat.vue b/src/components/chat/Chat.vue index 2a82185..4d1c979 100644 --- a/src/components/chat/Chat.vue +++ b/src/components/chat/Chat.vue @@ -210,7 +210,7 @@ const autoScroll = ref(true); const appStore = useAppStore(); const dialog = useDialog(); const assistantStore = useAssistantStore(); -const message = useMessage() +const message = useMessage(); function onKeydown(e: KeyboardEvent) { // 如果是 Esc @@ -346,7 +346,8 @@ function sendText() { async function sendMessage( role: SchemaChatMessageAddRequestRoleEnum, - text: string + text: string, + variables: any = {} ) { if (processing.value) { return; @@ -376,9 +377,20 @@ async function sendMessage( }); } + let chatVariables = { + "now": new Date().toLocaleString(), + }; + + // 合并 + chatVariables = { + ...chatVariables, + ...variables, + }; + let payload: SchemaChatMessageAddRequest = { message: text, role: role, + variables: chatVariables, }; if (chatStore.currentAssistantId) { payload = { @@ -488,7 +500,7 @@ function streamChat(streamId: String, redirect = false) { content: "目前无法完成推理,请稍后再试。", positiveText: "好", }); - } + }; let messageAdded = false; diff --git a/src/components/settings/AssistantSettings.vue b/src/components/settings/AssistantSettings.vue index 448631f..411efd4 100644 --- a/src/components/settings/AssistantSettings.vue +++ b/src/components/settings/AssistantSettings.vue @@ -67,7 +67,7 @@ /> - +