|
|
|
|
| from pydantic import BaseModel, Field
|
| from agents import Agent
|
| from agents.prompts import Prompt
|
| from pypdf import PdfReader
|
| import PyPDF2
|
|
|
|
|
| INSTRUCTIONS = (
|
| "You are a Proforma Invoice Generator assistant. "
|
| "Given customer details, produce a clear, structured Proforma Invoice in plain text. "
|
| "Include Consignor (True Vybes, Thane, GSTIN: 27BVOPS7767J2ZF), "
|
| "Consignee section (customer name, address, GSTIN, date), "
|
| "product table with Sl. No., Description, Code, Qty, Rate/unit, Value, "
|
| "total, GST @ 18%, Grand Total, bank details, standard terms, "
|
| "and 'Authorised Signatory' at the end. "
|
| "Output ONLY the invoice content, no extra text."
|
| )
|
|
|
|
|
| def prompt_fn(data):
|
|
|
| if hasattr(data, "input"):
|
| user_input = data.input
|
| elif hasattr(data, "raw_input"):
|
| user_input = data.raw_input
|
| elif hasattr(data, "__dict__"):
|
| user_input = data.__dict__
|
| else:
|
| user_input = data
|
|
|
| final_prompt = f"""
|
| Customer Name: {user_input.get('customer_name')}
|
| Address: {user_input.get('address')}
|
| GSTIN: {user_input.get('gst_number')}
|
| Date: {user_input.get('date')}
|
| Product: {user_input.get('product_name')}
|
| Qty: {user_input.get('quantity')}
|
| Price per piece: {user_input.get('price_per_piece')}
|
| """
|
|
|
| return Prompt(content=final_prompt)
|
|
|
| class ProformaInvoice(BaseModel):
|
| proforma_invoice: str = Field(description="Final Proforma invoice")
|
|
|
| writer_agent = Agent(
|
| name="PI Generator agent",
|
| instructions=INSTRUCTIONS,
|
| prompt=prompt_fn,
|
| model="gpt-4o-mini",
|
| output_type=ProformaInvoice,
|
| )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|