Created
February 23, 2023 08:49
-
-
Save pkutaj/1acfa229b395d7da7744c648363c6d9c to your computer and use it in GitHub Desktop.
2023-02-23-How-to-Ask-AI-from-Command-Line.py
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
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