MCPcopy Create free account
hub / github.com/M66B/FairEmail / getEmbedding

Method getEmbedding

app/src/main/java/eu/faircode/email/OpenAI.java:104–116  ·  view source on GitHub ↗
(Context context, String text, String model)

Source from the content-addressed store, hash-verified

102 }
103
104 static double[] getEmbedding(Context context, String text, String model) throws JSONException, IOException {
105 // https://platform.openai.com/docs/api-reference/embeddings
106 JSONObject jrequest = new JSONObject();
107 jrequest.put("input", text);
108 jrequest.put("model", model == null ? "text-embedding-ada-002" : model);
109 JSONObject jresponse = call(context, "POST", "embeddings", jrequest);
110 JSONObject jdata = jresponse.getJSONArray("data").getJSONObject(0);
111 JSONArray jembedding = jdata.getJSONArray("embedding");
112 double[] result = new double[jembedding.length()];
113 for (int i = 0; i < jembedding.length(); i++)
114 result[i] = jembedding.getDouble(i);
115 return result;
116 }
117
118 static Message[] completeChat(Context context, String model, Message[] messages, Float temperature, int n) throws JSONException, IOException {
119 // https://platform.openai.com/docs/guides/chat/introduction

Callers

nothing calls this directly

Calls 4

callMethod · 0.95
getDoubleMethod · 0.80
putMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected