Adding AI Agents to everything with Time Machines - OpenAI ChatGPT Integration
AI-Time-Machines is a powerful integration that brings OpenAI's ChatGPT capabilities to your applications. This repository provides a clean, easy-to-use wrapper for interacting with the OpenAI API, enabling advanced AI-powered conversations and automation.
Before you begin, ensure you have the following installed:
- Node.js (version 18.0.0 or higher)
- npm (comes with Node.js)
- OpenAI API Key (requires an OpenAI account)
git clone https://github.com/lippytm/AI-Time-Machines.git
cd AI-Time-Machinesnpm install- Create an account or log in at OpenAI Platform
- Navigate to API Keys
- Click "Create new secret key"
- Copy your API key (you won't be able to see it again!)
- Copy the example environment file:
cp .env.example .env- Open
.envand replaceyour_openai_api_key_herewith your actual API key:
OPENAI_API_KEY=sk-your-actual-api-key-here.env file to version control. It's already included in .gitignore.
Run the included examples to test your setup:
npm startThis will execute several example interactions with ChatGPT, demonstrating:
- Simple chat messages
- Conversations with context
- Custom parameters (temperature, max_tokens)
const { ChatGPT } = require('./src/index');
// Initialize ChatGPT
const chatgpt = new ChatGPT();
// Simple chat
async function example() {
const response = await chatgpt.chat('Hello, ChatGPT!');
console.log(response);
}
// Conversation with context
async function conversationExample() {
const messages = [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What is AI?' }
];
const response = await chatgpt.conversation(messages);
console.log(response);
}Send a single message to ChatGPT.
- message (string): The message to send
- options (object, optional):
model: The model to use (default: 'gpt-4')temperature: Controls randomness, 0-1 (default: 0.7)max_tokens: Maximum response length (default: 1000)
Have a conversation with context.
- messages (array): Array of message objects with
roleandcontent - options (object, optional): Same as
chat()options
Change the default model.
chatgpt.setModel('gpt-3.5-turbo');Get a list of commonly available models.
npm testnpm run lintAI-Time-Machines/
├── src/
│ ├── chatgpt.js # ChatGPT wrapper class
│ └── index.js # Main entry point with examples
├── tests/
│ └── chatgpt.test.js # Unit tests
├── .env.example # Environment variable template
├── .gitignore # Git ignore rules
├── package.json # Project dependencies
└── README.md # This file
- ✅ Always use environment variables for API keys
- ✅ Never commit
.envfiles to version control - ✅ Use
.env.exampleas a template without real credentials - ✅ Keep your API key secure and don't share it publicly
- ✅ Rotate your API keys regularly
- ✅ Monitor your OpenAI usage dashboard for unexpected activity
With an OpenAI Pro account, you can access:
- GPT-4: More capable model with better reasoning
- Higher rate limits: More requests per minute
- Priority access: Faster response times
- Extended context: Longer conversation history
To use GPT-4 (requires appropriate API access):
const chatgpt = new ChatGPT();
chatgpt.setModel('gpt-4');Make sure your .env file exists and contains a valid API key:
OPENAI_API_KEY=sk-your-actual-api-key-hereIf you encounter rate limit errors, you may need to:
- Wait a moment before retrying
- Upgrade your OpenAI plan
- Implement rate limiting in your application
Ensure all dependencies are installed:
npm installWe welcome contributions! Please see CONTRIBUTING.md for guidelines.
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
For questions and support:
- Check GitHub Discussions
- Review the OpenAI API Documentation
- Open an issue for bugs or feature requests