Commit 111fa1f4 authored by Mohamad Bashar Desoki's avatar Mohamad Bashar Desoki

delete llama3

parent 19f705f0
package org.example;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class llama3 {
public String llmChat(String chat){
String prompt = "{\n" +
// " \"systemPrompt\": \" العب دور مساعد تقني يتحدث اللغة العربية بفصاحة \",\n" +
// " \"user\": \" مرحبا\",\n" +
// " \"Assistant\": \" أهلا، أسألني عن أحدث التقنيات لأجيبك\",\n" +
" \"prompt\": \""+ chat +"\"\n" +
"}";
String response = sendRequestToAPI(prompt);
// System.out.println(response);
String jsonString = "";
if (response != null) {
jsonString = response.toString().substring(0, response.length() - 51);
jsonString = jsonString + "\n \uD83D\uDC50\uD83C\uDFFB";
return jsonString;
} else {
jsonString = " \n \uD83D\uDC50\uD83C\uDFFB please try again! \uD83D\uDE0A";
return jsonString;
}
}
public String sendRequestToAPI(String prompt) {
try {
URL url = new URL("https://fumes-api.onrender.com/llama3");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setDoOutput(true);
try (OutputStream os = connection.getOutputStream()) {
byte[] input = prompt.getBytes("utf-8");
os.write(input, 0, input.length);
}
StringBuilder response = new StringBuilder();
try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"))) {
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
}
connection.disconnect();
String responseBody = response.toString();
// System.out.println(responseBody);
return responseBody;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment