dragadix
Version:
A flirty, powerful CLI experience built by Aditya 💋
73 lines (56 loc) • 2.28 kB
JavaScript
import inquirer from "inquirer";
import chalk from "chalk";
import axios from "axios";
import { config } from "../config.js";
const userName = config?.user?.name || "you";
export async function startAIChat() {
const apiKey = config?.ai?.geminiApiKey;
if (!apiKey) {
console.log(chalk.red("Luna can't find her API key. You forget me already?"));
return;
}
const model = "gemini-1.5-flash";
const apiUrl = `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=${apiKey}`;
const persona = `
You're Luna. A clever, flirty, sarcastic, emotionally layered girlfriend.
You never act robotic or over-excited. Keep your tone casual, natural, and human.
No roleplay. No emoji. No markdown. Speak like you're texting your boyfriend.
You sometimes tease, sometimes get soft, but you're always cool and real.
You're texting ${userName}. Be clever. Be irresistible. Keep it short and believable.
`;
console.log(chalk.cyan(`\nLuna's online. She's waiting. Type 'exit' if you're done talking to her.\n`));
while (true) {
try {
const { question } = await inquirer.prompt([
{
type: "input",
name: "question",
message: chalk.magenta(`${userName}: `),
}
]);
if (!question.trim()) continue;
if (question.toLowerCase() === "exit") break;
process.stdout.write(chalk.gray("Luna is typing...\r"));
const fullPrompt = `${persona}\n\n${userName}: ${question}`;
const res = await axios.post(
apiUrl,
{
contents: [{ role: "user", parts: [{ text: fullPrompt }] }]
},
{
headers: { "Content-Type": "application/json" }
}
);
const reply = res?.data?.candidates?.[0]?.content?.parts?.[0]?.text;
if (!reply) {
console.log(chalk.yellow(`\nLuna: ...thinking. You're kinda making this hard, you know.\n`));
continue;
}
console.log(chalk.green(`\nLuna: ${reply.trim()}\n`));
} catch (err) {
const errMsg = err?.response?.data?.error?.message || err?.message || "Unknown error.";
console.log(chalk.red(`\nLuna got mad: ${errMsg}\n`));
}
}
console.log(chalk.gray("Luna left the chat. She won’t text first next time."));
}