Spaces:
Running
Running
Update static/script.js
Browse files- static/script.js +16 -14
static/script.js
CHANGED
|
@@ -2145,33 +2145,33 @@ function callOpenAIAPI(prompt) {
|
|
| 2145 |
}
|
| 2146 |
}
|
| 2147 |
|
| 2148 |
-
|
| 2149 |
-
|
| 2150 |
-
|
| 2151 |
-
// Add custom model API call function
|
| 2152 |
function callcustomAPI(prompt) {
|
| 2153 |
const apiUrl = document.getElementById('custom_api_url').value.trim();
|
| 2154 |
const apiKey = document.getElementById('api_key').value.trim();
|
| 2155 |
const modelName = document.getElementById('custom_model_name').value.trim();
|
| 2156 |
|
|
|
|
| 2157 |
const requestBody = {
|
|
|
|
|
|
|
| 2158 |
model: modelName,
|
| 2159 |
-
|
| 2160 |
-
|
| 2161 |
-
]
|
| 2162 |
};
|
| 2163 |
|
| 2164 |
-
fetch(
|
| 2165 |
method: 'POST',
|
| 2166 |
headers: {
|
| 2167 |
-
'Content-Type': 'application/json'
|
| 2168 |
-
'Authorization': `Bearer ${apiKey}`
|
| 2169 |
},
|
| 2170 |
body: JSON.stringify(requestBody)
|
| 2171 |
})
|
| 2172 |
.then(response => {
|
| 2173 |
if (!response.ok) {
|
| 2174 |
-
|
|
|
|
|
|
|
| 2175 |
}
|
| 2176 |
return response.json();
|
| 2177 |
})
|
|
@@ -2179,7 +2179,11 @@ function callcustomAPI(prompt) {
|
|
| 2179 |
// Clear safety timeout when API call succeeds
|
| 2180 |
clearSafetyTimeout();
|
| 2181 |
|
| 2182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2183 |
processAPIResponse(content);
|
| 2184 |
})
|
| 2185 |
.catch(error => {
|
|
@@ -2194,8 +2198,6 @@ function callcustomAPI(prompt) {
|
|
| 2194 |
});
|
| 2195 |
}
|
| 2196 |
|
| 2197 |
-
|
| 2198 |
-
|
| 2199 |
// Process API response
|
| 2200 |
function processAPIResponse(response) {
|
| 2201 |
try {
|
|
|
|
| 2145 |
}
|
| 2146 |
}
|
| 2147 |
|
| 2148 |
+
// Add custom model API call function (routed through backend to avoid CORS)
|
|
|
|
|
|
|
|
|
|
| 2149 |
function callcustomAPI(prompt) {
|
| 2150 |
const apiUrl = document.getElementById('custom_api_url').value.trim();
|
| 2151 |
const apiKey = document.getElementById('api_key').value.trim();
|
| 2152 |
const modelName = document.getElementById('custom_model_name').value.trim();
|
| 2153 |
|
| 2154 |
+
// Route through backend proxy to avoid CORS issues
|
| 2155 |
const requestBody = {
|
| 2156 |
+
session_id: sessionId,
|
| 2157 |
+
prompt: prompt,
|
| 2158 |
model: modelName,
|
| 2159 |
+
api_url: apiUrl,
|
| 2160 |
+
api_key: apiKey
|
|
|
|
| 2161 |
};
|
| 2162 |
|
| 2163 |
+
fetch('/api/custom_model_inference', {
|
| 2164 |
method: 'POST',
|
| 2165 |
headers: {
|
| 2166 |
+
'Content-Type': 'application/json'
|
|
|
|
| 2167 |
},
|
| 2168 |
body: JSON.stringify(requestBody)
|
| 2169 |
})
|
| 2170 |
.then(response => {
|
| 2171 |
if (!response.ok) {
|
| 2172 |
+
return response.json().then(err => {
|
| 2173 |
+
throw new Error(err.error || `API request failed: ${response.status}`);
|
| 2174 |
+
});
|
| 2175 |
}
|
| 2176 |
return response.json();
|
| 2177 |
})
|
|
|
|
| 2179 |
// Clear safety timeout when API call succeeds
|
| 2180 |
clearSafetyTimeout();
|
| 2181 |
|
| 2182 |
+
if (data.error) {
|
| 2183 |
+
throw new Error(data.error);
|
| 2184 |
+
}
|
| 2185 |
+
|
| 2186 |
+
const content = data.response;
|
| 2187 |
processAPIResponse(content);
|
| 2188 |
})
|
| 2189 |
.catch(error => {
|
|
|
|
| 2198 |
});
|
| 2199 |
}
|
| 2200 |
|
|
|
|
|
|
|
| 2201 |
// Process API response
|
| 2202 |
function processAPIResponse(response) {
|
| 2203 |
try {
|