|
@@ -111,27 +111,11 @@ export class BigModelApi implements LLMApi {
|
|
|
// start animaion
|
|
// start animaion
|
|
|
animateResponseText();
|
|
animateResponseText();
|
|
|
|
|
|
|
|
- const finish = async () => {
|
|
|
|
|
|
|
+ const finish = () => {
|
|
|
if (!finished) {
|
|
if (!finished) {
|
|
|
finished = true;
|
|
finished = true;
|
|
|
options.onFinish(responseText + remainText);
|
|
options.onFinish(responseText + remainText);
|
|
|
}
|
|
}
|
|
|
- const session = useChatStore.getState().sessions[0];
|
|
|
|
|
- const data = {
|
|
|
|
|
- id: session.id,
|
|
|
|
|
- messages: session.messages.map(item => {
|
|
|
|
|
- return {
|
|
|
|
|
- id: item.id,
|
|
|
|
|
- date: item.date,
|
|
|
|
|
- role: item.role,
|
|
|
|
|
- content: item.content,
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- await fetch('/api/bigModel', {
|
|
|
|
|
- method: 'POST',
|
|
|
|
|
- body: JSON.stringify(data)
|
|
|
|
|
- });
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
controller.signal.onabort = finish;
|
|
controller.signal.onabort = finish;
|
|
@@ -193,8 +177,24 @@ export class BigModelApi implements LLMApi {
|
|
|
console.error("[Request] parse error", text, msg);
|
|
console.error("[Request] parse error", text, msg);
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- onclose() {
|
|
|
|
|
|
|
+ async onclose() {
|
|
|
finish();
|
|
finish();
|
|
|
|
|
+ const session = useChatStore.getState().sessions[0];
|
|
|
|
|
+ const data = {
|
|
|
|
|
+ id: session.id,
|
|
|
|
|
+ messages: session.messages.map(item => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ id: item.id,
|
|
|
|
|
+ date: item.date,
|
|
|
|
|
+ role: item.role,
|
|
|
|
|
+ content: item.content,
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ await fetch('/api/bigModel', {
|
|
|
|
|
+ method: 'POST',
|
|
|
|
|
+ body: JSON.stringify(data)
|
|
|
|
|
+ });
|
|
|
},
|
|
},
|
|
|
onerror(e) {
|
|
onerror(e) {
|
|
|
options.onError?.(e);
|
|
options.onError?.(e);
|