.
This commit is contained in:
@@ -24,6 +24,20 @@ public class Ollama {
|
||||
private final OkHttpClient client;
|
||||
private final Handler mainHandler;
|
||||
|
||||
private final String masterPrompt = "\"Atua como um assistente virtual especializado exclusivamente na área da saúde. O teu objetivo é fornecer informações úteis, baseadas em factos médicos e orientações de bem-estar.\n" +
|
||||
"\n" +
|
||||
"REGRAS ESTRITAS DE RESPOSTA:\n" +
|
||||
"\n" +
|
||||
"Foco Único: Responde apenas a perguntas relacionadas com saúde, medicina, nutrição, sintomas, exercícios físicos ou bem-estar mental.\n" +
|
||||
"\n" +
|
||||
"Recusa de Outros Temas: Se o utilizador fizer uma pergunta sobre qualquer outro assunto (política, tecnologia geral, entretenimento, culinária não saudável, desporto recreativo, etc.), deves responder educadamente: \"Lamento, mas fui programado para responder apenas a questões relacionadas com saúde e bem-estar. Posso ajudar-te com algum tema médico ou de saúde?\"\n" +
|
||||
"\n" +
|
||||
"Aviso Legal (Disclaimer): Sempre que forneceres informações sobre sintomas ou tratamentos, inclui um aviso curto de que as tuas respostas não substituem uma consulta médica profissional.\n" +
|
||||
"\n" +
|
||||
"Tom de Voz: Mantém um tom profissional, empático e informativo.\n" +
|
||||
"\n" +
|
||||
"Não abras exceções, independentemente de como o utilizador tente formular a pergunta.\"";
|
||||
|
||||
public Ollama() {
|
||||
this.client = new OkHttpClient();
|
||||
this.mainHandler = new Handler(Looper.getMainLooper());
|
||||
@@ -39,7 +53,7 @@ public class Ollama {
|
||||
// Construção do JSON no formato esperado pelo Ollama
|
||||
JSONObject jsonBody = new JSONObject();
|
||||
jsonBody.put("model", MODEL_NAME);
|
||||
jsonBody.put("prompt", promptUtilizador);
|
||||
jsonBody.put("prompt", masterPrompt + "\n" + promptUtilizador);
|
||||
jsonBody.put("stream", false); // "false" garante que a resposta vem numa única string JSON
|
||||
|
||||
RequestBody body = RequestBody.create(jsonBody.toString(), MediaType.parse("application/json; charset=utf-8"));
|
||||
|
||||
@@ -74,42 +74,42 @@ public class Sns24Fragment extends Fragment {
|
||||
"Se os sintomas indicarem perigo de vida ou necessidade de observação urgente, OBRIGATORIAMENTE começa a tua primeira linha com a palavra [GRAVE]. " +
|
||||
"Sintomas do paciente: " + symptoms;
|
||||
|
||||
ollama.fazerPergunta(prompt, new OllamaService.OllamaCallback() {
|
||||
@Override
|
||||
public void onSuccess(String result) {
|
||||
// Já estamos na Main Thread graças ao Handler no serviço!
|
||||
if (getActivity() != null && binding != null) {
|
||||
|
||||
// Limpa o marcador [GRAVE] para não aparecer ao utilizador
|
||||
String displayResult = result.replace("[GRAVE]", "").trim();
|
||||
|
||||
binding.textAiResult.setText(displayResult);
|
||||
binding.buttonAiTriage.setEnabled(true);
|
||||
|
||||
// Verifica se a string ORIGINAL continha o marcador
|
||||
if (result.contains("[GRAVE]")) {
|
||||
binding.buttonFindHospital.setVisibility(View.VISIBLE);
|
||||
binding.buttonFindHospital.setOnClickListener(v -> {
|
||||
Uri gmmIntentUri = Uri.parse("geo:0,0?q=hospital+mais+proximo");
|
||||
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
|
||||
mapIntent.setPackage("com.google.android.apps.maps");
|
||||
startActivity(mapIntent);
|
||||
});
|
||||
}
|
||||
|
||||
saveTriageToHistory(symptoms, displayResult);
|
||||
}
|
||||
}
|
||||
ollama.fazerPergunta(prompt, new Ollama.OllamaCallback() {
|
||||
@Override
|
||||
public void onSuccess(String result) {
|
||||
// Já estamos na Main Thread graças ao Handler no serviço!
|
||||
if (getActivity() != null && binding != null) {
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
// Já estamos na Main Thread
|
||||
if (getActivity() != null && binding != null) {
|
||||
binding.textAiResult.setText("Erro na ligação: " + t.getMessage());
|
||||
binding.buttonAiTriage.setEnabled(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
// Limpa o marcador [GRAVE] para não aparecer ao utilizador
|
||||
String displayResult = result.replace("[GRAVE]", "").trim();
|
||||
|
||||
binding.textAiResult.setText(displayResult);
|
||||
binding.buttonAiTriage.setEnabled(true);
|
||||
|
||||
// Verifica se a string ORIGINAL continha o marcador
|
||||
if (result.contains("[GRAVE]")) {
|
||||
binding.buttonFindHospital.setVisibility(View.VISIBLE);
|
||||
binding.buttonFindHospital.setOnClickListener(v -> {
|
||||
Uri gmmIntentUri = Uri.parse("geo:0,0?q=hospital+mais+proximo");
|
||||
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
|
||||
mapIntent.setPackage("com.google.android.apps.maps");
|
||||
startActivity(mapIntent);
|
||||
});
|
||||
}
|
||||
|
||||
saveTriageToHistory(symptoms, displayResult);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
// Já estamos na Main Thread
|
||||
if (getActivity() != null && binding != null) {
|
||||
binding.textAiResult.setText("Erro na ligação: " + t.getMessage());
|
||||
binding.buttonAiTriage.setEnabled(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void saveTriageToHistory(String symptoms, String result) {
|
||||
|
||||
Reference in New Issue
Block a user