-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (39 loc) · 1004 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import argparse
import os
import openai
from dotenv import load_dotenv
from lib import get_answer, get_config
def setup():
# add API key
load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")
# parse args
parser = argparse.ArgumentParser(
description="Ask ChatGPT a question from your terminal."
)
parser.add_argument(
"question",
type=str,
nargs=1,
help='your question prompt for ChatGPT, make sure you wrap the question in quotes (")',
)
parser.add_argument(
"-t",
"--temperature",
type=float,
default=0,
nargs="?",
help="set temperature parameter",
)
args = parser.parse_args()
# load config
config = get_config(args.temperature)
return config, args
def main():
config, args = setup()
answer = get_answer(config, args.question[0])
for word in answer:
print(word, end="")
print()
if __name__ == "__main__":
main()