aringad commited on
Commit
28048a3
1 Parent(s): 0d4d60e

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +15 -5
index.html CHANGED
@@ -37,10 +37,14 @@
37
  });
38
 
39
  function generateText(prompt) {
40
- const apiUrl = 'https://aringad-test.hf.space/run';
 
 
41
  const requestData = {
42
- prompt: prompt,
43
- model: 'OpenBuddy/openbuddy-llama3-8b-v21.1-8k'
 
 
44
  };
45
 
46
  // Display request data in the debug output
@@ -49,7 +53,8 @@
49
  fetch(apiUrl, {
50
  method: 'POST',
51
  headers: {
52
- 'Content-Type': 'application/json'
 
53
  },
54
  body: JSON.stringify(requestData)
55
  })
@@ -57,12 +62,17 @@
57
  // Display response status and headers in the debug output
58
  document.getElementById('debugOutput').textContent += '\n\nResponse Status: ' + response.status;
59
  document.getElementById('debugOutput').textContent += '\nResponse Headers:\n' + JSON.stringify(Object.fromEntries(response.headers), null, 2);
 
 
 
 
 
60
  return response.json();
61
  })
62
  .then(data => {
63
  // Display response data in the debug output
64
  document.getElementById('debugOutput').textContent += '\n\nResponse Data:\n' + JSON.stringify(data, null, 2);
65
- const generatedText = data.output;
66
  document.getElementById('generatedText').textContent = generatedText;
67
  document.getElementById('resultContainer').style.display = 'block';
68
  })
 
37
  });
38
 
39
  function generateText(prompt) {
40
+ const apiUrl = 'https://api-inference.huggingface.co/models/OpenBuddy/openbuddy-llama3-8b-v21.1-8k';
41
+ const apiKey = '{{API_KEY}}'; // La chiave API verrà sostituita dalla variabile d'ambiente
42
+
43
  const requestData = {
44
+ inputs: prompt,
45
+ parameters: {
46
+ max_new_tokens: 100
47
+ }
48
  };
49
 
50
  // Display request data in the debug output
 
53
  fetch(apiUrl, {
54
  method: 'POST',
55
  headers: {
56
+ 'Content-Type': 'application/json',
57
+ 'Authorization': 'Bearer ' + apiKey
58
  },
59
  body: JSON.stringify(requestData)
60
  })
 
62
  // Display response status and headers in the debug output
63
  document.getElementById('debugOutput').textContent += '\n\nResponse Status: ' + response.status;
64
  document.getElementById('debugOutput').textContent += '\nResponse Headers:\n' + JSON.stringify(Object.fromEntries(response.headers), null, 2);
65
+
66
+ if (!response.ok) {
67
+ throw new Error('Request failed with status: ' + response.status);
68
+ }
69
+
70
  return response.json();
71
  })
72
  .then(data => {
73
  // Display response data in the debug output
74
  document.getElementById('debugOutput').textContent += '\n\nResponse Data:\n' + JSON.stringify(data, null, 2);
75
+ const generatedText = data[0].generated_text;
76
  document.getElementById('generatedText').textContent = generatedText;
77
  document.getElementById('resultContainer').style.display = 'block';
78
  })