-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathsimple_logging_plugin.py
More file actions
31 lines (20 loc) · 958 Bytes
/
simple_logging_plugin.py
File metadata and controls
31 lines (20 loc) · 958 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 simplemind as sm
class LoggingPlugin(sm.BasePlugin):
def pre_send_hook(self, conversation):
print(f"Sending conversation with {len(conversation.messages)} messages")
def add_message_hook(self, conversation, message):
print(f"Adding message to conversation: {message.text}")
def cleanup_hook(self, conversation):
print(f"Cleaning up conversation with {len(conversation.messages)} messages")
def initialize_hook(self, conversation):
print("Initializing conversation")
def post_send_hook(self, conversation, response):
print(f"Received response: {response.text}")
with sm.create_conversation() as conversation:
# Add the logging plugin.
conversation.add_plugin(LoggingPlugin())
# Add a message to the conversation.
conversation.add_message("user", "Hello!", meta={})
# Send the conversation.
response = conversation.send()
print(f"Response: {response.text}")