Suriya13 commited on
Commit
1c90314
·
verified ·
1 Parent(s): e3f37b1

Create app.java

Browse files
Files changed (1) hide show
  1. app.java +34 -0
app.java ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import java.net.URI;
2
+ import java.net.http.HttpClient;
3
+ import java.net.http.HttpRequest;
4
+ import java.net.http.HttpResponse;
5
+ import java.net.http.HttpRequest.BodyPublishers;
6
+
7
+ public class MistralChatbot {
8
+
9
+ private static final String API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.1";
10
+ private static final String API_TOKEN = "YOUR_HF_API_TOKEN";
11
+
12
+ public static void main(String[] args) throws Exception {
13
+ String prompt = "Explain the difference between Java and Python.";
14
+ String response = sendPromptToModel(prompt);
15
+ System.out.println("AI Response:\n" + response);
16
+ }
17
+
18
+ public static String sendPromptToModel(String prompt) throws Exception {
19
+ HttpClient client = HttpClient.newHttpClient();
20
+
21
+ String requestBody = "{ \"inputs\": \"" + prompt.replace("\"", "\\\"") + "\" }";
22
+
23
+ HttpRequest request = HttpRequest.newBuilder()
24
+ .uri(URI.create(API_URL))
25
+ .header("Authorization", "Bearer " + API_TOKEN)
26
+ .header("Content-Type", "application/json")
27
+ .POST(BodyPublishers.ofString(requestBody))
28
+ .build();
29
+
30
+ HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
31
+
32
+ return response.body();
33
+ }
34
+ }