This project demonstrates how to connect to the OpenAI API using Python. It allows you to send prompts to OpenAI models and receive responses.
Install the required packages using pip:
pip install -r requirements.txt- Create a
.envfile in the project root directory - Copy the contents from
.env.exampleto your new.envfile - Replace
your_api_key_herewith your actual OpenAI API key from OpenAI Platform
Execute the main script:
python main.pyWhen you run the application:
- You'll be prompted to enter your question or prompt
- The application will send your prompt to the OpenAI API
- The response will be displayed in the console
- Secure API key storage using environment variables
- Error handling for API requests
- Configurable model selection (default: gpt-4o)
- Simple command-line interface
You can modify the generate_completion function in main.py to adjust parameters like:
- Model selection
- Temperature
- Max tokens
- System prompt
- Other OpenAI API parameters