@dj-bot07/ai-chat-cli
v1.0.6
Published
A CLI and programmatic interface for chatting with AI using Gemini
Readme
Gemini CLI Chat Bot
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!
Features
- 🤖 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
Installation
Global Installation (for CLI usage)
npm install -g @dj-bot07/ai-chat-cliLocal Installation (for programmatic usage)
npm install @dj-bot07/ai-chat-cliSetup
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
.envfile 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"CLI Usage
Interactive Chat Session
Start an interactive chat session where you can have a conversation with the AI:
gchat chatIn chat mode:
- Type your messages and press Enter to send
- Type 'exit' to end the session
- The chat maintains context of your conversation
Quick Questions
Ask a single question and get an immediate response:
gchat ask "What is the capital of France?"Programmatic Usage
Basic Usage
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);
}Chat Session
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();With Environment Variables
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);Error Handling
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);
}
}TypeScript Support
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()
};
}Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
ISC
Support
If you encounter any issues or have questions, please file an issue on the GitHub repository.
