|
1 | 1 | # AI-Time-Machines |
2 | | -adding AI Agents to everything with Time Machines |
| 2 | + |
| 3 | +Adding AI Agents to everything with Time Machines - OpenAI ChatGPT Integration |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +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. |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +Before you begin, ensure you have the following installed: |
| 12 | + |
| 13 | +- **Node.js** (version 18.0.0 or higher) |
| 14 | +- **npm** (comes with Node.js) |
| 15 | +- **OpenAI API Key** (requires an OpenAI account) |
| 16 | + |
| 17 | +## Getting Started |
| 18 | + |
| 19 | +### 1. Clone the Repository |
| 20 | + |
| 21 | +```bash |
| 22 | +git clone https://github.com/lippytm/AI-Time-Machines.git |
| 23 | +cd AI-Time-Machines |
| 24 | +``` |
| 25 | + |
| 26 | +### 2. Install Dependencies |
| 27 | + |
| 28 | +```bash |
| 29 | +npm install |
| 30 | +``` |
| 31 | + |
| 32 | +### 3. Set Up Your OpenAI API Key |
| 33 | + |
| 34 | +#### Obtain Your API Key |
| 35 | + |
| 36 | +1. Create an account or log in at [OpenAI Platform](https://platform.openai.com/) |
| 37 | +2. Navigate to [API Keys](https://platform.openai.com/api-keys) |
| 38 | +3. Click "Create new secret key" |
| 39 | +4. Copy your API key (you won't be able to see it again!) |
| 40 | + |
| 41 | +#### Configure Environment Variables |
| 42 | + |
| 43 | +1. Copy the example environment file: |
| 44 | + |
| 45 | +```bash |
| 46 | +cp .env.example .env |
| 47 | +``` |
| 48 | + |
| 49 | +2. Open `.env` and replace `your_openai_api_key_here` with your actual API key: |
| 50 | + |
| 51 | +```bash |
| 52 | +OPENAI_API_KEY=sk-your-actual-api-key-here |
| 53 | +``` |
| 54 | + |
| 55 | +⚠️ **Important**: Never commit your `.env` file to version control. It's already included in `.gitignore`. |
| 56 | + |
| 57 | +## Usage |
| 58 | + |
| 59 | +### Running the Examples |
| 60 | + |
| 61 | +Run the included examples to test your setup: |
| 62 | + |
| 63 | +```bash |
| 64 | +npm start |
| 65 | +``` |
| 66 | + |
| 67 | +This will execute several example interactions with ChatGPT, demonstrating: |
| 68 | +- Simple chat messages |
| 69 | +- Conversations with context |
| 70 | +- Custom parameters (temperature, max_tokens) |
| 71 | + |
| 72 | +### Using in Your Code |
| 73 | + |
| 74 | +```javascript |
| 75 | +const { ChatGPT } = require('./src/index'); |
| 76 | + |
| 77 | +// Initialize ChatGPT |
| 78 | +const chatgpt = new ChatGPT(); |
| 79 | + |
| 80 | +// Simple chat |
| 81 | +async function example() { |
| 82 | + const response = await chatgpt.chat('Hello, ChatGPT!'); |
| 83 | + console.log(response); |
| 84 | +} |
| 85 | + |
| 86 | +// Conversation with context |
| 87 | +async function conversationExample() { |
| 88 | + const messages = [ |
| 89 | + { role: 'system', content: 'You are a helpful assistant.' }, |
| 90 | + { role: 'user', content: 'What is AI?' } |
| 91 | + ]; |
| 92 | + const response = await chatgpt.conversation(messages); |
| 93 | + console.log(response); |
| 94 | +} |
| 95 | +``` |
| 96 | + |
| 97 | +### Available Methods |
| 98 | + |
| 99 | +#### `chat(message, options)` |
| 100 | + |
| 101 | +Send a single message to ChatGPT. |
| 102 | + |
| 103 | +- **message** (string): The message to send |
| 104 | +- **options** (object, optional): |
| 105 | + - `model`: The model to use (default: 'gpt-4') |
| 106 | + - `temperature`: Controls randomness, 0-1 (default: 0.7) |
| 107 | + - `max_tokens`: Maximum response length (default: 1000) |
| 108 | + |
| 109 | +#### `conversation(messages, options)` |
| 110 | + |
| 111 | +Have a conversation with context. |
| 112 | + |
| 113 | +- **messages** (array): Array of message objects with `role` and `content` |
| 114 | +- **options** (object, optional): Same as `chat()` options |
| 115 | + |
| 116 | +#### `setModel(model)` |
| 117 | + |
| 118 | +Change the default model. |
| 119 | + |
| 120 | +```javascript |
| 121 | +chatgpt.setModel('gpt-3.5-turbo'); |
| 122 | +``` |
| 123 | + |
| 124 | +#### `getAvailableModels()` |
| 125 | + |
| 126 | +Get a list of commonly available models. |
| 127 | + |
| 128 | +## Development |
| 129 | + |
| 130 | +### Running Tests |
| 131 | + |
| 132 | +```bash |
| 133 | +npm test |
| 134 | +``` |
| 135 | + |
| 136 | +### Linting |
| 137 | + |
| 138 | +```bash |
| 139 | +npm run lint |
| 140 | +``` |
| 141 | + |
| 142 | +### Project Structure |
| 143 | + |
| 144 | +``` |
| 145 | +AI-Time-Machines/ |
| 146 | +├── src/ |
| 147 | +│ ├── chatgpt.js # ChatGPT wrapper class |
| 148 | +│ └── index.js # Main entry point with examples |
| 149 | +├── tests/ |
| 150 | +│ └── chatgpt.test.js # Unit tests |
| 151 | +├── .env.example # Environment variable template |
| 152 | +├── .gitignore # Git ignore rules |
| 153 | +├── package.json # Project dependencies |
| 154 | +└── README.md # This file |
| 155 | +``` |
| 156 | + |
| 157 | +## Security Best Practices |
| 158 | + |
| 159 | +- ✅ Always use environment variables for API keys |
| 160 | +- ✅ Never commit `.env` files to version control |
| 161 | +- ✅ Use `.env.example` as a template without real credentials |
| 162 | +- ✅ Keep your API key secure and don't share it publicly |
| 163 | +- ✅ Rotate your API keys regularly |
| 164 | +- ✅ Monitor your OpenAI usage dashboard for unexpected activity |
| 165 | + |
| 166 | +## Advanced Features (OpenAI Pro Account) |
| 167 | + |
| 168 | +With an OpenAI Pro account, you can access: |
| 169 | + |
| 170 | +- **GPT-4**: More capable model with better reasoning |
| 171 | +- **Higher rate limits**: More requests per minute |
| 172 | +- **Priority access**: Faster response times |
| 173 | +- **Extended context**: Longer conversation history |
| 174 | + |
| 175 | +To use GPT-4 (requires appropriate API access): |
| 176 | + |
| 177 | +```javascript |
| 178 | +const chatgpt = new ChatGPT(); |
| 179 | +chatgpt.setModel('gpt-4'); |
| 180 | +``` |
| 181 | + |
| 182 | +## Troubleshooting |
| 183 | + |
| 184 | +### "OpenAI API key is required" Error |
| 185 | + |
| 186 | +Make sure your `.env` file exists and contains a valid API key: |
| 187 | + |
| 188 | +```bash |
| 189 | +OPENAI_API_KEY=sk-your-actual-api-key-here |
| 190 | +``` |
| 191 | + |
| 192 | +### API Rate Limit Errors |
| 193 | + |
| 194 | +If you encounter rate limit errors, you may need to: |
| 195 | +- Wait a moment before retrying |
| 196 | +- Upgrade your OpenAI plan |
| 197 | +- Implement rate limiting in your application |
| 198 | + |
| 199 | +### Module Not Found Errors |
| 200 | + |
| 201 | +Ensure all dependencies are installed: |
| 202 | + |
| 203 | +```bash |
| 204 | +npm install |
| 205 | +``` |
| 206 | + |
| 207 | +## Contributing |
| 208 | + |
| 209 | +We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. |
| 210 | + |
| 211 | +## License |
| 212 | + |
| 213 | +This project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details. |
| 214 | + |
| 215 | +## Resources |
| 216 | + |
| 217 | +- [OpenAI API Documentation](https://platform.openai.com/docs) |
| 218 | +- [OpenAI Platform](https://platform.openai.com/) |
| 219 | +- [Node.js OpenAI SDK](https://github.com/openai/openai-node) |
| 220 | + |
| 221 | +## Support |
| 222 | + |
| 223 | +For questions and support: |
| 224 | +- Check [GitHub Discussions](https://github.com/lippytm/AI-Time-Machines/discussions) |
| 225 | +- Review the [OpenAI API Documentation](https://platform.openai.com/docs) |
| 226 | +- Open an issue for bugs or feature requests |
0 commit comments