Skip to content

Instantly share code, notes, and snippets.

@pkutaj
Created February 23, 2023 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkutaj/1acfa229b395d7da7744c648363c6d9c to your computer and use it in GitHub Desktop.
Save pkutaj/1acfa229b395d7da7744c648363c6d9c to your computer and use it in GitHub Desktop.
2023-02-23-How-to-Ask-AI-from-Command-Line.py
import os
import sys
import openai
import pyperclip as clipboard
def main(prompt):
openai.api_key = os.environ["OPENAI_KEY"]
model_engine = "text-davinci-003"
completion = openai.Completion.create(
engine=model_engine,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
response = completion.choices[0].text.strip()
print(response)
clipboard.copy(response)
if __name__ == "__main__":
main(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment