openaictl is an interactive command-line chatbot built with Python. It communicates with OpenAI's GPT model using the new client-based interface (openai-python>=1.0.0
). The chatbot supports conversational context, enabling dynamic and intelligent interactions.
- Interactive Chat: Engage in real-time conversations with OpenAI's GPT model.
- Context-Aware: Maintains conversation history for context-based responses.
- Customizable: Configure model, token limits, and API key via the
.env
file. - Secure API Key Handling: Loads OpenAI API key and other configurations from the
.env
file. - Dockerized: Fully containerized for ease of use across different systems and architectures.
- Multiple Architecture Support: Runs on linux/armv7, linux/amd64, linux/arm64
- Python: Ensure Python 3.9 or newer is installed if not using Docker.
- Docker: Install Docker for containerized execution.
- OpenAI API Key: Obtain an API key from OpenAI.
git clone <repository-url>
cd <repository-directory>
If running locally (not with Docker):
-
Create a virtual environment:
python3 -m venv venv source venv/bin/activate # For Linux/Mac venv\Scripts\activate # For Windows
-
Install dependencies:
pip install -r requirements.txt
-
Create a
.env
File: Add the following configuration to a.env
file in the project directory:OPENAI_API_KEY=your_openai_api_key_here MODEL=gpt-3.5-turbo MAX_TOKENS=150
OPENAI_API_KEY
: Your OpenAI API key.MODEL
: The OpenAI model to use (e.g.,gpt-4
,gpt-3.5-turbo
).MAX_TOKENS
: Maximum number of tokens per response.
-
Build the Docker Image:
docker build -t openaictl .
For Multiple Architecture build on your Machine:
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t <your container registry>/openaictl:<tag> --push .
Note: Multiarchitecture builds will not be visible by using
docker images
command. Your registry will show the different images. -
Run the Chatbot:
docker run --rm -it --env-file .env openaictl
Run the chatbot interactively:
python cli.py
Interactive Chatbot with OpenAI (Client-Based API)
Type 'exit' to quit.
You: Hello
AI: Hi there! How can I assist you today?
You: What's the capital of France?
AI: The capital of France is Paris.
You: exit
Goodbye!
The Raspberry Pi 2 has an ARMv7 architecture, so you need to ensure the Docker image is compatible with that architecture. Here's how you can build and run openaictl for a Raspberry Pi 2 on a Mac (including Apple Silicon).
-
Enable Buildx on Docker:
-
Ensure Docker's
buildx
feature is enabled for multi-platform builds. You can check with:docker buildx version
-
If not enabled, install it using Docker's official instructions: Docker Buildx.
-
-
Set Up QEMU for Cross-Platform Emulation:
-
If you haven’t already, set up QEMU for multi-architecture emulation:
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
-
-
Build the Docker Image for ARMv7:
-
Use
buildx
to target the Raspberry Pi 2 architecture (linux/arm/v7
):docker buildx build --platform linux/arm/v7 -t openaictl:rpi2 .
-
-
Save the Image for Transfer (Optional):
-
If building the image on your Mac and transferring it to the Raspberry Pi 2, save the image as a tar file:
docker save -o openaictl-rpi2.tar openaictl:rpi2
-
-
Transfer the Image to Raspberry Pi 2:
-
Copy the image file to the Raspberry Pi using
scp
or another file transfer method:scp openaictl-rpi2.tar pi@<RPI_IP>:/home/pi
-
-
Load and Run the Image on Raspberry Pi 2:
-
SSH into the Raspberry Pi:
ssh pi@<RPI_IP>
-
Load the Docker image:
docker load < openaictl-rpi2.tar
-
Run the chatbot:
docker run --rm -it --env-file .env openaictl:rpi2
-
-
Direct Deployment to Raspberry Pi (Alternative):
-
If the Raspberry Pi is network-accessible, you can build and push directly to it:
docker buildx build --platform linux/arm/v7 -t openaictl:rpi2 --push .
-
cli.py
: Main script for the chatbot.Dockerfile
: Configuration for building the Docker image.requirements.txt
: Python dependencies..env
: Configuration file for the API key, model, and other parameters.
- openai
>=1.0.0
- python-dotenv
Ensure the .env
file is properly configured with the OPENAI_API_KEY
.
Check your .env
file for incorrect values or run the script with debug logging to identify the issue.
This project is licensed under the MIT License. See the LICENSE
file for details.