Support gpt-4o for Azure deployments (#2182)

This commit is contained in:
Timothy Carambat 2024-08-26 14:35:42 -07:00 committed by GitHub
parent 12df88b2c5
commit b4651aff35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -65,17 +65,47 @@ class AzureOpenAiLLM {
return true; return true;
} }
/**
* Generates appropriate content array for a message + attachments.
* @param {{userPrompt:string, attachments: import("../../helpers").Attachment[]}}
* @returns {string|object[]}
*/
#generateContent({ userPrompt, attachments = [] }) {
if (!attachments.length) {
return userPrompt;
}
const content = [{ type: "text", text: userPrompt }];
for (let attachment of attachments) {
content.push({
type: "image_url",
imageUrl: {
url: attachment.contentString,
},
});
}
return content.flat();
}
constructPrompt({ constructPrompt({
systemPrompt = "", systemPrompt = "",
contextTexts = [], contextTexts = [],
chatHistory = [], chatHistory = [],
userPrompt = "", userPrompt = "",
attachments = [], // This is the specific attachment for only this prompt
}) { }) {
const prompt = { const prompt = {
role: "system", role: "system",
content: `${systemPrompt}${this.#appendContext(contextTexts)}`, content: `${systemPrompt}${this.#appendContext(contextTexts)}`,
}; };
return [prompt, ...chatHistory, { role: "user", content: userPrompt }]; return [
prompt,
...chatHistory,
{
role: "user",
content: this.#generateContent({ userPrompt, attachments }),
},
];
} }
async getChatCompletion(messages = [], { temperature = 0.7 }) { async getChatCompletion(messages = [], { temperature = 0.7 }) {