Skip to content

Instantly share code, notes, and snippets.

@skolo-online
Created January 31, 2022 07:57
Show Gist options
  • Save skolo-online/f63bc37fecf41a39dbf0c7cc04bb400f to your computer and use it in GitHub Desktop.
Save skolo-online/f63bc37fecf41a39dbf0c7cc04bb400f to your computer and use it in GitHub Desktop.
OpenAI API codex snippet
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