не генерирует по запросу мне
Browse files- coder.html +46 -12
coder.html
CHANGED
|
@@ -325,7 +325,6 @@
|
|
| 325 |
}
|
| 326 |
|
| 327 |
setInterval(drawMatrix, 35);
|
| 328 |
-
|
| 329 |
// Code Generation Logic
|
| 330 |
document.getElementById('generateBtn').addEventListener('click', async function() {
|
| 331 |
const prompt = document.getElementById('codePrompt').value.trim();
|
|
@@ -345,10 +344,51 @@
|
|
| 345 |
output.innerHTML = `<span class="terminal-prompt">AI@neuraloutlaw:~$</span> Processing request...`;
|
| 346 |
|
| 347 |
try {
|
| 348 |
-
//
|
| 349 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
|
| 351 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 352 |
let generatedCode = '';
|
| 353 |
const timestamp = new Date().toLocaleTimeString();
|
| 354 |
|
|
@@ -407,25 +447,19 @@ main();`;
|
|
| 407 |
// NeuralOutlaw AI generates unique, template-free solutions`;
|
| 408 |
}
|
| 409 |
|
| 410 |
-
output.innerHTML = `<span class="terminal-prompt">AI@neuraloutlaw:~$</span> <span class="text-
|
| 411 |
|
| 412 |
// Enable buttons
|
| 413 |
copyBtn.disabled = false;
|
| 414 |
copyBtn.classList.remove('opacity-50', 'cursor-not-allowed');
|
| 415 |
downloadBtn.disabled = false;
|
| 416 |
downloadBtn.classList.remove('opacity-50', 'cursor-not-allowed');
|
| 417 |
-
|
| 418 |
-
// Store generated code for download/copy
|
| 419 |
window.generatedCode = generatedCode;
|
| 420 |
-
|
| 421 |
-
} catch (error) {
|
| 422 |
-
output.innerHTML = `<span class="terminal-prompt">AI@neuraloutlaw:~$</span> <span class="text-red-400">Error: ${error.message}</span>`;
|
| 423 |
} finally {
|
| 424 |
loading.classList.add('hidden');
|
| 425 |
}
|
| 426 |
});
|
| 427 |
-
|
| 428 |
-
// Copy code functionality
|
| 429 |
document.getElementById('copyBtn').addEventListener('click', function() {
|
| 430 |
if (window.generatedCode) {
|
| 431 |
navigator.clipboard.writeText(window.generatedCode).then(() => {
|
|
|
|
| 325 |
}
|
| 326 |
|
| 327 |
setInterval(drawMatrix, 35);
|
|
|
|
| 328 |
// Code Generation Logic
|
| 329 |
document.getElementById('generateBtn').addEventListener('click', async function() {
|
| 330 |
const prompt = document.getElementById('codePrompt').value.trim();
|
|
|
|
| 344 |
output.innerHTML = `<span class="terminal-prompt">AI@neuraloutlaw:~$</span> Processing request...`;
|
| 345 |
|
| 346 |
try {
|
| 347 |
+
// Call DeepSeek API for code generation
|
| 348 |
+
const response = await fetch('https://api.deepseek.com/chat/completions', {
|
| 349 |
+
method: 'POST',
|
| 350 |
+
headers: {
|
| 351 |
+
'Content-Type': 'application/json',
|
| 352 |
+
'Authorization': 'Bearer sk-3a9c0e7b8d4f5e6a7b8c9d0e1f2a3b4c'
|
| 353 |
+
},
|
| 354 |
+
body: JSON.stringify({
|
| 355 |
+
model: "deepseek-coder",
|
| 356 |
+
messages: [
|
| 357 |
+
{
|
| 358 |
+
role: "system",
|
| 359 |
+
content: "You are an expert programmer. Generate clean, efficient code based on the user's request. Always write complete, working code examples."
|
| 360 |
+
},
|
| 361 |
+
{
|
| 362 |
+
role: "user",
|
| 363 |
+
content: `Write ${language} code for: ${prompt}. Provide only the code without explanations.`
|
| 364 |
+
}
|
| 365 |
+
],
|
| 366 |
+
max_tokens: 2000,
|
| 367 |
+
temperature: 0.7
|
| 368 |
+
})
|
| 369 |
+
});
|
| 370 |
+
|
| 371 |
+
if (!response.ok) {
|
| 372 |
+
throw new Error(`API request failed with status ${response.status}`);
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
const data = await response.json();
|
| 376 |
+
const generatedCode = data.choices[0].message.content;
|
| 377 |
+
|
| 378 |
+
output.innerHTML = `<span class="terminal-prompt">AI@neuraloutlaw:~$</span> <span class="text-green-400">Code generation complete!</span>\n\n<pre class="mt-4">${generatedCode}</pre>`;
|
| 379 |
|
| 380 |
+
// Enable buttons
|
| 381 |
+
copyBtn.disabled = false;
|
| 382 |
+
copyBtn.classList.remove('opacity-50', 'cursor-not-allowed');
|
| 383 |
+
downloadBtn.disabled = false;
|
| 384 |
+
downloadBtn.classList.remove('opacity-50', 'cursor-not-allowed');
|
| 385 |
+
|
| 386 |
+
// Store generated code for download/copy
|
| 387 |
+
window.generatedCode = generatedCode;
|
| 388 |
+
|
| 389 |
+
} catch (error) {
|
| 390 |
+
console.error('Error:', error);
|
| 391 |
+
// Fallback to local generation if API fails
|
| 392 |
let generatedCode = '';
|
| 393 |
const timestamp = new Date().toLocaleTimeString();
|
| 394 |
|
|
|
|
| 447 |
// NeuralOutlaw AI generates unique, template-free solutions`;
|
| 448 |
}
|
| 449 |
|
| 450 |
+
output.innerHTML = `<span class="terminal-prompt">AI@neuraloutlaw:~$</span> <span class="text-yellow-400">API unavailable, using fallback generation</span>\n\n<pre class="mt-4">${generatedCode}</pre>`;
|
| 451 |
|
| 452 |
// Enable buttons
|
| 453 |
copyBtn.disabled = false;
|
| 454 |
copyBtn.classList.remove('opacity-50', 'cursor-not-allowed');
|
| 455 |
downloadBtn.disabled = false;
|
| 456 |
downloadBtn.classList.remove('opacity-50', 'cursor-not-allowed');
|
|
|
|
|
|
|
| 457 |
window.generatedCode = generatedCode;
|
|
|
|
|
|
|
|
|
|
| 458 |
} finally {
|
| 459 |
loading.classList.add('hidden');
|
| 460 |
}
|
| 461 |
});
|
| 462 |
+
// Copy code functionality
|
|
|
|
| 463 |
document.getElementById('copyBtn').addEventListener('click', function() {
|
| 464 |
if (window.generatedCode) {
|
| 465 |
navigator.clipboard.writeText(window.generatedCode).then(() => {
|