Skip to content

Instantly share code, notes, and snippets.

@skolo-online
Created January 17, 2022 06:50
Show Gist options
  • Select an option

  • Save skolo-online/f005acc660dcfb538c89cb085a523e71 to your computer and use it in GitHub Desktop.

Select an option

Save skolo-online/f005acc660dcfb538c89cb085a523e71 to your computer and use it in GitHub Desktop.
AI Content Generator with Python Flask and OpenAI
import openai
import config
openai.api_key = config.OPENAI_API_KEY
def openAIQuery(query):
response = openai.Completion.create(
engine="davinci-instruct-beta-v3",
prompt=query,
temperature=0.8,
max_tokens=200,
top_p=1,
frequency_penalty=0,
presence_penalty=0)
if 'choices' in response:
if len(response['choices']) > 0:
answer = response['choices'][0]['text']
else:
answer = 'Opps sorry, you beat the AI this time'
else:
answer = 'Opps sorry, you beat the AI this time'
return answer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment