Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two changes: added file_output component and a cleaner way for a component to discard a message #22

Merged
merged 40 commits into from
Jul 25, 2024
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a133bd2
Remove launch.json
efunneko Apr 27, 2024
d9b3d36
Merge remote-tracking branch 'upstream/main'
efunneko Apr 27, 2024
c9f4091
Merge remote-tracking branch 'upstream/main'
efunneko Apr 27, 2024
dd861b0
Merge remote-tracking branch 'upstream/main'
efunneko Apr 29, 2024
7785992
Merge remote-tracking branch 'upstream/main'
efunneko May 5, 2024
0ae3420
Merge remote-tracking branch 'upstream/main'
efunneko May 9, 2024
2f7ec70
chore: Refactor SlackReceiver to handle channel events and join new c…
efunneko May 15, 2024
d852259
* Add ability for a component to send a message directly to a named flow
efunneko May 23, 2024
dd5b7f9
feat: Update default stream_batch_size to 15 in LangChainChatModelWit…
efunneko May 27, 2024
79b1021
Merge remote-tracking branch 'upstream/main'
efunneko May 27, 2024
8b01c1c
Merge remote-tracking branch 'upstream/main'
efunneko May 30, 2024
261d095
Update import statement in main.py
efunneko Jun 5, 2024
002e9b9
Another major reorganization of directory structure to make it more s…
efunneko Jun 6, 2024
fea2759
Fixed some documentation generation after package reorganization
efunneko Jun 6, 2024
3b421b8
Merge branch 'main' into main
efunneko Jun 6, 2024
5b21a74
Merge remote-tracking branch 'upstream/main'
efunneko Jun 6, 2024
bcac8ea
chore: Remove unused slack.yaml configuration file
efunneko Jun 6, 2024
5e4d350
Made some changes in utils.py for dynamic loading. We will no longer …
efunneko Jun 8, 2024
8c809e8
Moved slack components into their own plugin: solace-ai-connector-slack.
efunneko Jun 9, 2024
9cbba1d
chore: Update component_base.py to include flow_lock_manager and flow…
efunneko Jun 18, 2024
fc21829
chore: Update trust_store_path for Solace API
efunneko Jun 18, 2024
85bf89a
Bump up to latest Solace API and small fix in a debug log
efunneko Jul 8, 2024
f140ca6
DATAGO-79372: Add Publish workflow (#3)
AmanRiat1 Jul 8, 2024
df0fd3d
DATAGO-78654 : Add CI (#4)
artyom-morozov Jul 8, 2024
1c15df5
Merge remote-tracking branch 'upstream/main'
efunneko Jul 11, 2024
714e239
chore: Fix a bug in the user_processor component to properly return s…
efunneko Jul 11, 2024
1873ae4
Test clean up prints (#7)
artyom-morozov Jul 11, 2024
7b616d8
Remove empty test file
efunneko Jul 11, 2024
59e92b8
Skip SonarQube on fork PRs (#8)
artyom-morozov Jul 12, 2024
a6de455
Better streaming support from chat_model_with_history
efunneko Jul 15, 2024
bb19336
chore: Update TimerInput to fix sleep time calculation
efunneko Jul 15, 2024
96fe7b0
Merge pull request #9 from SolaceDev:fix_timer_issue
efunneko Jul 15, 2024
3dbab64
Merge remote-tracking branch 'upstream/main'
efunneko Jul 15, 2024
70f8643
Save the response_uuid into the message's user_properties (optionally)
efunneko Jul 17, 2024
5495009
A bit more help text in the docs
efunneko Jul 17, 2024
d5df0cf
More cleanup for better streaming
efunneko Jul 22, 2024
9098f50
Added file_output component (#11)
efunneko Jul 22, 2024
8e64032
DATAGO-80480: Change workflows to use shareable public actions (#10)
artyom-morozov Jul 24, 2024
fc02b88
Merge branch 'main' into better_streaming
efunneko Jul 25, 2024
b0b2548
Merge pull request #12 from SolaceDev:better_streaming
efunneko Jul 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: Refactor SlackReceiver to handle channel events and join new c…
…hannels
efunneko committed May 15, 2024
commit 2f7ec70df83dffded665ef6e6c96c305fe6fa00e
2 changes: 1 addition & 1 deletion examples/anthropic_bedrock.yaml
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ flows:
payload_encoding: utf-8
payload_format: text

- component_name: azure_openai_llm
- component_name: llm
component_module: langchain_chat_model
# Anthropic Claude2 in AWS Bedrock
component_config:
Original file line number Diff line number Diff line change
@@ -49,6 +49,20 @@
"default": 20,
"required": False,
},
{
"name": "listen_to_channels",
"type": "boolean",
"description": "Whether to listen to channels or not. Default: False",
"default": False,
"required": False,
},
{
"name": "send_history_on_join",
"type": "boolean",
"description": "Send history on join. Default: False",
"default": False,
"required": False,
},
],
"output_schema": {
"type": "object",
@@ -142,6 +156,8 @@ def init_slack_receiver(self):
stop_event=self.stop_receiver_event,
max_file_size=self.get_config("max_file_size"),
max_total_file_size=self.get_config("max_total_file_size"),
listen_to_channels=self.get_config("listen_to_channels"),
send_history_on_join=self.get_config("send_history_on_join"),
)
self.slack_receiver.start()

@@ -171,6 +187,8 @@ def __init__(
stop_event,
max_file_size=20,
max_total_file_size=20,
listen_to_channels=False,
send_history_on_join=False,
):
threading.Thread.__init__(self)
self.app = app
@@ -180,13 +198,24 @@ def __init__(
self.stop_event = stop_event
self.max_file_size = max_file_size
self.max_total_file_size = max_total_file_size
self.listen_to_channels = listen_to_channels
self.send_history_on_join = send_history_on_join
self.register_handlers()

def run(self):
SocketModeHandler(self.app, self.slack_app_token).connect()
self.stop_event.wait()

def handle_event(self, event):
def handle_channel_event(self, event):
# For now, just do the normal handling
channel_name = (self.get_channel_name(event.get("channel")),)

self.handle_event(event, channel_name)

def handle_group_event(self, event):
log.info("Received a private group event. Ignoring.")

def handle_event(self, event, channel_name=None):
files = []
total_file_size = 0
if "files" in event:
@@ -228,6 +257,7 @@ def handle_event(self, event):
"client_msg_id": event.get("client_msg_id"),
"ts": event.get("thread_ts") or event.get("ts"),
"channel": event.get("channel"),
"channel_name": channel_name or "",
"subtype": event.get("subtype"),
"event_ts": event.get("event_ts"),
"channel_type": event.get("channel_type"),
@@ -256,7 +286,7 @@ def download_file_as_base64_string(self, file_url):

def get_user_email(self, user_id):
response = self.app.client.users_info(user=user_id)
return response["user"]["profile"]["email"]
return response["user"]["profile"].get("email", "")

def process_text_for_mentions(self, text):
mention_emails = []
@@ -278,11 +308,80 @@ def process_text_for_mentions(self, text):
)
return text, mention_emails

def get_channel_name(self, channel_id):
response = self.app.client.conversations_info(channel=channel_id)
return response["channel"].get("name")

def get_channel_history(self, channel_id):
response = self.app.client.conversations_history(channel=channel_id)

# Go through the messages and remove any that have a sub_type
messages = []
for message in response["messages"]:
if "subtype" not in message and "text" in message:
payload = {
"text": message.get("text"),
"user_email": self.get_user_email(message.get("user")),
"mentions": [],
"type": message.get("type"),
"client_msg_id": message.get("client_msg_id"),
"ts": message.get("ts"),
"channel": channel_id,
"subtype": message.get("subtype"),
"user_id": message.get("user"),
}
messages.append(message)

return messages

def handle_new_channel_join(self, event):
"""We have been added to a new channel. This will get all the history and send it to the input queue."""
history = self.get_channel_history(event.get("channel"))
payload = {
"text": "New channel joined",
"user_email": "",
"mentions": [],
"type": "channel_join",
"client_msg_id": "",
"ts": "",
"channel": event.get("channel"),
"subtype": "channel_join",
"event_ts": "",
"channel_type": "channel",
"channel_name": self.get_channel_name(event.get("channel")),
"user_id": "",
"history": history,
}
user_properties = {
"type": "channel_join",
"channel": event.get("channel"),
"subtype": "channel_join",
"channel_type": "channel",
}
message = Message(payload=payload, user_properties=user_properties)
message.set_previous(payload)
self.input_queue.put(message)

def register_handlers(self):
@self.app.event("message")
def handle_chat_message(event):
self.handle_event(event)
print("Got message event: ", event, event.get("channel_type"))
if event.get("channel_type") == "im":
self.handle_event(event)
elif event.get("channel_type") == "channel":
self.handle_channel_event(event)
elif event.get("channel_type") == "group":
self.handle_group_event(event)

@self.app.event("app_mention")
def handle_app_mention(event):
print("Got app_mention event: ", event)
self.handle_event(event)

@self.app.event("member_joined_channel")
def handle_member_joined_channel(event, say, context):
if (
self.send_history_on_join
and event.get("user") == context["bot_user_id"]
):
self.handle_new_channel_join(event)