dspy icon indicating copy to clipboard operation
dspy copied to clipboard

Field descriptions for individual items in a Pydantic model

Open manankalra opened this issue 6 months ago • 1 comments

from pydantic import BaseModel, Field
from dspy.functional import TypedPredictor

class TravelInformation(BaseModel):
    origin: str = Field(pattern=r"^[A-Z]{3}$")
    destination: str = Field(pattern=r"^[A-Z]{3}$")
    date: datetime.date
    confidence: float = Field(gt=0, lt=1)

class TravelSignature(Signature):
    """ Extract all travel information in the given email """
    email: str = InputField()
    flight_information: list[TravelInformation] = OutputField()

predictor = TypedPredictor(TravelSignature)
predictor(email='...')

The README contains this example for using Pydantic types within a Signature. Is there a way to provide descriptions for individual properties in the Pydantic model that will be used by the prompt?

manankalra avatar Jul 24 '24 20:07 manankalra