-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatCompletion.py
51 lines (38 loc) · 1018 Bytes
/
chatCompletion.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 os
import openai
import dotenv
dotenv.load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")
# INSTRUCTION = "Eres Una Ai"
with open("text.txt", "r") as INSTRUCTION:
INSTRUCTION = INSTRUCTION.read()
def main():
while True:
user_input = input("Input: ")
gpt_request(user_input)
def gpt_request(user_input):
while True:
response = gpt_response(user_input)
print(response)
action = input("presiona y para generar otra vez: ")
if action == "y":
response
else:
return
def gpt_response(user_input):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "system",
"content": INSTRUCTION,
},
{
"role": "user",
"content": user_input,
},
],
)
return response["choices"][0]["message"]["content"]
if __name__ == "__main__":
main()