Skip to content

This is the Python Program to send Prompts & Receive Response from OpenAI API

Notifications You must be signed in to change notification settings

BNNagaraj/Python-Openai.api.demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

OpenAI API Prompt and Response Python Script This is a simple Python program that demonstrates how to interact with the OpenAI API to generate responses to given prompts.

Prerequisites You must have an OpenAI API key to use this program. If you don't have one already, please visit the OpenAI API page to sign up for an account and obtain an API key.

Python 3.x

The following Python packages must be installed: openai.

Usage Clone the repository or download the code as a zip file.

Navigate to the directory where the code is stored.

Replace with your actual OpenAI API key in the line openai.api_key = "".

Run the script using the following command:

Copy code python openai_prompt_response.py The program will prompt you to enter a prompt. Enter the prompt and press enter.

The program will generate a response using the OpenAI API and display it on the screen.

You can enter multiple prompts, and the program will generate a response for each one.

To exit the program, enter exit when prompted for a prompt.

Limitations The program has the following limitations:

It only works with text prompts.

It uses the text-davinci-003 engine by default. You can modify the engine by changing the engine parameter in the openai.Completion.create() method.

It sets a maximum response length of 4000 tokens by default. You can modify the max_tokens parameter in the openai.Completion.create() method.

It uses a timeout of 10 seconds by default. You can modify the timeout parameter in the openai.Completion.create() method.

The program doesn't handle errors gracefully. If an error occurs, the program will print an error message on the screen.

License This code is released under the MIT license.

About

This is the Python Program to send Prompts & Receive Response from OpenAI API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages