Skip to content

Instantly share code, notes, and snippets.

@dmrd
Last active November 14, 2021 02:03
Show Gist options
  • Save dmrd/22c117ddfd170037548c2e47cf7b5083 to your computer and use it in GitHub Desktop.
Save dmrd/22c117ddfd170037548c2e47cf7b5083 to your computer and use it in GitHub Desktop.
query gpt from command line
#!/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