From f86b572eae3682ae55ce42a09579abf8dff7be83 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 14 May 2024 17:08:23 +0200 Subject: [PATCH] OpenAI: optional multi modal --- .../main/java/eu/faircode/email/OpenAI.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/OpenAI.java b/app/src/main/java/eu/faircode/email/OpenAI.java index 1e1157ac44..7c1ed18f72 100644 --- a/app/src/main/java/eu/faircode/email/OpenAI.java +++ b/app/src/main/java/eu/faircode/email/OpenAI.java @@ -116,17 +116,19 @@ public class OpenAI { JSONObject jmessage = new JSONObject(); jmessage.put("role", message.role); - JSONArray jcontents = new JSONArray(); - - for (Content content : message.content) { - JSONObject jcontent = new JSONObject(); - jcontent.put("type", content.type); - jcontent.put(content.type, content.content); - jcontents.put(jcontent); + if (message.content.length == 1 && CONTENT_TEXT.equals(message.content[0].type)) + jmessage.put("content", message.content[0].content); + else { + JSONArray jcontents = new JSONArray(); + for (Content content : message.content) { + JSONObject jcontent = new JSONObject(); + jcontent.put("type", content.type); + jcontent.put(content.type, content.content); + jcontents.put(jcontent); + } + jmessage.put("content", jcontents); } - jmessage.put("content", jcontents); - jmessages.put(jmessage); }