|
|
| const promptInput = document.getElementById("prompt");
|
| const generateButton = document.getElementById("generate");
|
| const outputDiv = document.getElementById("output");
|
|
|
|
|
| const GEMINI_API_KEY = "AIzaSyBlkMn-zVlQyOERE4cLjnI-d24eMf5slGo";
|
| const GEMINI_API_URL = "https://api.gemini.com/v1/your-endpoint";
|
|
|
|
|
| generateButton.addEventListener("click", async () => {
|
| const prompt = promptInput.value;
|
|
|
| if (!prompt) {
|
| outputDiv.textContent = "Please enter a topic or prompt!";
|
| return;
|
| }
|
|
|
|
|
| outputDiv.textContent = "Generating your article...";
|
|
|
| try {
|
|
|
| const response = await fetch(GEMINI_API_URL, {
|
| method: "POST",
|
| headers: {
|
| "Content-Type": "application/json",
|
| "Authorization": `Bearer ${GEMINI_API_KEY}`,
|
| },
|
| body: JSON.stringify({
|
| prompt: prompt,
|
| max_tokens: 500,
|
| }),
|
| });
|
|
|
|
|
| if (!response.ok) {
|
| throw new Error(`Error: ${response.statusText}`);
|
| }
|
|
|
|
|
| const data = await response.json();
|
| const article = data.choices[0].text;
|
|
|
|
|
| outputDiv.textContent = article;
|
| } catch (error) {
|
|
|
| outputDiv.textContent = `An error occurred: ${error.message}`;
|
| }
|
| });
|
|
|