AI聊天更新历史记录
This commit is contained in:
@@ -6,9 +6,13 @@ import {
|
||||
|
||||
const service = axios.create({
|
||||
// baseURL: 'http://localhost:9090/dev-api/aitutor/aichat',
|
||||
baseURL: 'http://localhost:8088/aitutor/aichat',
|
||||
// baseURL: 'http://localhost:8088/aitutor/aichat',
|
||||
// baseURL: 'http://localhost:8080/aitutor/aichat',
|
||||
baseURL: 'http://localhost:8088',
|
||||
timeout: 15000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
// 请求拦截器:统一加 token
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// src/utils/ai_stream.js (H5 优化版)
|
||||
// src/utils/ai_stream.js
|
||||
import {
|
||||
getToken
|
||||
} from '@/utils/auth';
|
||||
@@ -23,7 +23,6 @@ export function createChatStream(params) {
|
||||
const fetchPromise = fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'text/event-stream',
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'X-Request-ID': requestId
|
||||
@@ -32,26 +31,27 @@ export function createChatStream(params) {
|
||||
query: params.prompt,
|
||||
user_id: params.userId,
|
||||
user_name: params.userName,
|
||||
user_token: params.user_token || '123',
|
||||
user_token: params.user_token || '123',
|
||||
user_role: 'student',
|
||||
conversation_id: params.conversationId || null,
|
||||
conversation_id: params.conversationId || null,
|
||||
}),
|
||||
signal: controller.signal
|
||||
})
|
||||
.then(resp => {
|
||||
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
|
||||
if (!resp.body) throw new Error('Response body is null');
|
||||
return resp.body;
|
||||
.then(response => {
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
if (!response.body) throw new Error('Response body is null');
|
||||
return {
|
||||
reader: response.body.getReader(),
|
||||
decoder: new TextDecoder('utf-8')
|
||||
};
|
||||
});
|
||||
|
||||
return fetchPromise.then(body => ({
|
||||
stream: Promise.resolve({
|
||||
reader: body.getReader(),
|
||||
decoder: new TextDecoder('utf-8')
|
||||
}),
|
||||
cancel: reason => !controller.signal.aborted && controller.abort(reason)
|
||||
})).catch(err => ({
|
||||
stream: Promise.reject(err),
|
||||
cancel: () => {}
|
||||
}));
|
||||
return {
|
||||
stream: fetchPromise,
|
||||
cancel: (reason) => {
|
||||
if (!controller.signal.aborted) {
|
||||
controller.abort(reason);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user