Created
January 18, 2023 17:45
-
-
Save monsieurpablo/39d43f9908bcbb23103b087716065e53 to your computer and use it in GitHub Desktop.
Integrate open AI API using Iron Python (Can be used inside Grasshopper3D)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
import json | |
# Set the endpoint URL and the prompt text | |
url = "https://api.openai.com/v1/completions" | |
# Set the API key and other parameters | |
data = json.dumps({ "model": "text-davinci-003", "prompt": prompt, "temperature": 0.5, "max_tokens": 1024}) | |
headers = { "Content-Type": "application/json", "Authorization": "Bearer {0}".format(api_key) } | |
answer = "Send to prompt to Open AI" | |
if send: | |
# Make the request | |
req = urllib2.Request(url, data, headers) | |
response = urllib2.urlopen(req) | |
# Parse the response | |
response_text = response.read() | |
response_json = json.loads(response_text) | |
# Read the answer | |
answer = response_json["choices"][0]["text"] | |
print(answer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
now don't work, i don't know why
always:
urllib2.HTTPError: HTTP Error 429: Too Many Requests