quero meter o gemini na app
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
57
app/src/main/java/com/example/cuida/services/Gemini.java
Normal file
57
app/src/main/java/com/example/cuida/services/Gemini.java
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package com.example.cuida.services;
|
||||||
|
|
||||||
|
import com.google.ai.client.generativeai.GenerativeModel;
|
||||||
|
import com.google.ai.client.generativeai.java.GenerativeModelFutures;
|
||||||
|
import com.google.ai.client.generativeai.type.Content;
|
||||||
|
import com.google.ai.client.generativeai.type.GenerateContentResponse;
|
||||||
|
import com.google.common.util.concurrent.FutureCallback;
|
||||||
|
import com.google.common.util.concurrent.Futures;
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
public class Gemini {
|
||||||
|
|
||||||
|
private final GenerativeModelFutures modelo;
|
||||||
|
|
||||||
|
public Gemini() {
|
||||||
|
// 1. Configurar o modelo (usa a tua API Key do Google AI Studio)
|
||||||
|
GenerativeModel generativeModel = new GenerativeModel(
|
||||||
|
"gemini-1.5-flash",
|
||||||
|
"AIzaSyBmLgn-SHaTDvAeDWsw2iTZRR9gahhOu7k");
|
||||||
|
this.modelo = GenerativeModelFutures.from(generativeModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface GeminiCallback {
|
||||||
|
void onSuccess(String result);
|
||||||
|
|
||||||
|
void onError(Throwable t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fazerPergunta(String promptUtilizador, GeminiCallback callback) {
|
||||||
|
// 2. Preparar o conteúdo da pergunta
|
||||||
|
Content conteudo = new Content.Builder()
|
||||||
|
.addText(promptUtilizador)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// 3. Chamar a IA de forma assíncrona
|
||||||
|
ListenableFuture<GenerateContentResponse> respostaFuture = modelo.generateContent(conteudo);
|
||||||
|
|
||||||
|
Executor executor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
|
Futures.addCallback(respostaFuture, new FutureCallback<GenerateContentResponse>() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(GenerateContentResponse resultado) {
|
||||||
|
// Aqui recebes o texto da IA
|
||||||
|
String textoResposta = resultado.getText();
|
||||||
|
callback.onSuccess(textoResposta);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Throwable t) {
|
||||||
|
callback.onError(t);
|
||||||
|
}
|
||||||
|
}, executor);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -650,7 +650,7 @@ code + .copy-button {
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function configurationCacheProblems() { return (
|
function configurationCacheProblems() { return (
|
||||||
// begin-report-data
|
// begin-report-data
|
||||||
{"diagnostics":[{"problem":[{"text":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 10."}],"contextualLabel":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated.","documentationLink":"https://docs.gradle.org/9.1.0/userguide/upgrading_version_8.html#groovy_space_assignment_syntax","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"properties-should-be-assigned-using-the-propname-value-syntax-setting-a-property-via-the-gradle-generated-propname-value-or-propname-value-syntax-in-groovy-dsl","displayName":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"solutions":[[{"text":"Use assignment ('namespace = <value>') instead."}]]},{"problem":[{"text":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 10."}],"contextualLabel":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated.","documentationLink":"https://docs.gradle.org/9.1.0/userguide/upgrading_version_8.html#groovy_space_assignment_syntax","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"properties-should-be-assigned-using-the-propname-value-syntax-setting-a-property-via-the-gradle-generated-propname-value-or-propname-value-syntax-in-groovy-dsl","displayName":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"solutions":[[{"text":"Use assignment ('viewBinding = <value>') instead."}]]},{"locations":[{"taskPath":":app:compileDebugJavaWithJavac"}],"problem":[{"text":"source value 8 is obsolete and will be removed in a future release"}],"severity":"WARNING","problemDetails":[{"text":"warning: [options] source value 8 is obsolete and will be removed in a future release"}],"contextualLabel":"source value 8 is obsolete and will be removed in a future release","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler.warn.option.obsolete.source","displayName":"source value 8 is obsolete and will be removed in a future release"}]},{"locations":[{"taskPath":":app:compileDebugJavaWithJavac"}],"problem":[{"text":"target value 8 is obsolete and will be removed in a future release"}],"severity":"WARNING","problemDetails":[{"text":"warning: [options] target value 8 is obsolete and will be removed in a future release"}],"contextualLabel":"target value 8 is obsolete and will be removed in a future release","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler.warn.option.obsolete.target","displayName":"target value 8 is obsolete and will be removed in a future release"}]},{"locations":[{"taskPath":":app:compileDebugJavaWithJavac"}],"problem":[{"text":"To suppress warnings about obsolete options, use -Xlint:-options."}],"severity":"WARNING","problemDetails":[{"text":"warning: [options] To suppress warnings about obsolete options, use -Xlint:-options."}],"contextualLabel":"To suppress warnings about obsolete options, use -Xlint:-options.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler.warn.option.obsolete.suppression","displayName":"To suppress warnings about obsolete options, use -Xlint:-options."}]}],"problemsReport":{"totalProblemCount":5,"buildName":"Cuida","requestedTasks":":app:assembleDebug","documentationLink":"https://docs.gradle.org/9.1.0/userguide/reporting_problems.html","documentationLinkCaption":"Problem report","summaries":[]}}
|
{"diagnostics":[{"problem":[{"text":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 10."}],"contextualLabel":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated.","documentationLink":"https://docs.gradle.org/9.1.0/userguide/upgrading_version_8.html#groovy_space_assignment_syntax","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"properties-should-be-assigned-using-the-propname-value-syntax-setting-a-property-via-the-gradle-generated-propname-value-or-propname-value-syntax-in-groovy-dsl","displayName":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"solutions":[[{"text":"Use assignment ('namespace = <value>') instead."}]]},{"problem":[{"text":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 10."}],"contextualLabel":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated.","documentationLink":"https://docs.gradle.org/9.1.0/userguide/upgrading_version_8.html#groovy_space_assignment_syntax","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"properties-should-be-assigned-using-the-propname-value-syntax-setting-a-property-via-the-gradle-generated-propname-value-or-propname-value-syntax-in-groovy-dsl","displayName":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"solutions":[[{"text":"Use assignment ('viewBinding = <value>') instead."}]]}],"problemsReport":{"totalProblemCount":2,"buildName":"Cuida","requestedTasks":"","documentationLink":"https://docs.gradle.org/9.1.0/userguide/reporting_problems.html","documentationLinkCaption":"Problem report","summaries":[]}}
|
||||||
// end-report-data
|
// end-report-data
|
||||||
);}
|
);}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user