mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-24 23:12:55 +00:00
OpenAI: refactoring
This commit is contained in:
parent
1bbafc8b7d
commit
93b1187032
2 changed files with 5 additions and 5 deletions
|
@ -2444,6 +2444,11 @@ public class FragmentCompose extends FragmentBase {
|
|||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String model = prefs.getString("openai_model", "gpt-3.5-turbo");
|
||||
float temperature = prefs.getFloat("openai_temperature", 0.5f);
|
||||
boolean moderation = prefs.getBoolean("openai_moderation", false);
|
||||
|
||||
if (moderation)
|
||||
for (OpenAI.Message message : result)
|
||||
OpenAI.checkModeration(context, message.getContent());
|
||||
|
||||
OpenAI.Message[] completions =
|
||||
OpenAI.completeChat(context, model, result.toArray(new OpenAI.Message[0]), temperature, 1);
|
||||
|
|
|
@ -112,13 +112,8 @@ public class OpenAI {
|
|||
static Message[] completeChat(Context context, String model, Message[] messages, Float temperature, int n) throws JSONException, IOException {
|
||||
// https://platform.openai.com/docs/guides/chat/introduction
|
||||
// https://platform.openai.com/docs/api-reference/chat/create
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean openai_moderation = prefs.getBoolean("openai_moderation", false);
|
||||
|
||||
JSONArray jmessages = new JSONArray();
|
||||
for (Message message : messages) {
|
||||
if (openai_moderation)
|
||||
checkModeration(context, message.content);
|
||||
JSONObject jmessage = new JSONObject();
|
||||
jmessage.put("role", message.role);
|
||||
jmessage.put("content", message.content);
|
||||
|
|
Loading…
Reference in a new issue