diff --git a/ui/src/api/application.ts b/ui/src/api/application.ts index 2a56d2c3e..1259aff33 100644 --- a/ui/src/api/application.ts +++ b/ui/src/api/application.ts @@ -73,11 +73,8 @@ const postChatOpen: (data: ApplicationFormType) => Promise> = (data) "message": "string", } */ -const postChatMessage: (chat_id: string, message: string) => Promise> = ( - chat_id, - message -) => { - return postStream(`${prefix}/chat_message/${chat_id}`, { message }) +const postChatMessage: (chat_id: string, message: string) => Promise = (chat_id, message) => { + return postStream(`/api/${prefix}/chat_message/${chat_id}`, { message }) } export default { getAllAppilcation, diff --git a/ui/src/api/model.ts b/ui/src/api/model.ts index 950b3765a..09d33cd05 100644 --- a/ui/src/api/model.ts +++ b/ui/src/api/model.ts @@ -1,7 +1,7 @@ import { Result } from '@/request/Result' import { get, post, del, put } from '@/request/index' import { type Ref } from 'vue' -import type { modelRequest, Provider } from '@/api/type/model' +import type { modelRequest, Provider, ListModelRequest, Model } from '@/api/type/model' const prefix = '/model' const prefix_provider = '/provider' @@ -9,9 +9,13 @@ const prefix_provider = '/provider' * 获得模型列表 * @params 参数 name, model_type, model_name */ -const getModel: (data?: modelRequest) => Promise> = (data) => { - return get(`${prefix}`, data) +const getModel: ( + request: ListModelRequest, + loading?: Ref +) => Promise>> = (data, loading) => { + return get(`${prefix}`, data, loading) } + /** * 获得供应商列表 */ diff --git a/ui/src/api/type/model.ts b/ui/src/api/type/model.ts index 368e0cd11..1adda47aa 100644 --- a/ui/src/api/type/model.ts +++ b/ui/src/api/type/model.ts @@ -1,3 +1,4 @@ +import { store } from '@/stores' interface modelRequest { name: string model_type: string @@ -19,4 +20,49 @@ interface Provider { icon: string } -export type { modelRequest, Provider } +interface ListModelRequest { + /** + * 模型名称 + */ + name?: string + /** + * 模型类型 + */ + model_type?: string + /** + * 基础模型名称 + */ + model_name?: string + /** + * 供应商 + */ + provider?: string +} + +interface Model { + /** + * 主键id + */ + id: String + /** + * 模型名 + */ + name: string + /** + * 模型类型 + */ + model_type: string + /** + * 基础模型 + */ + model_name: string + /** + * 认证信息 + */ + credential: any + /** + * 供应商 + */ + provider: string +} +export type { modelRequest, Provider, ListModelRequest, Model } diff --git a/ui/src/components/ai-dialog/index.vue b/ui/src/components/ai-dialog/index.vue index 2d9399119..800e6c7bc 100644 --- a/ui/src/components/ai-dialog/index.vue +++ b/ui/src/components/ai-dialog/index.vue @@ -128,22 +128,19 @@ function chatHandle() { } function chatMessage(chatId: string) { - applicationApi - .postChatMessage(chatId, inputValue.value) - .then((response) => { - console.log(response.data) - response.data.on('data', (chunk) => { - console.log(chunk) - // 处理流数据的逻辑 - }) - - // response.data.on('end', () => { - // // 数据接收完成的逻辑 - // }) - }) - .catch(() => { - loading.value = false - }) + applicationApi.postChatMessage(chatId, inputValue.value).then(async (response) => { + const reader = response.body.getReader() + while (true) { + const { done, value } = await reader.read() + if (done) { + loading.value = false + break + } + const decoder = new TextDecoder('utf-8') + const str = decoder.decode(value, { stream: true }) + console.log('value', JSON.parse(str.replace('data:', ''))) + } + }) }