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

Slackbot 2.0 #658

Merged
merged 16 commits into from
Nov 28, 2023
Merged

Slackbot 2.0 #658

merged 16 commits into from
Nov 28, 2023

Conversation

zzstoatzz
Copy link
Collaborator

@zzstoatzz zzstoatzz commented Nov 27, 2023

refactors slackbot to use assistants API

adds some slack utils to marvin.utilities.slack which im happy to put elsewhere if we don't think they're broadly useful

image

@zzstoatzz zzstoatzz self-assigned this Nov 27, 2023
@zzstoatzz zzstoatzz marked this pull request as ready for review November 27, 2023 01:29
cookbook/slackbot/start.py Outdated Show resolved Hide resolved
await assistant_thread.add_async(cleaned_message)
run = await assistant_thread.run_async(assistant)
await task(post_slack_message)(
ai_response_text := run.thread.get_messages()[-1].content[0].text.value,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting quirk about the assistants API -- assistants can post multiple messages to the thread in a single "run". Here's one approach you might take to getting them all. Note if for some reason one of them was an image response the content[0].text.value could fail but for this bot I dont think thats an issue

# get the reference to the user message object
user_message = await assistant_thread.add_async(cleaned_message)
run = await assistant_thread.run_async(assistant)
# get all messages that were posted after the user message
ai_messages = assistant_thread.get_messages(after_message=user_message.id)
# extract content
ai_messages_content = [m.content[0].text.value for m in ai_messages]
await task(post_slack_message)(
    ai_response_text '\n\n'.join(ai_messages_content),
    ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, thanks! added in 42bca9c

@zzstoatzz zzstoatzz merged commit 2edaaa1 into main Nov 28, 2023
9 of 12 checks passed
@zzstoatzz zzstoatzz deleted the slackbot-2.0 branch November 28, 2023 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants