diff --git a/app/build.gradle b/app/build.gradle index df39329ba0..7dfc11d4f3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -208,7 +208,7 @@ android { buildConfigField "String", "ANNOUNCEMENT_URI", "\"\"" buildConfigField "String", "CLOUD_URI", "\"https://api.fairemail.net/sync\"" buildConfigField "String", "CLOUD_EMAIL", "\"cloud@in.faircode.eu\"" - buildConfigField "String", "OPENAI_ENDPOINT", "\"https://api.openai.com/\"" + buildConfigField "String", "OPENAI_ENDPOINT", "\"https://api.openai.com/v1/\"" buildConfigField "String", "OPENAI_PRIVACY", "\"https://openai.com/policies/privacy-policy\"" buildConfigField "String", "FDROID", "\"https://f-droid.org/packages/%s/\"" } @@ -230,7 +230,7 @@ android { buildConfigField "String", "ANNOUNCEMENT_URI", "\"\"" buildConfigField "String", "CLOUD_URI", "\"https://api.fairemail.net/sync\"" buildConfigField "String", "CLOUD_EMAIL", "\"cloud@in.faircode.eu\"" - buildConfigField "String", "OPENAI_ENDPOINT", "\"https://api.openai.com/\"" + buildConfigField "String", "OPENAI_ENDPOINT", "\"https://api.openai.com/v1/\"" buildConfigField "String", "OPENAI_PRIVACY", "\"https://openai.com/policies/privacy-policy\"" buildConfigField "String", "FDROID", "\"https://f-droid.org/packages/%s/\"" } @@ -261,7 +261,7 @@ android { buildConfigField "String", "ANNOUNCEMENT_URI", "\"\"" buildConfigField "String", "CLOUD_URI", "\"https://api.fairemail.net/sync\"" buildConfigField "String", "CLOUD_EMAIL", "\"cloud@in.faircode.eu\"" - buildConfigField "String", "OPENAI_ENDPOINT", "\"https://api.openai.com/\"" + buildConfigField "String", "OPENAI_ENDPOINT", "\"https://api.openai.com/v1/\"" buildConfigField "String", "OPENAI_PRIVACY", "\"https://openai.com/policies/privacy-policy\"" buildConfigField "String", "FDROID", "\"https://f-droid.org/packages/%s/\"" } diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 9b7ee18581..75a9a9c292 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -2662,14 +2662,6 @@ public class FragmentCompose extends FragmentBase { OpenAI.Message[] completions = OpenAI.completeChat(context, model, result.toArray(new OpenAI.Message[0]), temperature, 1); - try { - Pair usage = OpenAI.getGrants(context); - args.putDouble("used", usage.first); - args.putDouble("granted", usage.second); - } catch (Throwable ex) { - Log.w(ex); - } - return completions; } diff --git a/app/src/main/java/eu/faircode/email/OpenAI.java b/app/src/main/java/eu/faircode/email/OpenAI.java index 30296c4c9f..9991b7ded7 100644 --- a/app/src/main/java/eu/faircode/email/OpenAI.java +++ b/app/src/main/java/eu/faircode/email/OpenAI.java @@ -58,39 +58,11 @@ public class OpenAI { (!TextUtils.isEmpty(apikey) || !Objects.equals(getUri(context), BuildConfig.OPENAI_ENDPOINT))); } - static Pair getGrants(Context context) throws JSONException, IOException { - // dashboard/billing/credit_grants - // { - // "object": "credit_summary", - // "total_granted": , - // "total_used": , - // "total_available": , - // "grants": { - // "object": "list", - // "data": [ - // { - // "object": "credit_grant", - // "id": ">", - // "grant_amount": , - // "used_amount": >, - // "effective_at": , - // "expires_at": - // } - // ] - // } - //} - - JSONObject grants = call(context, "GET", "dashboard/billing/credit_grants", null); - return new Pair<>( - grants.getDouble("total_used"), - grants.getDouble("total_granted")); - } - static void checkModeration(Context context, String text) throws JSONException, IOException { // https://platform.openai.com/docs/api-reference/moderations/create JSONObject jrequest = new JSONObject(); jrequest.put("input", text); - JSONObject jresponse = call(context, "POST", "v1/moderations", jrequest); + JSONObject jresponse = call(context, "POST", "moderations", jrequest); JSONArray jresults = jresponse.getJSONArray("results"); for (int i = 0; i < jresults.length(); i++) { JSONObject jresult = jresults.getJSONObject(i); @@ -117,7 +89,7 @@ public class OpenAI { JSONObject jrequest = new JSONObject(); jrequest.put("input", text); jrequest.put("model", model == null ? "text-embedding-ada-002" : model); - JSONObject jresponse = call(context, "POST", "v1/embeddings", jrequest); + JSONObject jresponse = call(context, "POST", "embeddings", jrequest); JSONObject jdata = jresponse.getJSONArray("data").getJSONObject(0); JSONArray jembedding = jdata.getJSONArray("embedding"); double[] result = new double[jembedding.length()]; @@ -143,7 +115,7 @@ public class OpenAI { if (temperature != null) jquestion.put("temperature", temperature); jquestion.put("n", n); - JSONObject jresponse = call(context, "POST", "v1/chat/completions", jquestion); + JSONObject jresponse = call(context, "POST", "chat/completions", jquestion); JSONArray jchoices = jresponse.getJSONArray("choices"); Message[] choices = new Message[jchoices.length()]; @@ -227,7 +199,7 @@ public class OpenAI { Log.w(ex); } if (status == 429) - error = "\nThis is an error message from OpenAI, not of the app"; + error += "\nThis is an error message from OpenAI, not of the app"; throw new IOException(error); }