hellooooooo000 commited on
Commit
70adee4
·
verified ·
1 Parent(s): a73b70a

// Error: No code generated

Browse files

faut bien que ça envoie la requete à gemini qui met le code

Files changed (1) hide show
  1. script.js +13 -16
script.js CHANGED
@@ -32,28 +32,22 @@ document.addEventListener('DOMContentLoaded', () => {
32
  try {
33
  const tech = document.querySelector('.tech-choice.active').textContent;
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;
@@ -65,8 +59,11 @@ typeWriterEffect(codeOutput, generatedCode, 10, () => {
65
  chatSection.classList.remove('hidden');
66
 
67
  // Update preview iframe
68
- const blob = new Blob([generatedCode], {type: 'text/html'});
69
- previewFrame.src = URL.createObjectURL(blob);
 
 
 
70
  });
71
  } catch (error) {
72
  console.error('Error generating code:', error);
 
32
  try {
33
  const tech = document.querySelector('.tech-choice.active').textContent;
34
  const prompt = `Create a ${tech} app that ${appDescription.value}`;
 
35
  // Call Gemini API
36
+ const response = await fetch('https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=YOUR_API_KEY', {
37
+ method: 'POST',
 
 
 
 
38
  headers: {
39
  'Content-Type': 'application/json',
40
  },
41
  body: JSON.stringify({
42
+ contents: [{
43
+ parts: [{
44
+ text: prompt
45
+ }]
46
+ }]
 
47
  })
48
  });
49
  const data = await response.json();
50
+ let generatedCode = data.candidates?.[0]?.content?.parts?.[0]?.text || "// Error: No code generated";
51
  // Display the code with typewriter effect
52
  typeWriterEffect(codeOutput, generatedCode, 10, () => {
53
  generateBtn.disabled = false;
 
59
  chatSection.classList.remove('hidden');
60
 
61
  // Update preview iframe
62
+ // Extract just the code block if present
63
+ const codeMatch = generatedCode.match(/```[a-zA-Z]*\n([\s\S]*?)\n```/);
64
+ const codeToShow = codeMatch ? codeMatch[1] : generatedCode;
65
+ const blob = new Blob([codeToShow], {type: 'text/html'});
66
+ previewFrame.src = URL.createObjectURL(blob);
67
  });
68
  } catch (error) {
69
  console.error('Error generating code:', error);