
    6i                        d Z ddlmZ ddlmZ ddlmZ ddlmZ 	 	 	 	 	 	 ddZ		 	 	 	 	 	 ddZ
ej                  e	e
d	iZy
)zPerplexity-specific utilities.

This module contains utilities specific to the Perplexity provider,
including reask functions, response handlers, and message formatting.
    )annotations)Any   )Mode)dump_messagec                    | j                         } t        |j                  d   j                        g}|j	                  dd| d       | d   j                  |       | S )z
    Handle reask for Perplexity JSON mode when validation fails.

    Kwargs modifications:
    - Adds: "messages" (user message requesting JSON correction)
    r   userz@Correct your JSON ONLY RESPONSE, based on the following errors:
)rolecontentmessages)copyr   choicesmessageappendextend)kwargsresponse	exception
reask_msgss       p/root/.openclaw/workspace/visionaryfx/venv/lib/python3.12/site-packages/instructor/providers/perplexity/utils.pyreask_perplexity_jsonr      si     [[]Fx//2::;<JZ[dZef	
 :j)M    c                :    dd| j                         id|d<   | |fS )zp
    Handle Perplexity JSON mode.

    Kwargs modifications:
    - Adds: "response_format" with json_schema
    json_schemaschema)typer   response_format)model_json_schema)response_model
new_kwargss     r   handle_perplexity_jsonr!   &   s2      ."B"B"DE%J !
 :%%r   )reaskr   N)r   dict[str, Any]r   r   r   	Exception)r   z	type[Any]r    r#   returnz tuple[type[Any], dict[str, Any]])__doc__
__future__r   typingr   moder   
utils.corer   r   r!   PERPLEXITY_JSONPERPLEXITY_HANDLERS r   r   <module>r.      sr    #   & .&&+9&%&& 	&* r   