Skip to content

PanthaLasso/Demo-Python-OpenAI-API-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Demo-Python-OpenAI-API-Project

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.

🚀 Features

  • 🔐 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

🛠️ Tech Stack

  • Python 3.x
  • openai >= 1.0.0
  • python-dotenv

📁 Project Structure

├── app.py # Main application script
├── .env # API key (not committed)
├── .gitignore # Ignore sensitive files
└── README.md # Project documentation

🔐 Setup Instructions

1. Clone the Repository

git clone https://github.com/your-username/openai-python-playground.git
cd openai-python-playground

2. Install Dependencies

pip install openai python-dotenv

3. Add API Key

OPENAI_API_KEY=your_api_key_here

4. Run the App

python app.py

5. Usage Modes

  1. Chat Mode Interactive conversation Set temperature and max tokens dynamically

  2. Compare Temperatures Input one prompt See outputs at: 0.2 → deterministic 0.5 → balanced 0.9 → creative

  3. 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

6. Security Best Practices:

Add .env to .gitignore:

Never expose API keys in code or public repos

📈 Future Improvements

🌐 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 found this useful, consider giving it a ⭐ on GitHub!

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 🔥

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages