antes do ollama

This commit is contained in:
2026-06-18 11:15:49 +01:00
parent 04ce7ece4f
commit 55560a1bfb
4 changed files with 21 additions and 13 deletions

View File

@@ -47,7 +47,7 @@ public class InvoiceScannerHelper {
}
GenerativeModel gm = new GenerativeModel(
"gemini-2.5-flash",
"gemini-1.5-flash",
API_KEY
);
GenerativeModelFutures model = GenerativeModelFutures.from(gm);
@@ -65,13 +65,19 @@ public class InvoiceScannerHelper {
try {
String textResponse = result.getText();
if (textResponse != null) {
textResponse = textResponse.replace("```json", "").replace("```", "").trim();
JSONObject json = new JSONObject(textResponse);
double valor = json.optDouble("valor", 0.0);
String descricao = json.optString("descricao", "");
String categoria = json.optString("categoria", "Outros");
String data = json.optString("data", "");
callback.onSuccess(valor, descricao, categoria, data);
int start = textResponse.indexOf("{");
int end = textResponse.lastIndexOf("}");
if (start != -1 && end != -1 && end > start) {
String jsonContent = textResponse.substring(start, end + 1);
JSONObject json = new JSONObject(jsonContent);
double valor = json.optDouble("valor", 0.0);
String descricao = json.optString("descricao", "");
String categoria = json.optString("categoria", "Outros");
String data = json.optString("data", "");
callback.onSuccess(valor, descricao, categoria, data);
} else {
callback.onError("Não foi possível extrair os dados formatados em JSON.");
}
} else {
callback.onError("Resposta vazia da IA.");
}