Created
January 31, 2022 07:57
-
-
Save skolo-online/f63bc37fecf41a39dbf0c7cc04bb400f to your computer and use it in GitHub Desktop.
OpenAI API codex snippet
This file contains hidden or 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 os | |
import openai | |
import config | |
openai.api_key = config.OPENAI_API_KEY | |
def runSomeCode(): | |
response = openai.Completion.create( | |
engine="code-davinci-001", | |
prompt="\"\"\"\n1. Get a reputable free news api\n2. Make a request to the api for the latest news stories\n\"\"\"", | |
temperature=0, | |
max_tokens=1500, | |
top_p=1, | |
frequency_penalty=0, | |
presence_penalty=0) | |
if 'choices' in response: | |
x = response['choices'] | |
if len(x) > 0: | |
return x[0]['text'] | |
else: | |
return '' | |
else: | |
return '' | |
answer = runSomeCode() | |
print(answer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment