Fix chat msg formatting in Output for image models (#971)

This commit is contained in:
Peter Zaback 2024-03-16 16:33:19 -05:00 • committed by GitHub
parent 5b3dda0038
commit 6a5ad0e5d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -29,6 +29,7 @@ import {
compileChatMessages,
countTokens,
pruneRawPromptFromTop,
stripImages,
} from "./countTokens";
import CompletionOptionsForModels from "./templates/options";
@ -245,8 +246,13 @@ ${prompt}`;
}
private _formatChatMessages(messages: ChatMessage[]): string {
const msgsCopy = messages ? messages.map((msg) => ({ ...msg })) : [];
let formatted = "";
for (let msg of messages) {
for (let msg of msgsCopy) {
if ("content" in msg && Array.isArray(msg.content)) {
const content = stripImages(msg.content);
msg.content = content;
}
formatted += `<${msg.role}>\n${msg.content || ""}\n\n`;
}
return formatted;