Download app/embed.py from drowzeys/keys-Auto-Receipts-Studio: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/drowzeys/keys-Auto-Receipts-Studio/resolve/main/app/embed.py
- Command line
-
hf download hf://drowzeys/keys-Auto-Receipts-Studio/app/embed.py
-
curl -L -o embed.py https://huggingface.co/drowzeys/keys-Auto-Receipts-Studio/resolve/main/app/embed.py
1.28 kB
| from __future__ import annotations | |
| from app.config import Settings | |
| from app.schemas import LineItem, ReceiptExtract | |
| from backends.base import EmbedBackend, InputType | |
| from backends.openai_compat import apply_embed_prefix | |
| def format_embed_input(text: str, input_type: InputType, *, enabled: bool = True) -> str: | |
| return apply_embed_prefix(text, input_type, enabled=enabled) | |
| def line_query_text(extract: ReceiptExtract, item: LineItem) -> str: | |
| parts = [ | |
| extract.vendor or "", | |
| item.sku or "", | |
| item.description, | |
| f"qty {item.qty}" if item.qty is not None else "", | |
| f"amount {item.amount}" if item.amount is not None else "", | |
| ] | |
| return " | ".join(p for p in parts if p) | |
| def catalog_passage_text( | |
| *, | |
| vendor: str | None, | |
| sku: str | None, | |
| description: str, | |
| size: str | None = None, | |
| ) -> str: | |
| parts = [vendor or "", sku or "", description, size or ""] | |
| return " | ".join(p for p in parts if p) | |
| def vendor_query_text(vendor: str) -> str: | |
| return vendor.strip() | |
| def embed_texts( | |
| backend: EmbedBackend, | |
| texts: list[str], | |
| *, | |
| input_type: InputType, | |
| settings: Settings | None = None, | |
| ) -> list[list[float]]: | |
| del settings | |
| return backend.embed(texts, input_type=input_type) | |