Python code to call ChatGPT API
import requests
# Set up API endpoint and parameters
url = "https://api.openai.com/v1/engines/davinci-codex/completions"
prompt = "Hello, how are you doing today?"
params = {
"prompt": prompt,
"max_tokens": 50,
"temperature": 0.7
}
# Set up API authorization headers
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY_HERE"
}
# Send API request and get response
response = requests.post(url, json=params, headers=headers)
# Print the response
print(response.json())
Save the above code as anyname.py and execute it in terminal.
Python code to call ChatGPT API
Reviewed by TechnifAId
on
March 03, 2023
Rating:

No comments