-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
34 lines (27 loc) · 1.08 KB
/
example.py
File metadata and controls
34 lines (27 loc) · 1.08 KB
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
import openai
import argparse
import gptparse
openai.api_key = YOUR_API_KEY
API_VERSION = 'gpt-3.5-turbo-0613'
available_people = ["Robert", "Mike", "Jane", "Kate", "Marry", "Elon"]
def greet(greeting: str = 'Hi', people: list[str] = available_people) -> None:
for person in people:
print(f'{greeting} {person}!')
greet_parser = argparse.ArgumentParser(
prog = "greet",
description="Greets a list of people individually")
greet_parser.add_argument("greeting", type=str, help="Greeting string")
greet_parser.add_argument("people", nargs="+", help="List of people", choices=available_people)
try:
while True:
user_input = input("Provide instruction for GPT: ")
completition = openai.ChatCompletion.create(
model = API_VERSION,
messages = [{"role": "user", "content": user_input}],
functions = gptparse.from_parsers([greet_parser]),
function_call = "auto"
)
prog, kwargs = gptparse.get_arguments(completition)
if prog == "greet": greet(**kwargs)
except KeyboardInterrupt:
pass