
    6i2                        d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	 ddl
mZ ddlmZ g d	Z ej                  d
      dd       Z ej                  d
      dd       Z ej                  d
      dd       Zy)z
Standalone schema generation utilities for different LLM providers.

This module provides provider-agnostic functions to generate schemas from Pydantic models
without requiring inheritance from OpenAISchema or use of decorators.
    )annotationsN)Anycast)parse)	BaseModel   )map_to_gemini_function_schema)generate_openai_schemagenerate_anthropic_schemagenerate_gemini_schema   )maxsizec                   | j                         }t        | j                  xs d      }|j                         D ci c]  \  }}|dvs|| }}}|j                  D ];  }|j
                  x}|d   v s|j                  x}s&d|d   |   vs1||d   |   d<   = t        d |d   j                         D              |d<   d|vr/|j                  r|j                  |d<   nd| j                   d|d<   |d	   |d   |d
S c c}}w )ak  
    Generate OpenAI function schema from a Pydantic model.

    Args:
        model: A Pydantic BaseModel subclass

    Returns:
        A dictionary in the format of OpenAI's function schema

    Note:
        The model's docstring will be used for the function description.
        Parameter descriptions from the docstring will enrich field descriptions.
     )titledescription
propertiesr   c              3  0   K   | ]  \  }}d |vs|  yw)defaultN ).0kvs      g/root/.openclaw/workspace/visionaryfx/venv/lib/python3.12/site-packages/instructor/processing/schema.py	<genexpr>z)generate_openai_schema.<locals>.<genexpr>5   s       $a)1:L$s   requiredzCorrectly extracted `z5` with all the required parameters with correct typesr   namer   
parameters)
model_json_schemar   __doc__itemsparamsarg_namer   sortedshort_description__name__)	modelschema	docstringr   r   r   paramr   r   s	            r   r
   r
      sI    $$&Femm)r*I#)<<>W41aQ>V5V!Q$WJW !! LNN"Dz,'?? ,,,K,J|$<T$BB@K
<(.}=L $ $ .446$ Jz F"&&$-$?$?F=! ('7 8= > =! wm,  / Xs   D
Dc                L    t        |       }|d   |d   | j                         dS )z
    Generate Anthropic tool schema from a Pydantic model.

    Args:
        model: A Pydantic BaseModel subclass

    Returns:
        A dictionary in the format of Anthropic's tool schema
    r   r   )r   r   input_schema)r
   r    )r(   openai_schemas     r   r   r   I   s4     +51Mf%$]3//1     c                "   t        j                  dt        d       	 ddl}t	        t
        |j                  d            }t        |       }|j                  |d   |d   t        |d	         
      }|S # t        $ r}t        d      |d}~ww xY w)a%  
    Generate Gemini function schema from a Pydantic model.

    Args:
        model: A Pydantic BaseModel subclass

    Returns:
        A Gemini FunctionDeclaration object

    Note:
        This function is deprecated. The google-generativeai library is being replaced by google-genai.
    zhgenerate_gemini_schema is deprecated. The google-generativeai library is being replaced by google-genai.r   )
stacklevelr   Nzgoogle.generativeai.typesr   r   r   r   z`google-generativeai is deprecated. Please install google-genai instead: pip install google-genai)warningswarnDeprecationWarning	importlibr   r   import_moduler
   FunctionDeclarationr	   ImportError)r(   r5   genai_typesr.   functiones         r   r   r   ]   s     MMr3	 7 78S TU /u5 22v&%m44]<5PQ 3 
  n
	s   AA4 4	B=B		B)r(   type[BaseModel]returnzdict[str, Any])r(   r<   r=   r   )r!   
__future__r   	functoolsr2   typingr   r   docstring_parserr   pydanticr   providers.gemini.utilsr	   __all__	lru_cacher
   r   r   r   r/   r   <module>rF      s    #    "  B S!+ "+\ S! "& S!' "'r/   