a
    bg                     @  sD   d dl mZ d dlmZmZmZmZ d dlmZ G dd deZ	dS )    )annotations)AnyCallableDictOptional)BaseOutputParserc                	   @  s   e Zd ZU dZded< ded< ded< ded< edd	d
dZeddddddd dddZeddddddd dddZ	ed dddddd dddZ
dd	ddZdddddZdS )!GuardrailsOutputParserz1Parse the output of an LLM call using Guardrails.r   guardzOptional[Callable]apiargskwargsstr)returnc                 C  s   dS )N
guardrails selfr   r   |/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/output_parsers/rail_parser.py_type   s    zGuardrailsOutputParser._type   Nint)	rail_file
num_reasksr
   r   r   r   c                 O  sF   zddl m} W n ty*   tdY n0 | |j||d|||dS )a  Create a GuardrailsOutputParser from a rail file.

        Args:
            rail_file: a rail file.
            num_reasks: number of times to re-ask the question.
            api: the API to use for the Guardrails object.
            *args: The arguments to pass to the API
            **kwargs: The keyword arguments to pass to the API.

        Returns:
            GuardrailsOutputParser
        r   GuardWguardrails-ai package not installed. Install it by running `pip install guardrails-ai`.r   r	   r
   r   r   )r   r   ImportError	from_rail)clsr   r   r
   r   r   r   r   r   r   r      s    
z GuardrailsOutputParser.from_rail)rail_strr   r
   r   r   r   c                 O  sF   zddl m} W n ty*   tdY n0 | |j||d|||dS )Nr   r   r   r   r   )r   r   r   from_rail_string)r    r!   r   r
   r   r   r   r   r   r   r"   ;   s    	
z'GuardrailsOutputParser.from_rail_string)output_classr   r
   r   r   r   c                 O  sH   zddl m} W n ty*   tdY n0 | |j|d|d|||dS )Nr   r   r    r   r   )r   r   r   from_pydantic)r    r#   r   r
   r   r   r   r   r   r   r%   R   s    	
z$GuardrailsOutputParser.from_pydanticc                 C  s
   | j jjS )N)r	   Z
raw_promptZformat_instructionsr   r   r   r   get_format_instructionsi   s    z.GuardrailsOutputParser.get_format_instructionsr   )textr   c                 C  s$   | j j|g| jR d| ji| jS )NZllm_api)r	   parser   r
   r   )r   r'   r   r   r   r(   l   s    zGuardrailsOutputParser.parse)r   N)r   N)r   N)__name__
__module____qualname____doc____annotations__propertyr   classmethodr   r"   r%   r&   r(   r   r   r   r   r      s*   
  "    r   N)

__future__r   typingr   r   r   r   Zlangchain_core.output_parsersr   r   r   r   r   r   <module>   s   