-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
31 lines (21 loc) · 639 Bytes
/
Copy pathrun.py
File metadata and controls
31 lines (21 loc) · 639 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
import os
import openai
from dotenv import load_dotenv
load_dotenv()
openai.organization = os.getenv("OPENAI_ORGANIZATION")
openai.api_key = os.getenv("OPENAI_API_KEY")
def chat(message: str):
# create a chat completion
chat_completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo", messages=[{"role": "user", "content": message}]
)
# return the chat completion
return chat_completion.choices[0].message.content
def main():
while True:
prompt = input(" you > ")
if prompt == "q":
break
print(" ai >", chat(prompt))
if __name__ == "__main__":
main()