-
Notifications
You must be signed in to change notification settings - Fork 346
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
Slackbot 2.0 #658
Conversation
cookbook/slackbot/start.py
Outdated
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, |
There was a problem hiding this comment.
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),
...
There was a problem hiding this comment.
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
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