()
| 44 | |
| 45 | |
| 46 | def source_retriever() -> Generator[str, None, None]: |
| 47 | # Connect to the database |
| 48 | DBHOST = os.environ["POSTGRES_HOST"] |
| 49 | DBUSER = os.environ["POSTGRES_USERNAME"] |
| 50 | DBPASS = os.environ["POSTGRES_PASSWORD"] |
| 51 | DBNAME = os.environ["POSTGRES_DATABASE"] |
| 52 | DATABASE_URI = f"postgresql://{DBUSER}:{DBPASS}@{DBHOST}/{DBNAME}" |
| 53 | engine = create_engine(DATABASE_URI, echo=False) |
| 54 | with Session(engine) as session: |
| 55 | # Fetch all products for a particular type |
| 56 | item_types = session.scalars(select(Item.type).distinct()) |
| 57 | for item_type in item_types: |
| 58 | records = list(session.scalars(select(Item).filter(Item.type == item_type).order_by(Item.id))) |
| 59 | logger.info(f"Processing database records for type: {item_type}") |
| 60 | yield "\n\n".join([f"## Product ID: [{record.id}]\n" + record.to_str_for_rag() for record in records]) |
| 61 | # Fetch each item individually |
| 62 | # records = list(session.scalars(select(Item).order_by(Item.id))) |
| 63 | # for record in records: |
| 64 | # logger.info(f"Processing database record: {record.name}") |
| 65 | # yield f"## Product ID: [{record.id}]\n" + record.to_str_for_rag() |
| 66 | |
| 67 | |
| 68 | def source_to_text(source) -> str: |
no test coverage detected