diff --git a/ai/providers/__init__.py b/ai/providers/__init__.py index d93361a..3a87ed6 100644 --- a/ai/providers/__init__.py +++ b/ai/providers/__init__.py @@ -1,25 +1,24 @@ from .anthropic import AnthropicAPI from .openai import OpenAI_API from ..ai_constants import DEFAULT_SYSTEM_CONTENT -from logging import Logger from state_store.get_user_state import get_user_state from typing import Optional, List """ -New AI providers must be added below +New AI providers must be added below. `get_available_providers()` This function retrieves available API models from different AI providers. It combines the available models into a single dictionary. -`_get_provider()` +`_get_provider()` This function returns an instance of the appropriate API provider based on the given provider name. `get_provider_response`() This function retrieves the user's selected API provider and model, sets the model, and generates a response. -Note that context is an optional parameter because some functionalities, -such as commands, do not allow access to conversation history if the bot +Note that context is an optional parameter because some functionalities, +such as commands, do not allow access to conversation history if the bot isn't in the channel where the command is run. """ diff --git a/listeners/commands/ask_command.py b/listeners/commands/ask_command.py index 090d7b9..c7acfda 100644 --- a/listeners/commands/ask_command.py +++ b/listeners/commands/ask_command.py @@ -1,6 +1,7 @@ from slack_bolt import Ack, Say, BoltContext from logging import Logger from ai.providers import get_provider_response +from slack_sdk import WebClient """ Callback for handling the 'ask-bolty' command. It acknowledges the command, retrieves the user's ID and prompt, @@ -8,15 +9,37 @@ """ -def ask_callback(ack: Ack, command, say: Say, logger: Logger, context: BoltContext): +def ask_callback(client: WebClient, ack: Ack, command, say: Say, logger: Logger, context: BoltContext): try: ack() user_id = context["user_id"] + channel_id = context["channel_id"] prompt = command["text"] + if prompt == "": - say(text="Please provide a question.") + client.chat_postEphemeral( + channel=channel_id, user=user_id, text="Looks like you didn't provide a prompt. Try again." + ) else: - say(text=get_provider_response(user_id, prompt)) + client.chat_postEphemeral( + channel=channel_id, + user=user_id, + blocks=[ + { + "type": "rich_text", + "elements": [ + { + "type": "rich_text_quote", + "elements": [{"type": "text", "text": prompt}], + }, + { + "type": "rich_text_section", + "elements": [{"type": "text", "text": get_provider_response(user_id, prompt)}], + }, + ], + } + ], + ) except Exception as e: logger.error(e) - say(text=f"An unexpected error occured: {e}") + client.chat_postEphemeral(channel=channel_id, user=user_id, text=f"An unexpected error occured: {e}")