Skip to content

Commit

Permalink
Support for interrupting a conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
AiQL.com authored Oct 23, 2024
1 parent ad10fff commit 0d6616d
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ <h5 class="font-weight-bold">{{ column.key }}</h5>
},
handleKeydown(e) {
if (e.key === "Enter" && (e.altKey || e.shiftKey || e.ctrlKey)) {
// 当同时按下 alt或者shift 和 enter 时,插入一个换行符
// Alt/Shift + Enter, insert a \n
e.preventDefault();
const textarea = e.target;
// Get the current cursor position
Expand All @@ -1059,7 +1059,7 @@ <h5 class="font-weight-bold">{{ column.key }}</h5>
textarea.selectionEnd = start + 1;
}, 0);
} else if (e.key === "Enter") {
// 当只按下 enter 时,发送消息
// Only Enter is pressed, send message
e.preventDefault();
this.sendMessage();
}
Expand All @@ -1071,10 +1071,9 @@ <h5 class="font-weight-bold">{{ column.key }}</h5>
index--;
}

// 如果找到了 role "user" 的元素,丢弃它之后的所有元素
// when role == "user" is found,drop followings
if (index >= 0) {
this.conversation.splice(index + 1);;
console.log(this.conversation);

this.userMessage = "";
this.images = [];
Expand Down Expand Up @@ -1217,9 +1216,6 @@ <h5 class="font-weight-bold">{{ column.key }}</h5>
"/v1/openai/chat/completions",
"/openai/v1/chat/completions"],
model: [
"gpt-4o-mini",
"gpt-4o",
"gpt-4-turbo",
"Qwen/Qwen2.5-72B-Instruct",
"meta-llama/Llama-3.2-11B-Vision-Instruct",
"meta-llama/Llama-3.2-90B-Vision-Instruct",
Expand Down Expand Up @@ -1360,7 +1356,7 @@ <h5 class="font-weight-bold">{{ column.key }}</h5>
let buffer = ''

// Read the stream
read(reader, messageStore.conversation, buffer, chatbotStore.stream);
read(reader, messageStore.conversation[messageStore.conversation.length - 1], buffer, chatbotStore.stream);
} catch (error) {
snackbarStore.showErrorMessage(error.message);
}
Expand Down Expand Up @@ -1452,10 +1448,8 @@ <h5 class="font-weight-bold">{{ column.key }}</h5>

const parseChoice = (choice, target) => {
if (choice) {
if (target instanceof Array) {
target[target.length - 1].content += choice;
} else {
target = target += choice;
if (target.role == 'assistant') {
target.content += choice;
}
}
};
Expand Down

0 comments on commit 0d6616d

Please sign in to comment.