
    {h                       d dl mZ d dlmZmZmZ d dlmZ d dlm	Z
 d dlmZ d dlZd dlmZ d dlZddZ	 	 	 	 ddZ	 	 	 	 dd	Z	 	 	 	 dd
Z	 	 	 	 	 	 ddZ	 	 	 	 ddZddZej0                  j2                  ddf	 	 	 	 	 	 	 	 	 	 	 ddZy)    )annotations)AnyUnion
get_origin)
ToolConfigN)	BaseModel)get_types_arrayc                    t        |       t        d|        | j                         }t        j                  |      }|d   |d   d|v r|d   ng d}|S )Nz-Expected concrete model class, got type hint type
propertiesrequired)r   r   r   )r   	TypeErrormodel_json_schemajsonrefreplace_refs)modelschemaschema_without_refsgemini_schemas       [/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/instructor/client_vertexai.py_create_gemini_json_schemar      sr    %$GwOPP$$&F*1*>*>v*F#F+),7/9=P/P
+VX	%M     c                :   t        |       t        t        |             }nt        | t              r| n| g}g }|D ]J  }t	        |      }t        j                  |j                  |j                  |      }|j                  |       L t        j                  |      S )zLCreates a tool with function declarations for single model or list of models)namedescription
parameters)function_declarations)r   listr	   
isinstancer   gmFunctionDeclaration__name____doc__appendTool)models
model_listdeclarationsr   r   declarations         r   _create_vertexai_toolr*      s    
 &%/&12
  *&$7VfX
L )/6
,,!

 	K() 7766r   c                (   t        | d   t              r;t        j                  | d   t        j                  j                  | d         g      S t        | d   t              rg }| d   D ]  }t        |t              r/|j                  t        j                  j                  |             Bt        |t        j                        r|j                  |       nt        dt        |              t        j                  | d   |      S t        d      )Ncontentrole)r-   partsz"Unsupported content type in list: z Unsupported message content type)
r   strr    ContentPart	from_textr   r$   
ValueErrorr   )messager.   items      r   vertexai_message_parserr6   6   s     ')$c*zz77$$WY%789
 	
 
GI&	-!I& 	TD$$RWW..t45D"''*T" #Ed4j\!RSS	T zz
 	

 ;<<r   c                d    | D cg c]  }t        |t              rt        |      n|! }}|S c c}w )N)r   dictr6   )messagesr4   contentss      r   _vertexai_message_list_parserr;   O   sA    
   -7w,E(7RH  O	s   $-c           	         t        j                  t         j                  j                  | j                  d   j
                  j                  d   j                  j                  dd| di      g      S )Nr   r,   zValidation Error found:
z.
Recall the function correctly, fix the errors)r   response)r.   )	r    r0   r1   from_function_response
candidatesr,   r.   function_callr   )r=   	exceptions     r   !vertexai_function_response_parserrB   Y   sq     ::GG**((+3399!<JJOO!:9+Etu + 
	 	r   c                    | j                  d      }t        |      }t        |      }t        t        j                  t        j                  j
                  j                              }||g|fS )Nr9   )r&   )mode)function_calling_config)popr;   r*   r   FunctionCallingConfigModeANY)_kwargsr   r9   r:   tooltool_configs         r   vertexai_process_responserM   h   sd     &-[[%<H,X6H .D * @ @1166::!
K
 dV[((r   c                    | j                  d      }t        |      }| j                  dd       }t        |      }t        j                  dd|d|r|ni }||fS )Nr9   generation_configzapplication/json)response_mime_typeresponse_schema )rF   r;   r   r    GenerationConfig)rJ   r   r9   r:   configrQ   rO   s          r   vertexai_process_json_responserU   y   sm    %,[[%<H,X6H$+KK0CT$JF07O++ -' 6 &&&r   Fc           
         dd l }|j                  dt        d       t        j                  j
                  t        j                  j                  t        j                  j                  h}||vr1ddlm	}  |t        |      d|D cg c]  }t        |       c}      t        | t        j                        s$ddlm}	  |	d	t        |       j                          ||d
k7  rddlm}
  |
d      |r |dd l }|j                  dt        d       |}||n|}|r| j$                  n| j&                  }t        j(                  d| t        j*                  ||      t        j,                  j.                  |d|S c c}w )Nr   au  from_vertexai is deprecated and will be removed in a future version. Please use from_genai with vertexai=True or from_provider instead. Install google-genai with: pip install google-genai
Example migration:
  # Old way
  from instructor import from_vertexai
  import vertexai.generative_models as gm
  client = from_vertexai(gm.GenerativeModel('gemini-1.5-flash'))

  # New way
  from instructor import from_genai
  from google import genai
  client = from_genai(genai.Client(vertexai=True, project='your-project', location='us-central1'))
  # OR use from_provider
  client = instructor.from_provider('vertexai/gemini-1.5-flash')   )
stacklevel)	ModeErrorVertexAI)rD   providervalid_modes)ClientErrorzOClient must be an instance of vertexai.generative_models.GenerativeModel. Got: F)ConfigurationErrorzFCannot provide both '_async' and 'use_async'. Use 'use_async' instead.z0'_async' is deprecated. Use 'use_async' instead.)createrD   )clientr_   r[   rD   rR   )warningswarnDeprecationWarning
instructorrH   VERTEXAI_PARALLEL_TOOLSVERTEXAI_TOOLSVERTEXAI_JSONinstructor.exceptionsrY   r/   r   r    GenerativeModelr]   r   r"   r^   generate_content_asyncgenerate_content
InstructorpatchProviderVERTEXAI)r`   rD   _async	use_asynckwargsra   r\   rY   mr]   r^   is_asyncr_   s                r   from_vertexairu      s    MM	K 	!  ( 	//&&%%K ;3T)45AQ5
 	
 fb0015L))*,
 	

 5< T
 	
 )#> 	 	

 	%1yvH.6V**F<S<SF   vD9$$--	
  A 6s   E;)r   r   )r&   z"BaseModel | list[BaseModel] | typereturnzgm.Tool)r4   z.dict[str, str | gm.Part | list[str | gm.Part]]rv   
gm.Content)r9   z4list[dict[str, str | gm.Part | list[str | gm.Part]]]rv   zlist[gm.Content])r=   zgm.GenerationResponserA   	Exceptionrv   rw   )rJ   dict[str, Any]r   z'Union[BaseModel, list[BaseModel], type])rJ   ry   r   r   )r`   zgm.GenerativeModelrD   zinstructor.Moderp   boolrq   zbool | Nonerr   r   rv   zinstructor.Instructor)
__future__r   typingr   r   r   "vertexai.preview.generative_modelsr   vertexai.generative_modelsgenerative_modelsr    pydanticr   rd   instructor.dsl.parallelr	   r   r   r*   r6   r;   rB   rM   rU   rH   rf   ru   rR   r   r   <module>r      s    " ) ) 9 '   3 "7.770=;==2B#09))2)"'& 'OO::!	NN
N N 	N
 N Nr   