A simple yet powerful Python project to interact with OpenAI models using the latest API.
This project demonstrates how to control model behavior using parameters like temperature, max tokens, and system messages.
- 🔐 Secure API key handling using
.env - 💬 Interactive chatbot (CLI-based)
- 🌡️ Temperature control (randomness tuning)
- ✂️ Max token control (response length)
- 🧠 Custom system message (behavior control)
- 🔍 Compare outputs across different temperatures
- Python 3.x
- openai >= 1.0.0
- python-dotenv
├── app.py # Main application script
├── .env # API key (not committed)
├── .gitignore # Ignore sensitive files
└── README.md # Project documentation
git clone https://github.com/your-username/openai-python-playground.git
cd openai-python-playground
pip install openai python-dotenv
OPENAI_API_KEY=your_api_key_here
python app.py
-
Chat Mode Interactive conversation Set temperature and max tokens dynamically
-
Compare Temperatures Input one prompt See outputs at: 0.2 → deterministic 0.5 → balanced 0.9 → creative
-
Custom System Role Define AI behavior Example: "You are a strict teacher" "You are a startup mentor" ⚙️ Key Concepts 🔥 Temperature
Controls randomness:
0.2 → factual, consistent 0.7 → balanced 0.9+ → creative, diverse ✂️ Max Tokens
Limits response length:
Smaller → short answers Larger → detailed responses
Add .env to .gitignore:
Never expose API keys in code or public repos
🌐 Streamlit UI ⚡ FastAPI backend 🧠 RAG (Retrieval-Augmented Generation) 🤖 Agent-based workflows 💾 Chat history persistence 📚 Learning Outcome
By completing this project, you will understand:
How to call OpenAI models programmatically How LLM parameters affect outputs How to integrate AI into real applications 👨💻 Author
Built as part of an AI engineering learning journey 🚀
If you want, I can also:
- Generate a GitHub repo description + tags (SEO optimized)
- Add badges (build, license, etc.)
- Convert this into a portfolio-ready project 🔥