Skip to content

Commit

Permalink
Optimize the conversation assembly logic
Browse files Browse the repository at this point in the history
  • Loading branch information
AiQL.com authored Oct 19, 2024
1 parent 2d8e51b commit f5c897b
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -990,29 +990,15 @@ <h5 class="font-weight-bold">{{ column.key }}</h5>
if (this.userMessage) {
// Add the message to the list


const imageBase64 = this.base64;

let conversation

if (imageBase64) {
const contentWithImage = {
content: [
{ type: "image_url", image_url: { url: imageBase64 } },
{ type: "text", text: this.userMessage }],
role: "user",
};
this.conversation.push(contentWithImage);
// Image is too large, only latest query could be kept
conversation = [contentWithImage]
} else {
const contentText = {
content: this.userMessage,
role: "user",
}
this.conversation.push(contentText);
conversation = this.conversation
}
this.conversation.push({
content: imageBase64
? [{ type: "image_url", image_url: { url: imageBase64 } }, { type: "text", text: this.userMessage }]
: this.userMessage,
role: "user",
});

// Clear the input
this.userMessage = "";
this.images = [];
Expand All @@ -1023,6 +1009,16 @@ <h5 class="font-weight-bold">{{ column.key }}</h5>
}
historyStore.sync(this.conversation)

// Image is too large, only latest query could be kept
const conversation = this.conversation.reduce((newConversation, item) => {
if (item.role === "user" && item.content[0].type === "image_url") {
newConversation = [item];
} else {
newConversation.push(item);
}
return newConversation;
}, []);

await createCompletion(conversation);
historyStore.sync(this.conversation)
}
Expand Down

0 comments on commit f5c897b

Please sign in to comment.