antes do ollama
This commit is contained in:
@@ -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.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user