-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory_openAI.py
39 lines (34 loc) · 1.08 KB
/
memory_openAI.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
from openai import OpenAI
class Chatbot:
def __init__(self):
self.client = OpenAI()
self.message_history = [
{
"role": "system",
"content": "You are a helpful assistant. You must answer in Korean.",
}
]
def ask(self, question):
# 사용자 질문 추가
self.message_history.append(
{
"role": "user",
"content": question,
}
)
# GPT에 질문을 전달하여 답변을 생성
completion = self.client.chat.completions.create(
model="gpt-3.5-turbo",
messages=self.message_history,
stream=True
)
# 사용자 질문에 대한 답변을 추가
assistant_response = completion.choices[0].message.content
print(assistant_response)
self.message_history.append(
{
"role": "assistant",
"content": assistant_response
}
)
return assistant_response