hellooooooo000 commited on
Commit
a73b70a
·
verified ·
1 Parent(s): 7c14ef9

// Error: Could not generate code. Please try again.

Browse files
Files changed (2) hide show
  1. script.js +14 -37
  2. style.css +1 -10
script.js CHANGED
@@ -34,41 +34,26 @@ document.addEventListener('DOMContentLoaded', () => {
34
  const prompt = `Create a ${tech} app that ${appDescription.value}`;
35
 
36
  // Call Gemini API
37
- const apiUrl = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=AIzaSyB0HOw6eHYRrqMJ_ZwcEdynMk2NdDfPnP4';
38
- const response = await fetch(apiUrl, {
 
 
 
39
  method: 'POST',
40
  headers: {
41
  'Content-Type': 'application/json',
42
  },
43
  body: JSON.stringify({
44
- contents: [{
45
- parts: [{
46
- text: prompt
47
- }]
48
- }]
 
49
  })
50
- });
51
-
52
  const data = await response.json();
53
- let generatedCode = "";
54
- if (!response.ok) {
55
- throw new Error(`API request failed with status ${response.status}`);
56
- }
57
-
58
- const data = await response.json();
59
- let generatedCode = "";
60
-
61
- try {
62
- if (data.candidates?.[0]?.content?.parts?.[0]?.text) {
63
- generatedCode = data.candidates[0].content.parts[0].text;
64
- } else {
65
- console.warn('Unexpected API response format:', data);
66
- throw new Error('Invalid API response format');
67
- }
68
- } catch (err) {
69
- generatedCode = `// Error: ${err.message}\n// Raw response: ${JSON.stringify(data, null, 2)}`;
70
- console.error('Error processing API response:', err);
71
- }
72
  // Display the code with typewriter effect
73
  typeWriterEffect(codeOutput, generatedCode, 10, () => {
74
  generateBtn.disabled = false;
@@ -85,15 +70,7 @@ typeWriterEffect(codeOutput, generatedCode, 10, () => {
85
  });
86
  } catch (error) {
87
  console.error('Error generating code:', error);
88
-
89
- // Create error message with more details
90
- const errorMsg = `Failed to generate code:\n\n${error.message}\n\nPlease check your input and try again.`;
91
-
92
- // Add error to chat
93
- addMessage(errorMsg, 'ai');
94
-
95
- // Show error in code output
96
- codeOutput.textContent = `// Error: ${error.message}\n// Please try again or modify your request`;
97
  generateBtn.disabled = false;
98
  generateBtn.innerHTML = '<i data-feather="code"></i> Generate My App';
99
  feather.replace();
 
34
  const prompt = `Create a ${tech} app that ${appDescription.value}`;
35
 
36
  // Call Gemini API
37
+ const response = await fetch('https://api.openai.com/v1/chat/completions', {
38
+ headers: {
39
+ 'Content-Type': 'application/json',
40
+ 'Authorization': 'Bearer sk-proj-abc123' // Replace with your OpenAI API key
41
+ },
42
  method: 'POST',
43
  headers: {
44
  'Content-Type': 'application/json',
45
  },
46
  body: JSON.stringify({
47
+ model: "gpt-3.5-turbo",
48
+ messages: [{
49
+ role: "user",
50
+ content: prompt
51
+ }],
52
+ temperature: 0.7
53
  })
54
+ });
 
55
  const data = await response.json();
56
+ let generatedCode = data.choices?.[0]?.message?.content || "// Error: No code generated";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  // Display the code with typewriter effect
58
  typeWriterEffect(codeOutput, generatedCode, 10, () => {
59
  generateBtn.disabled = false;
 
70
  });
71
  } catch (error) {
72
  console.error('Error generating code:', error);
73
+ alert('Échec de la génération du code. Veuillez réessayer. Détails dans la console.');
 
 
 
 
 
 
 
 
74
  generateBtn.disabled = false;
75
  generateBtn.innerHTML = '<i data-feather="code"></i> Generate My App';
76
  feather.replace();
style.css CHANGED
@@ -35,22 +35,13 @@ body {
35
  ::-webkit-scrollbar-thumb:hover {
36
  background: #555;
37
  }
38
- /* Error styles */
39
- #code-output {
40
- white-space: pre-wrap;
41
- }
42
-
43
- #code-output:has(> :contains("Error:")) {
44
- color: #ef4444;
45
- background-color: #fee2e2;
46
- border-left: 4px solid #ef4444;
47
- }
48
 
49
  /* Tech choice buttons */
50
  .tech-choice {
51
  transition: all 0.2s ease;
52
  cursor: pointer;
53
  }
 
54
  .tech-choice.active {
55
  background-color: #6366f1;
56
  color: white;
 
35
  ::-webkit-scrollbar-thumb:hover {
36
  background: #555;
37
  }
 
 
 
 
 
 
 
 
 
 
38
 
39
  /* Tech choice buttons */
40
  .tech-choice {
41
  transition: all 0.2s ease;
42
  cursor: pointer;
43
  }
44
+
45
  .tech-choice.active {
46
  background-color: #6366f1;
47
  color: white;