Spaces:
Runtime error
Runtime error
File size: 1,469 Bytes
c6a2a56 bb7c9a3 9fd6e20 3799925 bb7c9a3 9fd6e20 a1a6d79 c6a2a56 bb7c9a3 3799925 9fd6e20 3799925 c6a2a56 bb7c9a3 c6a2a56 9fd6e20 c6a2a56 8ec2c5a 9fd6e20 cf871ae 8ec2c5a 9fd6e20 8ec2c5a bb7c9a3 |
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 32 33 34 |
from loguru import logger
from pydantic import ConfigDict
from typing import Collection, Self
from ctp_slack_bot.core import ApplicationComponentBase, Settings
from ctp_slack_bot.enums import EventType
from ctp_slack_bot.models import Chunk, SlackMessage, SlackResponse
from .event_brokerage_service import EventBrokerageService
from .language_model_service import LanguageModelService
class AnswerRetrievalService(ApplicationComponentBase):
"""
Service for context-based answer retrievel from a language model.
"""
model_config = ConfigDict(frozen=True)
settings: Settings
event_brokerage_service: EventBrokerageService
language_model_service: LanguageModelService
async def push(self: Self, question: SlackMessage, context: Collection[Chunk]) -> None:
channel_to_respond_to = question.channel
thread_to_respond_to = question.thread_ts if question.thread_ts else question.ts
answer = await self.language_model_service.answer_question(question.user, question.text, context)
logger.debug("Pushing response to channel {} and thread {}: {}", channel_to_respond_to, thread_to_respond_to, answer)
slack_response = SlackResponse(text=answer, channel=channel_to_respond_to, thread_ts=thread_to_respond_to)
await self.event_brokerage_service.publish(EventType.OUTGOING_SLACK_RESPONSE, slack_response)
@property
def name(self: Self) -> str:
return "answer_retrieval_service"
|