diff --git a/src/api/agent.ts b/src/api/agent.ts index 535248d..85043af 100644 --- a/src/api/agent.ts +++ b/src/api/agent.ts @@ -12,68 +12,8 @@ export interface AgentParamsType { export const fetchAgentReply = (data: AgentParamsType): Promise => { return request({ url: '/api/ai-design/chat', - method: 'post', + method: 'get', data, meta: { responseAll: true } }) } - -// 流式对话 -export const fetchAgentReplyStream = async ( - data: AgentParamsType, - onMessage: (chunk: string) => void, - onEnd: () => void -) => { - try { - const params = new URLSearchParams({ - message: data.message, - threadId: data.threadId, - token: data.token, - configParams: JSON.stringify(data.configParams) - }) - - const response = await fetch(`/api/ai-design/chat?${params.toString()}`, { - method: 'GET' - }) - - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`) - } - - const reader = response.body?.getReader() - if (!reader) { - throw new Error('Response body is not readable') - } - - const decoder = new TextDecoder() - let buffer = '' - - while (true) { - const { done, value } = await reader.read() - if (done) break - - buffer += decoder.decode(value, { stream: true }) - const lines = buffer.split('\n') - buffer = lines.pop() || '' // 保留不完整的行 - - for (const line of lines) { - console.log('line---', line) - - const trimmedLine = line.trim() - if (trimmedLine.startsWith('data: ')) { - const chunk = trimmedLine.slice(6) - if (chunk === '[DONE]') { - onEnd() - return - } else { - onMessage(chunk) - } - } - } - } - onEnd() - } catch (error) { - console.error('Stream error:', error) - onEnd() - } -} diff --git a/src/views/home/agent/components/Agent.vue b/src/views/home/agent/components/Agent.vue index f79ea91..3b39c0c 100644 --- a/src/views/home/agent/components/Agent.vue +++ b/src/views/home/agent/components/Agent.vue @@ -77,8 +77,8 @@ }) messageList.value.push(aiMessage) - const threadId = '' // - console.log('token---', params.token, '参数---', params) + // const threadId = '' // + // console.log('token---', params.token, '参数---', params) try { const urlParams = new URLSearchParams({ diff --git a/src/views/home/components/Input.vue b/src/views/home/components/Input.vue index 0d10a79..f528da1 100644 --- a/src/views/home/components/Input.vue +++ b/src/views/home/components/Input.vue @@ -512,6 +512,7 @@ } .scroll-content { + display: flex; flex: 1; overflow-y: auto; padding: 3.4rem 1.7rem 1.7rem;