Spaces:
Running
Running
| /* // aiEngine.js | |
| import { GoogleGenAI } from '@google/genai'; | |
| /* import dotenv from 'dotenv'; | |
| dotenv.config(); | |
| */ | |
| const genAI = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY }); | |
| console.log(process.env.GEMINI_API_KEY); | |
| // Prompt Loader | |
| import fs from 'fs'; | |
| const prompts = JSON.parse(fs.readFileSync('./prompts.json', 'utf8')); | |
| export const AIEngine = { | |
| /** | |
| * PM MODEL (Gemini 3.0 Pro Preview - High Thinking) | |
| */ | |
| callPM: async (history, input) => { | |
| const modelId = 'gemini-3-pro-preview'; // Per prompt requirements | |
| const config = { | |
| thinkingConfig: { thinkingLevel: 'HIGH' }, | |
| tools: [{ | |
| systemInstruction: [{ | |
| text: prompts.pm_system_prompt | |
| }], | |
| googleSearch: {} }], | |
| }; | |
| const contents = [ | |
| { role: 'user', parts: [{ text: prompts.pm_system_prompt }] }, // System instruction injection | |
| ...history, | |
| { role: 'user', parts: [{ text: input }] } | |
| ]; | |
| try { | |
| const response = await genAI.models.generateContent({ | |
| model: modelId, | |
| config, | |
| contents, | |
| }); | |
| return response.text; // Simple text return for non-stream internal logic | |
| } catch (error) { | |
| console.error("PM AI Error:", error); | |
| throw error; | |
| } | |
| }, | |
| /** | |
| * WORKER MODEL (Gemini 2.5 Flash - Fast execution) | |
| */ | |
| callWorker: async (history, input, imagePart = null) => { | |
| /* const modelId = 'gemini-flash-latest'; // Per prompt requirements | |
| const config = { | |
| thinkingConfig: { thinkingBudget: -1 }, // Standard generation | |
| */ | |
| const modelId = 'gemini-3-pro-preview'; // Per prompt requirements | |
| const config = { | |
| thinkingConfig: { thinkingLevel: 'HIGH' }, | |
| tools: [{ | |
| systemInstruction: [{ | |
| text: prompts.worker_system_prompt | |
| }], | |
| googleSearch: {} }], | |
| }; | |
| const currentParts = [{ text: input }]; | |
| if (imagePart) { | |
| currentParts.push(imagePart); | |
| } | |
| const contents = [ | |
| { role: 'user', parts: [{ text: prompts.worker_system_prompt }] }, | |
| ...history, | |
| { role: 'user', parts: currentParts } | |
| ]; | |
| try { | |
| const response = await genAI.models.generateContent({ | |
| model: modelId, | |
| config, | |
| contents, | |
| }); | |
| return response.text; | |
| } catch (error) { | |
| console.error("Worker AI Error:", error); | |
| throw error; | |
| } | |
| } | |
| }; |