
    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ej                  eedej                  eediZy)zCerebras-specific utilities.

This module contains utilities specific to the Cerebras provider,
including reask functions, response handlers, and message formatting.
    )annotations)Any   )Mode)dump_message)generate_openai_schemac                p   | j                         } t        |j                  d   j                        g}|j                  d   j                  j                  D ]H  }|j                  dd| d|j                  j                   d|j                  j                   dd       J | d   j                  |       | S )	z
    Handle reask for Cerebras tools mode when validation fails.

    Kwargs modifications:
    - Adds: "messages" (tool response messages indicating validation errors)
    r   userzValidation Error found:
zA
Recall the function correctly, fix the errors and call the tool z. again, taking into account the problems with z that was previously generated.rolecontentmessages)
copyr   choicesmessage
tool_callsappendfunctionname	argumentsextend)kwargsresponse	exception
reask_msgs	tool_calls        n/root/.openclaw/workspace/visionaryfx/venv/lib/python3.12/site-packages/instructor/providers/cerebras/utils.pyreask_cerebras_toolsr      s     [[]Fx//2::;<J%%a(00;; 

	/	{ ;88A8J8J8O8O7P Q==F=O=O=Y=Y<ZZy{		


 :j)M    c                    |j                  dd      rt        d      dt        |       dg|d<   ddt        |       d   id|d<   | |fS )	z
    Handle Cerebras tools mode.

    Kwargs modifications:
    - Adds: "tools" (list with function schema)
    - Adds: "tool_choice" (forced function call)
    - Validates: stream=False
    streamFz1Stream is not supported for Cerebras Tool Callingr   )typer   toolsr   tool_choice)get
ValueErrorr   )response_model
new_kwargss     r   handle_cerebras_toolsr)   ,   sm     ~~h&LMM .~>	
Jw 3NCFKL!J} :%%r   c                j    d| j                          d| j                   d}d|dg|d   z   |d<   | |fS )z|
    Handle Cerebras JSON mode.

    Kwargs modifications:
    - Adds: "messages" (system instruction with JSON schema)
    z
You are a helpful assistant that excels at following instructions.Your task is to understand the content and provide the parsed objects in json that match the following json_schema:


Here is the relevant JSON schema to adhere to

<schema>
zK
</schema>

Your response should consist only of a valid JSON object that `z0.model_validate_json()` can successfully parse.
systemr   r   )model_json_schema__name__)r'   r(   instructions      r   handle_cerebras_jsonr/   F   sl     !!# $ %@ AO@W@W?X Y
K (0KHIJM Jz :%%r   )reaskr   N)r   dict[str, Any]r   r   r   	Exception)r'   z	type[Any]r(   r1   returnz tuple[type[Any], dict[str, Any]])__doc__
__future__r   typingr   moder   
utils.corer   processing.schemar   r   r)   r/   CEREBRAS_TOOLSCEREBRAS_JSONCEREBRAS_HANDLERS r   r   <module>r>      s    #   & 7 8&&+9&%&4&&+9&%&: 	%) 	%(	 r   