Created
January 1, 2023 12:22
-
-
Save MoElaSec/09b19d40bbb3258d996d1c2dcae346d1 to your computer and use it in GitHub Desktop.
🤖 OpenAI Text-Davinci-003 language model, CLI prompt.
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 sys | |
import signal | |
openai.api_key = os.getenv("OPENAI_API_KEY") | |
print('🤖 Using Davinci-003 OpenAI model\n') | |
print('Type quite anytime to close the app or ctr-z/c') | |
def sig_handler(signum, frame): | |
print("\n\n👋 Existing Programe...") | |
sys.exit(0) | |
signals = [signal.SIGINT, signal.SIGTSTP, signal.SIGQUIT, signal.SIGTERM] | |
for sig in signals: | |
signal.signal(sig, sig_handler) | |
while True: | |
try: | |
prompt = input("💀 Ask me anything: ") | |
if prompt.lower() == 'quite': | |
print("👋 Existing Programe...") | |
sys.exit(0) | |
response = openai.Completion.create( | |
model="text-davinci-003", | |
prompt=f"{prompt}", | |
temperature=0.7, | |
max_tokens=256, | |
top_p=1, | |
frequency_penalty=0, | |
presence_penalty=0 | |
) | |
ans = response['choices'][0]['text'] | |
print(ans) | |
except KeyboardInterrupt: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make sure to set up your environment variable (don't recommend hard-coding the API key to your code).
🐧 Unix (MacOS/Linux)
🪟 Windows