|
@@ -195,7 +195,7 @@ class ChatUI {
|
|
|
// 发送分析请求到父页面
|
|
|
window.parent.postMessage({ type: "ANALYZE_PAGE" }, "*");
|
|
|
console.log(2222285);
|
|
|
-
|
|
|
+
|
|
|
});
|
|
|
console.log(this.iframeInfo);
|
|
|
this.fileInput.click();
|
|
@@ -265,10 +265,7 @@ class ChatUI {
|
|
|
基于这个Excel文件的内容,请回答以下问题:
|
|
|
${this.iframeInfo}`;
|
|
|
}
|
|
|
-
|
|
|
const response = await this.aiService.sendMessage(prompt);
|
|
|
-console.log(response);
|
|
|
-
|
|
|
if (this.loadingDiv) {
|
|
|
this.loadingDiv.remove();
|
|
|
this.loadingDiv = null;
|
|
@@ -309,12 +306,7 @@ console.log(response);
|
|
|
* @param {boolean} typing 是否使用打字效果
|
|
|
* @param {boolean} isInterrupted 是否是中断消息
|
|
|
*/
|
|
|
- async addMessage(
|
|
|
- content,
|
|
|
- type,
|
|
|
- typing = type === "assistant",
|
|
|
- isInterrupted = false
|
|
|
- ) {
|
|
|
+ async addMessage(content, type, typing = type === "assistant", isInterrupted = false) {
|
|
|
const messageDiv = document.createElement("div");
|
|
|
messageDiv.className = `message ${type}`;
|
|
|
|
|
@@ -351,7 +343,31 @@ console.log(response);
|
|
|
|
|
|
if (typing) {
|
|
|
messageContent.classList.add("typing");
|
|
|
- await this.typeMessage(paragraph, content);
|
|
|
+ if (typeof content !== 'string') {
|
|
|
+ console.log(content);
|
|
|
+ console.log(content.controller);
|
|
|
+ const signal = content.controller.signal;
|
|
|
+ try {
|
|
|
+ const iterator = content.iterator();
|
|
|
+ for await (const chunk of iterator) {
|
|
|
+ if (chunk) {
|
|
|
+ console.log(chunk);
|
|
|
+ const decodedChunk = chunk.choices[0].delta.content;
|
|
|
+ if (decodedChunk) {
|
|
|
+ paragraph.innerHTML += decodedChunk;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ if (signal.aborted) {
|
|
|
+ console.log("Stream reading aborted");
|
|
|
+ } else {
|
|
|
+ console.error("Error reading stream:", error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ await this.typeMessage(paragraph, content);
|
|
|
+ }
|
|
|
messageContent.classList.remove("typing");
|
|
|
} else {
|
|
|
paragraph.innerHTML = this.formatMessage(content);
|
|
@@ -373,7 +389,7 @@ console.log(response);
|
|
|
* @param {string} text 要显示的文字
|
|
|
*/
|
|
|
async typeMessage(element, text) {
|
|
|
- return element.innerHTML = text;
|
|
|
+ return element.innerHTML = text;
|
|
|
let index = 0;
|
|
|
const rawText = text;
|
|
|
const tempDiv = document.createElement("div");
|
|
@@ -751,7 +767,7 @@ console.log(response);
|
|
|
this.loadingDiv = null;
|
|
|
}
|
|
|
|
|
|
- await this.addMessage(response, "assistant", true);
|
|
|
+ await this.addMessage(response, "assistant", false);
|
|
|
|
|
|
// 将总结内容添加到上下文
|
|
|
this.aiService.updateContext(prompt, "user");
|
|
@@ -809,12 +825,12 @@ console.log(response);
|
|
|
// 调用AI服务理解数据
|
|
|
const response = await this.aiService.sendMessage(prompt);
|
|
|
console.log(response);
|
|
|
-
|
|
|
+
|
|
|
if (this.loadingDiv) {
|
|
|
this.loadingDiv.remove();
|
|
|
this.loadingDiv = null;
|
|
|
}
|
|
|
- 0 && window.parent.postMessage({
|
|
|
+ 0 && window.parent.postMessage({
|
|
|
type: "HANDLE_FILL_INPUT", data: {
|
|
|
excelData: this.excelData,
|
|
|
formData: JSON.parse(response.split('json')[1].split('```')[0]) //根据不同返回修改res
|
|
@@ -852,7 +868,7 @@ console.log(response);
|
|
|
const headers = data[0];
|
|
|
const rows = data.slice(1);
|
|
|
const sampleRows = rows.slice(0, 2);
|
|
|
- console.log();
|
|
|
+ console.log();
|
|
|
data[0].forEach((header, i) => {
|
|
|
if (!this.excelData[header]) this.excelData[header] = []
|
|
|
this.excelData[header].push(data[1][i])
|
|
@@ -923,7 +939,7 @@ ${this.iframeInfo}
|
|
|
// .join(", ")}`;
|
|
|
// })
|
|
|
// .join("\n")}
|
|
|
-
|
|
|
+
|
|
|
// 等待DOM加载完成后再初始化
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
|
try {
|