formatting

This commit is contained in:
PawelC4
2025-11-09 00:07:25 -05:00
parent 3686ae72da
commit 972df9b70b
15 changed files with 1283 additions and 1107 deletions
+56 -56
View File
@@ -1,71 +1,71 @@
import { GoogleGenerativeAI } from "@google/generative-ai";
import type { NextApiRequest, NextApiResponse } from 'next';
// import { GoogleGenerativeAI } from "@google/generative-ai";
// import type { NextApiRequest, NextApiResponse } from 'next';
// Initialize the Gemini Client with your API Key
// IMPORTANT: The GEMINI_API_KEY should be an environment variable.
const apiKey = process.env.GEMINI_API_KEY;
// // Initialize the Gemini Client with your API Key
// // IMPORTANT: The GEMINI_API_KEY should be an environment variable.
// const apiKey = process.env.GEMINI_API_KEY;
if(!apiKey){
throw new Error("api key not found");
}
const ai = new GoogleGenerativeAI(apiKey);
// if(!apiKey){
// throw new Error("api key not found");
// }
// const ai = new GoogleGenerativeAI(apiKey);
// Define the handler function for the API route
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
// Only allow POST requests
if (req.method !== 'POST') {
return res.status(405).json({ error: 'Method Not Allowed' });
}
// // Define the handler function for the API route
// export default async function handler(
// req: NextApiRequest,
// res: NextApiResponse
// ) {
// // Only allow POST requests
// if (req.method !== 'POST') {
// return res.status(405).json({ error: 'Method Not Allowed' });
// }
// Destructure the data sent from the frontend
let { prompt, settings } = req.body;
// // Destructure the data sent from the frontend
// let { prompt, settings } = req.body;
// Basic validation
if (!prompt || typeof prompt !== 'string') {
return res.status(400).json({ error: 'Prompt is required' });
}
// // Basic validation
// if (!prompt || typeof prompt !== 'string') {
// return res.status(400).json({ error: 'Prompt is required' });
// }
// Modify the prompt to instruct the AI to generate only the game, concept, and track
prompt = `You're going to fill out a card base off the document.
you will Generate the project short title.
you will list out the track you used ${prompt}`;
// // Modify the prompt to instruct the AI to generate only the game, concept, and track
// prompt = `You're going to fill out a card base off the document.
// you will Generate the project short title.
// you will list out the track you used ${prompt}`;
try {
// 1. Call the Gemini API using the correct method signature
// try {
// // 1. Call the Gemini API using the correct method signature
const model = settings?.model || 'gemini-2.5-flash-lite';
const generativeModel = ai.getGenerativeModel({ model });
// const model = settings?.model || 'gemini-2.5-flash-lite';
// const generativeModel = ai.getGenerativeModel({ model });
// 1. Define the generation configuration object
const generationConfig = {
temperature: settings?.temperature || 0.9,
// The SDK property name for system instructions is 'systemInstruction'
systemInstruction: settings?.sysTemInstructions,
};
// // 1. Define the generation configuration object
// const generationConfig = {
// temperature: settings?.temperature || 0.9,
// // The SDK property name for system instructions is 'systemInstruction'
// systemInstruction: settings?.sysTemInstructions,
// };
// 2. Call generateContent with the single GenerateContentRequest object.
const result = await generativeModel.generateContent({
// contents must be an array of Content objects
contents: [{
role: "user",
parts: [{ text: prompt }]
}],
// // 2. Call generateContent with the single GenerateContentRequest object.
// const result = await generativeModel.generateContent({
// // contents must be an array of Content objects
// contents: [{
// role: "user",
// parts: [{ text: prompt }]
// }],
// The fixed property name that resolves the TypeScript error
generationConfig: generationConfig,
});
// // The fixed property name that resolves the TypeScript error
// generationConfig: generationConfig,
// });
// 2. Extract the response text
// The result object now contains a property 'text' at the top level for simple text generation
const geminiResponseText = result.response.text(); res.status(200).json({ response: geminiResponseText });
// // 2. Extract the response text
// // The result object now contains a property 'text' at the top level for simple text generation
// const geminiResponseText = result.response.text(); res.status(200).json({ response: geminiResponseText });
} catch (error) {
console.error("Gemini API Error:", error);
res.status(500).json({ error: 'Failed to generate idea from AI.' });
}
}
// } catch (error) {
// console.error("Gemini API Error:", error);
// res.status(500).json({ error: 'Failed to generate idea from AI.' });
// }
// }