-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_connection.js
36 lines (30 loc) · 1021 Bytes
/
test_connection.js
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
async function testConnection() {
const llmServer = "http://localhost:11434";
const generateEndpoint = "/api/generate";
const parameters = {
model: "phi3",
prompt: "Why is the sky blue? Answer in one concise sentence."
};
try {
const response = await fetch(llmServer + generateEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(parameters)
});
if (!response.ok) {
const errorData = await response.json();
console.error('Server Error:', errorData);
throw new Error(`Server Error: ${errorData.message}`);
}
const result = await response.json();
console.log('LLM Response:', result);
return result.response;
} catch (error) {
console.error('Error:', error);
return 'An error occurred while communicating with the LLM server.';
}
}
// Call this function to test the connection
testConnection();