
    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l	m
Z
 	 	 	 	 	 	 ddZ	 	 	 	 	 	 dd	Z	 	 	 	 	 	 dd
Z	 	 	 	 	 	 ddZej                  eedej                   eediZy)zWriter-specific utilities.

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

    Kwargs modifications:
    - Adds: "messages" (user instructions to correct tool call)
    r   userzValidation Error found:
a@  
 Fix errors and fill tool call arguments/name correctly. Just update arguments dict values or update name. Don't change the structure of them. You have to call function by passing desired functions name/args as part of special attribute with name tools_calls, not as text in attribute with name content. IT'S IMPORTANT!rolecontentmessages)copyr	   choicesmessageappendextendkwargsresponse	exception
reask_msgss       l/root/.openclaw/workspace/visionaryfx/venv/lib/python3.12/site-packages/instructor/providers/writer/utils.pyreask_writer_toolsr      sp     [[]Fx//2::;<J+I; 7N O		
 :j)M    c                
   | j                         } t        |j                  d   j                        g}|j	                  dd|j                  d   j                  j
                   d| d       | d   j                  |       | S )z
    Handle reask for Writer JSON mode when validation fails.

    Kwargs modifications:
    - Adds: "messages" (user message requesting JSON correction)
    r   r   zCorrect your JSON response: z!, based on the following errors:
r   r   )r   r	   r   r   r   r   r   r   s       r   reask_writer_jsonr   -   s     [[]Fx//2::;<J5h6F6Fq6I6Q6Q6Y6Y5Z [//8k;	
 :j)Mr   c                8    dt        |       dg|d<   d|d<   | |fS )z
    Handle Writer tools mode.

    Kwargs modifications:
    - Adds: "tools" (list with function schema)
    - Sets: "tool_choice" to "auto"
    function)typer    toolsautotool_choicer   response_model
new_kwargss     r   handle_writer_toolsr(   E   s7     .~>	
Jw !'J}:%%r   c                :    dd| j                         id|d<   | |fS )zl
    Handle Writer JSON mode.

    Kwargs modifications:
    - Adds: "response_format" with json_schema
    json_schemaschema)r!   r*   response_format)model_json_schemar%   s     r   handle_writer_jsonr.   Y   s2      ."B"B"DE%J !
 :%%r   )reaskr   N)r   dict[str, Any]r   r   r   	Exception)r&   z	type[Any]r'   r0   returnz tuple[type[Any], dict[str, Any]])__doc__
__future__r   typingr   moder   processing.schemar   
utils.corer	   r   r   r(   r.   WRITER_TOOLSWRITER_JSONWRITER_HANDLERS r   r   <module>r=      s    #   7 & : 0&&+9&%&(&&+9&%&& 	#' 	"&	r   