
    {hF                         d dl mZmZmZ d dlmZmZmZ  ede      Z G d deee         Z	de
e   de
e	e      fd	Zy
)    )	BaseModelFieldcreate_model)GenericOptionalTypeVarT)boundc                   Z    e Zd ZU dZee   ed<    ed      Ze	ed<   ee
   ed<   de	fdZy	)
	MaybeBasez\
    Extract a result from a model, if any, otherwise set the error and message fields.
    resultFdefaulterrormessagereturnc                     | j                   d uS )N)r   )selfs    U/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/instructor/dsl/maybe.py__bool__zMaybeBase.__bool__   s    {{$&&    N)__name__
__module____qualname____doc__r   r	   __annotations__r   r   boolstrr    r   r   r   r      s8     QK&E4&c]'$ 'r   r   modelr   c                     t        d| j                   t        t        |    t	        dd      ft
        t	        d      ft        t           t	        dd      f      S )	a  
    Create a Maybe model for a given Pydantic model. This allows you to return a model that includes fields for `result`, `error`, and `message` for sitatations where the data may not be present in the context.

    ## Usage

    ```python
    from pydantic import BaseModel, Field
    from instructor import Maybe

    class User(BaseModel):
        name: str = Field(description="The name of the person")
        age: int = Field(description="The age of the person")
        role: str = Field(description="The role of the person")

    MaybeUser = Maybe(User)
    ```

    ## Result

    ```python
    class MaybeUser(BaseModel):
        result: Optional[User]
        error: bool = Field(default=False)
        message: Optional[str]

        def __bool__(self):
            return self.result is not None
    ```

    Parameters:
        model (Type[BaseModel]): The Pydantic model to wrap with Maybe.

    Returns:
        MaybeModel (Type[BaseModel]): A new Pydantic model that includes fields for `result`, `error`, and `message`.
    MaybeNzACorrectly extracted result from the model, if any, otherwise None)r   descriptionFr   zAError message if no result was found, should be short and concise)__base__r   r   r   )r   r   r   r   r   r   r   )r    s    r   r"   r"      sg    H 
 UO_
 U5)*SM_
 r   N)pydanticr   r   r   typingr   r   r   r	   r   typer"   r   r   r   <module>r(      sO    3 3 - -Cy!
'	71: 
'6a 6T)A,/ 6r   