-
-
Save dmrd/22c117ddfd170037548c2e47cf7b5083 to your computer and use it in GitHub Desktop.
query gpt from command line
This file contains 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
#!/usr/bin/env python3 | |
# Query GPT3 API | |
import openai | |
import fire | |
# API_KEY = os.getenv("OPENAI_API_KEY") | |
openai.api_key = "FAKE_KEY" | |
def gpt(prompt, | |
l=16, | |
n=1, | |
p=1.0, | |
t=1.0, | |
beam=1, | |
engine='davinci', | |
stop='\n' | |
): | |
completion = openai.Completion.create( | |
engine=engine, | |
prompt=prompt, | |
max_tokens=l, | |
n=n, | |
top_p=p, | |
temperature=t, | |
stop=stop, | |
best_of=beam | |
) | |
for x in completion['choices']: | |
print(x['text']) | |
def codex(prompt, **kwargs): | |
gpt(prompt=prompt, engine='davinci-codex', **kwargs) | |
if __name__ == '__main__': | |
fire.Fire() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment