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 π₯