-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api.html
More file actions
53 lines (45 loc) · 1.82 KB
/
Copy pathtest-api.html
File metadata and controls
53 lines (45 loc) · 1.82 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
50
51
52
53
<!DOCTYPE html>
<html>
<head>
<title>API Test</title>
</head>
<body>
<h1>Testing LLM API</h1>
<button onclick="testAPI()">Test API</button>
<div id="result"></div>
<script>
async function testAPI() {
const prompt = "Generate 2 quiz questions about Binary Search in JSON format.";
const API_URL = 'https://api-inference.huggingface.co/models/microsoft/DialoGPT-large';
try {
console.log('Testing API with prompt:', prompt);
const response = await fetch(API_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
inputs: prompt,
parameters: {
max_length: 1000,
temperature: 0.7,
do_sample: true
}
})
});
console.log('Response status:', response.status);
console.log('Response headers:', response.headers);
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const data = await response.json();
console.log('Response data:', data);
document.getElementById('result').innerHTML = '<pre>' + JSON.stringify(data, null, 2) + '</pre>';
} catch (error) {
console.error('Error:', error);
document.getElementById('result').innerHTML = '<p style="color: red;">Error: ' + error.message + '</p>';
}
}
</script>
</body>
</html>