Gemini integration improvements

This commit is contained in:
M66B 2024-03-28 09:32:11 +01:00
parent b141489e61
commit c0a0fef08c
4 changed files with 51 additions and 10 deletions

13
FAQ.md
View File

@ -415,6 +415,7 @@ Anything on this list is in random order and *might* be added in the near future
* [(201) What is certificate transparency?](#faq201)
* [(202) What is DNSSEC and what is DANE?](#faq202)
* [(203) Where is my sent message?](#faq203)
* [(204) How do I use Gemini?](#faq204)
[I have another question.](#get-support)
@ -5802,6 +5803,18 @@ Basically, an outgoing message is either in the draft messages folder, the outbo
<br>
<a name="faq204"></a>
**(204) How do I use Gemini?**
1. Check if your country [is supported](https://support.google.com/gemini/answer/13575153)
1. Get an API key via [here](https://ai.google.dev/tutorials/setup)
1. Enter the API key in the integration settings tab page
1. Enable Gemini integration in the integration settings tab page
For usage, please see [this FAQ](#faq190)
<br>
<h2><a name="get-support"></a>Get support</h2>
&#x1F30E; [Google Translate](https://translate.google.com/translate?sl=en&u=https%3A%2F%2Fm66b.github.io%2FFairEmail%2F%23get-support)

View File

@ -89,6 +89,7 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
private EditText etGemini;
private TextInputLayout tilGemini;
private EditText etGeminiModel;
private ImageButton ibGemini;
private CardView cardVirusTotal;
private CardView cardSend;
@ -158,6 +159,7 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
etGemini = view.findViewById(R.id.etGemini);
tilGemini = view.findViewById(R.id.tilGemini);
etGeminiModel = view.findViewById(R.id.etGeminiModel);
ibGemini = view.findViewById(R.id.ibGemini);
cardVirusTotal = view.findViewById(R.id.cardVirusTotal);
cardSend = view.findViewById(R.id.cardSend);
@ -604,6 +606,13 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
}
});
ibGemini.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Helper.viewFAQ(v.getContext(), 204);
}
});
// Initialize
FragmentDialogTheme.setBackground(getContext(), view, false);

View File

@ -64,23 +64,30 @@ public class Gemini {
jpart.put(jtext);
}
JSONObject jcontent = new JSONObject();
jcontent.put("parts", jpart);
JSONObject jcontent0 = new JSONObject();
jcontent0.put("parts", jpart);
JSONArray jcontents = new JSONArray();
jcontents.put(jcontent);
jcontents.put(jcontent0);
JSONObject jrequest = new JSONObject();
jrequest.put("contents", jcontents);
String path = "models/" + model + ":generateContent";
String path = "models/" + Uri.encode(model) + ":generateContent";
JSONObject jresponse = call(context, "POST", path, jrequest);
return new String[]{jresponse.getJSONArray("candidates")
.getJSONObject(0)
.getJSONObject("content")
.getJSONArray("parts")
.getJSONObject(0)
.getString("text")};
JSONArray jcandidates = jresponse.optJSONArray("candidates");
if (jcandidates == null || jcandidates.length() < 1)
throw new IOException("candidates missing");
JSONObject jcontent = jcandidates.getJSONObject(0).optJSONObject("content");
if (jcontent == null)
throw new IOException("content missing");
JSONArray jparts = jcontent.optJSONArray("parts");
if (jparts == null || jparts.length() < 1)
throw new IOException("parts missing");
JSONObject jtext = jparts.getJSONObject(0);
if (!jtext.has("text"))
throw new IOException("text missing");
return new String[]{jtext.getString("text")};
}
private static String getUri(Context context) {

View File

@ -727,6 +727,18 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvGeminiModel" />
<ImageButton
android:id="@+id/ibGemini"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:contentDescription="@string/title_info"
android:tooltipText="@string/title_info"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etGeminiModel"
app:srcCompat="@drawable/twotone_info_24" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>