-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_simple_ai.java
More file actions
49 lines (42 loc) · 1.93 KB
/
test_simple_ai.java
File metadata and controls
49 lines (42 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import simu.framework.Trace;
import java.io.*;
import java.net.*;
import java.nio.charset.StandardCharsets;
public class test_simple_ai {
public static void main(String[] args) {
Trace.setTraceLevel(Trace.Level.INFO);
System.out.println("Testing direct HTTP request...");
try {
URL url = new URL("http://localhost:8000/generate");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoOutput(true);
conn.setConnectTimeout(10000);
conn.setReadTimeout(60000);
// Simple short prompt
String jsonInputString = "{\"prompt\": \"Apple AI investment?\", \"max_tokens\": 10}";
try (OutputStream os = conn.getOutputStream()) {
byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
int responseCode = conn.getResponseCode();
System.out.println("Response Code: " + responseCode);
if (responseCode == 200) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) {
StringBuilder response = new StringBuilder();
String responseLine;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
System.out.println("Response: " + response.toString());
}
} else {
System.out.println("❌ Request failed with status: " + responseCode);
}
} catch (Exception e) {
System.out.println("❌ Error: " + e.getMessage());
e.printStackTrace();
}
}
}