UNPKG

dragadix

Version:

A flirty, powerful CLI experience built by Aditya 💋

58 lines (46 loc) 1.76 kB
import inquirer from "inquirer"; import chalk from "chalk"; import axios from "axios"; import { config } from "../config.js"; export async function startAIChat() { const apiKey = config?.ai?.geminiApiKey; if (!apiKey) { console.log(chalk.red("❌ Gemini API key not found in config.js")); return; } const model = "gemini-1.5-flash"; // Use gemini-1.5-pro if preferred const apiUrl = `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=${apiKey}`; console.log(chalk.cyan("\n💬 Gemini Chat Mode Activated! Ask anything, baby... (type 'exit' to quit)\n")); while (true) { try { const { question } = await inquirer.prompt([ { type: "input", name: "question", message: chalk.magenta("You: "), } ]); if (!question.trim()) continue; if (question.toLowerCase() === "exit") break; const res = await axios.post( apiUrl, { contents: [{ role: "user", parts: [{ text: question }] }] }, { headers: { "Content-Type": "application/json" } } ); const reply = res?.data?.candidates?.[0]?.content?.parts?.[0]?.text; if (!reply) { console.log(chalk.yellow("\n🤔 Gemini didn’t respond. Maybe try again with something juicy?\n")); continue; } console.log(chalk.greenBright(`\nGemini 💎: ${reply}\n`)); } catch (err) { const errMsg = err?.response?.data?.error?.message || err?.message || "Unknown error occurred"; console.log(chalk.redBright(`\n🚫 Oops! Something went wrong, babe:\n${errMsg}\n`)); } } console.log(chalk.blueBright("👋 Bye bye, lover. Come chat with me again soon 💋")); }