Spaces:
Running
Running
Update index.html
Browse files- index.html +26 -11
index.html
CHANGED
@@ -20,10 +20,10 @@
|
|
20 |
<textarea id="url" placeholder="EndPoint URL" style="width: 400px;">https://api-inference.huggingface.co/models/mistralai/Mistral-Nemo-Instruct-2407</textarea>
|
21 |
<textarea id="fetchParamsOptions" placeholder="fetchParamsOptions" style="width: 600px;">
|
22 |
{
|
23 |
-
"inputs": "You are
|
24 |
"parameters": {
|
25 |
-
"temperature": 0.
|
26 |
-
"max_length":
|
27 |
}
|
28 |
}</textarea>
|
29 |
<textarea id="API-KEY" placeholder="API-KEY" style="width: 400px;"></textarea><br>
|
@@ -43,6 +43,7 @@
|
|
43 |
let typingstatus = false;
|
44 |
let MAX_RESPONSES = 250;
|
45 |
let aiResponseCounter = 0;
|
|
|
46 |
|
47 |
function typeWriterForTerminal(text, onComplete) {
|
48 |
const terminal = document.getElementById('terminal');
|
@@ -74,6 +75,16 @@
|
|
74 |
}
|
75 |
}
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
function handleSubmit(event) {
|
78 |
if (event) event.preventDefault();
|
79 |
|
@@ -102,14 +113,7 @@
|
|
102 |
},
|
103 |
body: JSON.stringify(fetchParamsOptions)
|
104 |
})
|
105 |
-
.then(
|
106 |
-
if (!response.ok) {
|
107 |
-
return response.text().then(body => {
|
108 |
-
throw new Error('Failed to load resource: Server response status: ' + response.status + ', Response body: ' + body);
|
109 |
-
});
|
110 |
-
}
|
111 |
-
return response.json();
|
112 |
-
})
|
113 |
.then(data => {
|
114 |
const responseText = (data.generated_text) ? data.generated_text.trim() : '';
|
115 |
typeWriterForTerminal(responseText, () => {
|
@@ -128,6 +132,17 @@
|
|
128 |
handleSubmit();
|
129 |
}
|
130 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
});
|
132 |
}
|
133 |
|
|
|
20 |
<textarea id="url" placeholder="EndPoint URL" style="width: 400px;">https://api-inference.huggingface.co/models/mistralai/Mistral-Nemo-Instruct-2407</textarea>
|
21 |
<textarea id="fetchParamsOptions" placeholder="fetchParamsOptions" style="width: 600px;">
|
22 |
{
|
23 |
+
"inputs": "You are Mistral Instruct.",
|
24 |
"parameters": {
|
25 |
+
"temperature": 0.2,
|
26 |
+
"max_length": 512
|
27 |
}
|
28 |
}</textarea>
|
29 |
<textarea id="API-KEY" placeholder="API-KEY" style="width: 400px;"></textarea><br>
|
|
|
43 |
let typingstatus = false;
|
44 |
let MAX_RESPONSES = 250;
|
45 |
let aiResponseCounter = 0;
|
46 |
+
const RETRY_INTERVAL = 10000; // 10 seconds
|
47 |
|
48 |
function typeWriterForTerminal(text, onComplete) {
|
49 |
const terminal = document.getElementById('terminal');
|
|
|
75 |
}
|
76 |
}
|
77 |
|
78 |
+
function handleResponse(response) {
|
79 |
+
return response.json().then(data => {
|
80 |
+
if (response.ok) {
|
81 |
+
return data;
|
82 |
+
} else {
|
83 |
+
throw new Error(data.error || 'Request failed');
|
84 |
+
}
|
85 |
+
});
|
86 |
+
}
|
87 |
+
|
88 |
function handleSubmit(event) {
|
89 |
if (event) event.preventDefault();
|
90 |
|
|
|
113 |
},
|
114 |
body: JSON.stringify(fetchParamsOptions)
|
115 |
})
|
116 |
+
.then(handleResponse)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
.then(data => {
|
118 |
const responseText = (data.generated_text) ? data.generated_text.trim() : '';
|
119 |
typeWriterForTerminal(responseText, () => {
|
|
|
132 |
handleSubmit();
|
133 |
}
|
134 |
});
|
135 |
+
})
|
136 |
+
.catch(error => {
|
137 |
+
console.error("Error:", error);
|
138 |
+
if (error.message.includes("currently loading")) {
|
139 |
+
setTimeout(handleSubmit, RETRY_INTERVAL);
|
140 |
+
} else {
|
141 |
+
typeWriterForTerminal("An error occurred: " + error.message);
|
142 |
+
}
|
143 |
+
})
|
144 |
+
.finally(() => {
|
145 |
+
loader.style.display = 'none';
|
146 |
});
|
147 |
}
|
148 |
|