From b4651aff35917ec55e7ce91620b0d92d575700f3 Mon Sep 17 00:00:00 2001 From: Timothy Carambat Date: Mon, 26 Aug 2024 14:35:42 -0700 Subject: [PATCH] Support gpt-4o for Azure deployments (#2182) --- server/utils/AiProviders/azureOpenAi/index.js | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/server/utils/AiProviders/azureOpenAi/index.js b/server/utils/AiProviders/azureOpenAi/index.js index feb6f0a1b..2a293d053 100644 --- a/server/utils/AiProviders/azureOpenAi/index.js +++ b/server/utils/AiProviders/azureOpenAi/index.js @@ -65,17 +65,47 @@ class AzureOpenAiLLM { 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({ systemPrompt = "", contextTexts = [], chatHistory = [], userPrompt = "", + attachments = [], // This is the specific attachment for only this prompt }) { const prompt = { role: "system", 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 }) {