-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt_fast.py
More file actions
executable file
·43 lines (37 loc) · 949 Bytes
/
gpt_fast.py
File metadata and controls
executable file
·43 lines (37 loc) · 949 Bytes
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
import os
import sys
from openai import OpenAI
class bcolors:
HEADER = "\033[95m"
OKBLUE = "\033[94m"
OKCYAN = "\033[96m"
OKGREEN = "\033[92m"
WARNING = "\033[93m"
FAIL = "\033[91m"
ENDC = "\033[0m"
BOLD = "\033[1m"
UNDERLINE = "\033[4m"
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"),
)
def gpt4_response(prompt):
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": prompt,
}
],
model="gpt-3.5-turbo",
)
return chat_completion.choices[0].message.content
def main():
if len(sys.argv) > 1:
prompt = ' '.join(sys.argv[1:])
response = gpt4_response(prompt)
gpt_reply = response
print(f"{bcolors.OKCYAN} \n GPT: {gpt_reply} {bcolors.ENDC}")
else:
print("Please provide a prompt")
if __name__ == "__main__":
main()