| import os |
| from pydantic_ai import Agent |
| from .models import InvoiceSchema, ResumeSchema, GenericSchema |
| from utils.client import get_api_key |
| from utils.prompt_loader import load_prompt |
|
|
| |
| os.environ["GOOGLE_API_KEY"] = get_api_key() |
|
|
| |
| master_system_prompt = load_prompt("system.yaml") |
|
|
| |
| |
| agent = Agent( |
| 'google-gla:models/gemini-2.5-flash', |
| system_prompt=master_system_prompt |
| ) |
|
|
| async def process_data(text: str, schema_type: str): |
| """ |
| Orchestrates the extraction process. |
| Selects the correct Pydantic schema and enforces type-safety. |
| """ |
| |
| if schema_type == "invoice": |
| target_model = InvoiceSchema |
| elif schema_type == "resume": |
| target_model = ResumeSchema |
| else: |
| target_model = GenericSchema |
|
|
| try: |
| |
| |
| result = await agent.run(text, output_type=target_model) |
| |
| |
| if hasattr(result, 'data'): |
| return result.data |
| elif hasattr(result, 'output'): |
| return result.output |
| else: |
| return result |
| |
| except Exception as e: |
| return {"error": f"Extraction Logic Failed: {str(e)}"} |
|
|