11import json
22import logging
33from pprint import pformat
4+ from uuid import UUID
45
56import hayhooks
67from hayhooks import BasePipelineWrapper
910from haystack .dataclasses .chat_message import ChatMessage
1011from haystack_integrations .components .generators .amazon_bedrock import AmazonBedrockChatGenerator
1112from pydantic import BaseModel
12- from sqlalchemy .inspection import inspect
1313
1414from src .app_config import config
1515from src .common import haystack_utils
1919
2020
2121class Resource (BaseModel ):
22- resource_name : str
23- resource_addresses : list [str ]
24- resource_phones : list [str ]
22+ name : str
23+ addresses : list [str ]
24+ phones : list [str ]
25+ emails : list [str ]
26+ website : str
2527 description : str
2628 justification : str
2729
@@ -50,12 +52,12 @@ def setup(self) -> None:
5052
5153 # Called for the `generate-referrals/run` endpoint
5254 def run_api (self , query : str ) -> dict :
53- supports_from_db = retrieve_supports_from_db ()
55+ supports_from_db = format_support_strings ()
5456 response = self .pipeline .run (
5557 {
5658 "prompt_builder" : {
5759 "query" : query ,
58- "supports" : supports_from_db ,
60+ "supports" : supports_from_db . values () ,
5961 "resource_json" : resource_as_json ,
6062 },
6163 }
@@ -80,15 +82,16 @@ def run_chat_completion(self, model: str, messages: list, body: dict) -> None:
8082 )
8183
8284
83- def retrieve_supports_from_db () -> list [str ]:
84- all_supports : list [str ] = []
85+ def format_support_strings () -> dict [UUID , str ]:
8586 with config .db_session () as db_session , db_session .begin ():
86- all_db_supports = db_session .query (Support ).all ()
87-
88- for support in all_db_supports :
89- support_dict = {
90- c .key : getattr (support , c .key ) for c in inspect (Support ).mapper .column_attrs
91- }
92- support_as_str = json .dumps (support_dict , default = str )
93- all_supports .append (support_as_str )
94- return all_supports
87+ return {
88+ support .id : (
89+ f"Name: { support .name } \n "
90+ f"- Description: { support .description } \n "
91+ f"- Addresses: { ', ' .join (support .addresses )} \n "
92+ f"- Phones: { ', ' .join (support .phone_numbers )} \n "
93+ f"- Website: { support .website } \n "
94+ f"- Email Addresses: { ', ' .join (support .email_addresses )} \n "
95+ )
96+ for support in db_session .query (Support ).all ()
97+ }
0 commit comments