A powerful command-line interface and programmatic API for chatting with AI using Google's Gemini model. Have interactive conversations or get quick answers right from your terminal!
- 🤖 Interactive chat sessions with memory
- 💡 Quick single-question mode
- 🎨 Beautiful CLI interface with loading spinners
- 📦 Easy-to-use programmatic API
- 🔧 TypeScript support
- 🚀 Built on Google's Gemini AI model
npm install -g @dj-bot07/ai-chat-cli
npm install @dj-bot07/ai-chat-cli
Before using the package, you'll need a Gemini API key from Google. You can get one from the Google AI Studio.
There are two ways to set up your API key:
- Create a
.env
file in your project root:
GEMINI_API_KEY=your_api_key_here
- Set it as an environment variable:
# Windows (PowerShell)
$env:GEMINI_API_KEY="your_api_key_here"
# Linux/MacOS
export GEMINI_API_KEY="your_api_key_here"
Start an interactive chat session where you can have a conversation with the AI:
gchat chat
In chat mode:
- Type your messages and press Enter to send
- Type 'exit' to end the session
- The chat maintains context of your conversation
Ask a single question and get an immediate response:
gchat ask "What is the capital of France?"
import { AIService } from 'gemini-cli-chat-bot-dj';
// Initialize with your API key
const aiService = new AIService('your_api_key_here');
// Ask a single question
try {
const response = await aiService.chat('What is the capital of France?');
console.log(response);
} catch (error) {
console.error('Error:', error.message);
}
import { AIService } from 'gemini-cli-chat-bot-dj';
async function chatExample() {
const aiService = new AIService('your_api_key_here');
// Start a chat session
const chatSession = await aiService.startChat();
try {
// Send multiple messages in the same context
const response1 = await chatSession.sendMessage('Tell me about Paris.');
console.log('AI:', response1);
const response2 = await chatSession.sendMessage('What about its famous landmarks?');
console.log('AI:', response2);
} catch (error) {
console.error('Error:', error.message);
}
}
chatExample();
import dotenv from 'dotenv';
import { AIService } from 'gemini-cli-chat-bot-dj';
// Load environment variables from .env file
dotenv.config();
const aiService = new AIService(process.env.GEMINI_API_KEY);
The package includes built-in error handling for common issues:
try {
const response = await aiService.chat('Your question here');
console.log(response);
} catch (error) {
if (error.message.includes('API key')) {
console.error('Invalid or missing API key');
} else {
console.error('An error occurred:', error.message);
}
}
The package is written in TypeScript and includes type definitions. You get full type support out of the box:
import { AIService } from 'gemini-cli-chat-bot-dj';
const aiService = new AIService(process.env.GEMINI_API_KEY!);
interface ChatResponse {
text: string;
timestamp: Date;
}
async function getResponse(): Promise<ChatResponse> {
const response = await aiService.chat('Hello!');
return {
text: response,
timestamp: new Date()
};
}
Contributions are welcome! Please feel free to submit a Pull Request.
ISC
If you encounter any issues or have questions, please file an issue on the GitHub repository.