This Python script allows you to interact with OpenAI's API via command-line inputs, where you can provide a model and input text to receive a generated response. It uses the openai library and environment variables for secure API key management.
- Communicates with OpenAI's models (e.g.,
gpt-3.5-turbo) via API. - Accepts model and input content as command-line arguments.
- Handles up to 2000 tokens per response.
- Flexible parameters for response generation (temperature, top_p).
Before running the script, make sure you have the following installed:
- Python 3.x
- Required libraries:
openaipython-dotenv
You can install the dependencies using the following command:
pip install openai python-dotenv-
Clone the repository:
git clone <repository_url> cd <repository_folder>
-
Create a
.envfile: In the project directory, create a.envfile and add your OpenAI API key:OPENAI_API_KEY=your_openai_api_key
-
Run the script:
To use the script, pass the desired OpenAI model and input content as command-line arguments:
python script.py <model_name> "<input_text>"
For example:
python script.py gpt-3.5-turbo "What is the capital of France?" -
Response:
The script will return the response generated by the OpenAI model based on the input text:
Paris is the capital of France.
- Model: You can specify any OpenAI model, such as
gpt-3.5-turbo. - Max Tokens: You can adjust the maximum number of tokens returned by modifying the
max_tokensargument in the script. - Temperature & Top P: You can control the randomness of the responses by tweaking the
temperatureandtop_pparameters in the script.
This project is licensed under the MIT License - see the LICENSE file for details.
For any questions or issues, please contact [bdeva1975@gmail.com].
Let me know if you need any further changes to the README.md!