Gemini: fixed temperature range

pull/215/head
M66B 8 months ago
parent 12e79ce7e9
commit a207b73082

@ -642,7 +642,7 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
sbGeminiTemperature.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { sbGeminiTemperature.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
float temp = progress / 20f; float temp = progress / 10f;
prefs.edit().putFloat("gemini_temperature", temp).apply(); prefs.edit().putFloat("gemini_temperature", temp).apply();
} }
@ -806,7 +806,7 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
temperature = prefs.getFloat("gemini_temperature", 0.5f); temperature = prefs.getFloat("gemini_temperature", 0.5f);
tvGeminiTemperature.setText(getString(R.string.title_advanced_openai_temperature, NF.format(temperature))); tvGeminiTemperature.setText(getString(R.string.title_advanced_openai_temperature, NF.format(temperature)));
sbGeminiTemperature.setProgress(Math.round(temperature * 20)); sbGeminiTemperature.setProgress(Math.round(temperature * 10));
sbGeminiTemperature.setEnabled(swGemini.isChecked()); sbGeminiTemperature.setEnabled(swGemini.isChecked());
etGeminiSummarize.setText(prefs.getString("gemini_summarize", null)); etGeminiSummarize.setText(prefs.getString("gemini_summarize", null));

@ -62,6 +62,7 @@ public class Gemini {
} }
static Message[] generate(Context context, String model, Message[] messages, Float temperature, int n) throws JSONException, IOException { static Message[] generate(Context context, String model, Message[] messages, Float temperature, int n) throws JSONException, IOException {
//https://ai.google.dev/api/rest/v1beta/models/generateContent
JSONArray jcontents = new JSONArray(); JSONArray jcontents = new JSONArray();
for (Message message : messages) { for (Message message : messages) {
JSONArray jparts = new JSONArray(); JSONArray jparts = new JSONArray();
@ -78,13 +79,13 @@ public class Gemini {
jcontents.put(jcontent); jcontents.put(jcontent);
} }
// https://ai.google.dev/api/python/google/ai/generativelanguage/GenerationConfig // https://ai.google.dev/api/rest/v1beta/GenerationConfig
JSONObject jconfig = new JSONObject(); JSONObject jconfig = new JSONObject();
if (temperature != null) if (temperature != null)
jconfig.put("temperature", temperature); jconfig.put("temperature", temperature);
jconfig.put("candidate_count", n); jconfig.put("candidate_count", n);
// https://ai.google.dev/api/python/google/ai/generativelanguage/SafetySetting // https://ai.google.dev/api/rest/v1beta/SafetySetting
JSONArray jsafety = new JSONArray(); JSONArray jsafety = new JSONArray();
JSONObject jsex = new JSONObject(); JSONObject jsex = new JSONObject();
@ -107,7 +108,6 @@ public class Gemini {
jdanger.put("threshold", "BLOCK_ONLY_HIGH"); jdanger.put("threshold", "BLOCK_ONLY_HIGH");
jsafety.put(jdanger); jsafety.put(jdanger);
// https://ai.google.dev/api/python/google/ai/generativelanguage/GenerateContentRequest
JSONObject jrequest = new JSONObject(); JSONObject jrequest = new JSONObject();
jrequest.put("contents", jcontents); jrequest.put("contents", jcontents);
jrequest.put("generationConfig", jconfig); jrequest.put("generationConfig", jconfig);

Loading…
Cancel
Save