-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatbot.py
29 lines (23 loc) · 842 Bytes
/
chatbot.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
systemPrompt = "You are a helpful and useful Slack chat bot, be very concise"
config = {
"openai": {
"model": "gpt-3.5-turbo",
"temperature": 0.7,
"max_tokens": 1024
},
"system_prompt": systemPrompt
}
def chatbot_message_response(message, client):
formatted_messages = []
# Add the user's message to the formatted_messages list
formatted_messages.append({"role": "system", "content": config["system_prompt"]})
formatted_messages.append({"role": "user", "content": message['text']})
# Get the response from the OpenAI API
completion = client.chat.completions.create(
messages = formatted_messages,
model="gpt-3.5-turbo",
)
# Get the bot's response
botResponse = completion.choices[0].message.content
# Return the bot's response
return botResponse