Created
January 17, 2022 06:50
-
-
Save skolo-online/f005acc660dcfb538c89cb085a523e71 to your computer and use it in GitHub Desktop.
AI Content Generator with Python Flask and OpenAI
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 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