Ë
    µŒj°z  ã                   óø  — d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZ d dlmZ d dlmZ d dlmZmZ d dlmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& d d	l'm(Z(m)Z)m*Z* d d
l+m,Z, d dl-m.Z.m/Z/m0Z0m1Z1 d dl2m3Z3m4Z4m5Z5 d dl6m7Z7m8Z8m9Z9 d dl:m;Z; d dl<m=Z= d dl>m?Z? d dl@mAZAmBZBmCZC d dlDmEZE  G d„ de«      ZFde)deGfd„ZHde(deGfd„ZIdeeJef   defd„ZKdedefd„ZLdedeGfd„ZMdeeJef   d ee   defd!„ZNy)"é    N)Ú
itemgetter)ÚPath)ÚAnyÚCallableÚDictÚIteratorÚListÚMappingÚOptionalÚSequenceÚTypeÚUnionÚcast)ÚCallbackManagerForLLMRun)ÚLanguageModelInput)ÚBaseChatModelÚgenerate_from_stream)Ú	AIMessageÚAIMessageChunkÚBaseMessageÚBaseMessageChunkÚChatMessageÚChatMessageChunkÚFunctionMessageÚFunctionMessageChunkÚHumanMessageÚHumanMessageChunkÚSystemMessageÚSystemMessageChunkÚToolMessageÚToolMessageChunk)ÚInvalidToolCallÚToolCallÚToolCallChunk)ÚOutputParserLike)ÚJsonOutputKeyToolsParserÚPydanticToolsParserÚmake_invalid_tool_callÚparse_tool_call)ÚChatGenerationÚChatGenerationChunkÚ
ChatResult)ÚRunnableÚRunnableMapÚRunnablePassthrough)ÚBaseTool)Úconvert_to_openai_tool)Úis_basemodel_subclass)Ú	BaseModelÚFieldÚmodel_validator)ÚSelfc                   ój  ‡ — e Zd ZU dZdZeed<   eed<   	 dZe	e   ed<   	 dZ
e	e   ed<   	 dZeed<   	 d	Zeed
<   	 d	Zeed<   	 dZeed<   	 dZeed<   	 dZeed<   	 dZeed<   	 dZe	e   ed<   	 dZeed<   	 dZe	e   ed<   	 dZe	e   ed<   	 dZeed<   	 dZeed<   	 dZeed<   	 dZe	e   ed<   	 dZeed<   	 dZe	ee      ed<   	 d Z eed!<   	 d"Z!eed#<   	 d$Z"eed%<   	 dZ#eed&<   	 d'Z$eed(<   	 d)Z%eed*<   	  e&e'¬+«      Z(e)eef   ed,<   	 dZ*eed-<   	 dZ+e	e,ee-f      ed.<   	 dZ.eed/<   	 dZ/eed0<   	  e0d1¬2«      d3e1fd4„«       Z2de	ee      d3e)eef   fd5„Z3d6ee4   d3ee)eef      fd7„Z5d8e'd3e6fd9„Z7	 	 dId6ee4   de	ee      d:e	e8   d;ed3e6f
d<„Z9	 	 dId6ee4   de	ee      d:e	e8   d;ed3e:e;   f
d=„Z<dd>œd?e=e,e)eef   e>e?   e@eAf      d@e	e,e'eef      d;ed3eBeCe4f   fˆ fdA„ZD	 dJddBœdCe	e,e)e>e?   f      dDed;ed3eBeCe,e)e?f   f   fdE„ZEeFd3e)eef   fdF„«       ZGeFd3efdG„«       ZHeFd3e)eef   fdH„«       ZIˆ xZJS )KÚChatLlamaCppzëllama.cpp model.

    To use, you should have the llama-cpp-python library installed, and provide the
    path to the Llama model as a named parameter to the constructor.
    Check out: https://github.com/abetlen/llama-cpp-python

    NÚclientÚ
model_pathÚ	lora_baseÚ	lora_pathi   Ún_ctxéÿÿÿÿÚn_partsÚseedTÚf16_kvFÚ
logits_allÚ
vocab_onlyÚ	use_mlockÚ	n_threadsé   Ún_batchÚn_gpu_layersÚsuffixé   Ú
max_tokensgš™™™™™é?Útemperaturegffffffî?Útop_pÚlogprobsÚechoÚstopgš™™™™™ñ?Úrepeat_penaltyé(   Útop_ké@   Úlast_n_tokens_sizeÚuse_mmapg      ð?Úrope_freq_scaleg     ˆÃ@Úrope_freq_base)Údefault_factoryÚmodel_kwargsÚ	streamingÚgrammar_pathÚgrammarÚverboseÚafter)ÚmodeÚreturnc                 óÎ  — 	 ddl m}m} | j                  }g d¢}|D �ci c]  }|t        | |«      “Œ }}| j                  �| j                  |d<   |j                  | j                  «       	  ||fi |¤Ž| _	        | j                  r6| j                  r*| j                  }| j                  }	t        d	|›d
|	›d�«      ‚t        | j                  t        «      r"|j!                  | j                  «      | _        | S | j                  r"|j#                  | j                  «      | _        | S 	 | S # t        $ r t        d«      ‚w xY wc c}w # t        $ r}t        d|› d|› �«      ‚d}~ww xY w)z4Validate that llama-cpp-python library is installed.r   )ÚLlamaÚLlamaGrammarz�Could not import llama-cpp-python library. Please install the llama-cpp-python library to use this embedding model: pip install llama-cpp-python)rW   rX   r<   r;   r=   r?   r@   rA   rB   rC   rD   rE   rG   rV   rU   r^   NrH   z&Could not load Llama model from path: z. Received error zCCan only pass in one of grammar and grammar_path. Received grammar=z and grammar_path=Ú.)Ú	llama_cpprc   rd   ÚImportErrorr:   ÚgetattrrH   ÚupdaterZ   r9   Ú	ExceptionÚ
ValueErrorr]   r\   Ú
isinstanceÚstrÚfrom_stringÚ	from_file)
Úselfrc   rd   r:   Úmodel_param_namesÚkÚmodel_paramsÚer]   r\   s
             úr/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/chat_models/llamacpp.pyÚvalidate_environmentz!ChatLlamaCpp.validate_environment°   s“  € ð	ß5ð —_‘_ˆ
ò
Ðñ$ 6GÓGÑ5F°˜œ7 4¨Ó+Ñ+Ð5FˆÐGà×ÑÐ(Ø+/×+<Ñ+<ˆL˜Ñ(à×Ñ˜D×-Ñ-Ô.ð	Ù 
Ñ;¨lÑ;ˆDŒKð �<Š<˜D×-Ò-Ø—l‘lˆGØ×,Ñ,ˆLÜðØ�*Ð/ , °ð3óð ô ˜Ÿ™¤cÔ*Ø'×3Ñ3°D·L±LÓAˆDŒLð
 ˆð	 ×ÒØ'×1Ñ1°$×2CÑ2CÓDˆDŒLð ˆð Øˆøôm ò 	ÜðIóð ð	üò4 Høô ò 	ÜØ8¸¸ð E"Ø"# ð&óð ûð	ús(   ‚D( žE Á+E Ä(D=Å	E$ÅEÅE$c                 óv   — | j                   }|j                  d«      }|xs |xs | j                  xs g |d<   |S )z©
        Performs sanity check, preparing parameters in format needed by llama_cpp.

        Returns:
            Dictionary containing the combined parameters.
        Ústop_sequencesrP   )Ú_default_paramsÚpoprP   )rp   rP   Úparamsrx   s       ru   Ú_get_parameterszChatLlamaCpp._get_parametersí   sC   € ð ×%Ñ%ˆð  Ÿ™Ð$4Ó5ˆð ÒB ÒB°4·9±9ÒBÀˆˆv‰àˆó    Úmessagesc                 ó@   — |D �cg c]  }t        |«      ‘Œ }}|S c c}w ©N)Ú_convert_message_to_dict)rp   r~   ÚmÚmessage_dictss       ru   Ú_create_message_dictsz"ChatLlamaCpp._create_message_dictsÿ   s+   € ñ ?GÓG¹h¸Ô1°!Õ4¸hˆÐGàÐùò Hs   …Úresponsec                 ó  — g }|d   D ]U  }t        |d   «      }t        |j                  d«      ¬«      }d|v r|d   |d<   t        ||¬«      }|j	                  |«       ŒW |j                  di «      }d|i}t        ||¬	«      S )
NÚchoicesÚmessageÚfinish_reason)r‰   rN   ©rˆ   Úgeneration_infoÚusageÚtoken_usage)ÚgenerationsÚ
llm_output)Ú_convert_dict_to_messageÚdictÚgetr*   Úappendr,   )	rp   r…   rŽ   Úresrˆ   r‹   Úgenr�   r�   s	            ru   Ú_create_chat_resultz ChatLlamaCpp._create_chat_result  s”   € ØˆØ˜IÔ&ˆCÜ.¨s°9©~Ó>ˆGÜ"°·±¸Ó1IÔJˆOØ˜SÑ Ø.1°*©o� 
Ñ+Ü ¨À/ÔRˆCØ×Ñ˜sÕ#ð 'ð —l‘l 7¨BÓ/ˆà˜;ð
ˆ
ô  k¸jÔIÐIr}   Úrun_managerÚkwargsc                 ó&  — i | j                  |«      ¥|¥}| j                  r1|j                  d«      s  | j                  |fd|i|¤Ž}t	        |«      S | j                  |«      } | j                  j                  dd|i|¤Ž}| j                  |«      S )NÚtool_choicer—   r~   © )	r|   r[   r’   Ú_streamr   r„   r9   Úcreate_chat_completionr–   )	rp   r~   rP   r—   r˜   r{   Ústream_iterrƒ   r…   s	            ru   Ú	_generatezChatLlamaCpp._generate  s—   € ð :�D×(Ñ(¨Ó.Ð9°&Ð9ˆð �>Š> &§*¡*¨]Ô";Ø&˜$Ÿ,™, xÑS¸[ÐSÈFÑSˆKÜ'¨Ó4Ð4à×2Ñ2°8Ó<ˆà5�4—;‘;×5Ñ5ÑW¸}ÐWÐPVÑWˆà×'Ñ'¨Ó1Ð1r}   c              +   óB  K  — i | j                  |«      ¥|¥}| j                  |«      } | j                  j                  d|ddœ|¤Ž}t        }d}	|D ]É  }
|	dz  }	t        |
t        «      s|
j                  «       }
t        |
d   «      dk(  rŒ:|
d   d   }|d   €ŒHt        |d   |«      }
i }|j                  d«      x}r||d<   |j                  d«      }|r||d<   |
j                  }t        |
|xs d ¬	«      }
|r|j                  |
j                  |
|¬
«       |
–— ŒË y ­w)NT)r~   Ústreamr   é   r‡   Údeltar‰   rN   rŠ   )ÚchunkrN   r›   )r|   r„   r9   r�   r   rl   r‘   Ú
model_dumpÚlenÚ_convert_delta_to_message_chunkr’   Ú	__class__r+   Úon_llm_new_tokenÚtext)rp   r~   rP   r—   r˜   r{   rƒ   ÚresultÚdefault_chunk_classÚcountr¤   Úchoicer‹   r‰   rN   s                  ru   rœ   zChatLlamaCpp._stream+  sY  è ø€ ð :�D×(Ñ(¨Ó.Ð9°&Ð9ˆØ×2Ñ2°8Ó<ˆà3�—‘×3Ñ3ð 
Ø"¨4ñ
Ø39ñ
ˆô 7EÐØˆÛˆEØ�Q‰JˆEÜ˜e¤TÔ*Ø×(Ñ(Ó*�Ü�5˜Ñ#Ó$¨Ò)ØØ˜9Ñ% aÑ(ˆFØ�g‰Ð&ØÜ3Ø�w‘Ð!4óˆEð !ˆOØ &§
¡
¨?Ó ;Ð;ˆ}Ð;Ø3@� Ñ0Ø—z‘z *Ó-ˆHÙØ.6� 
Ñ+Ø"'§/¡/ÐÜ'Ø¨Ò/FÀ$ôˆEñ Ø×,Ñ,¨U¯Z©Z¸uÈxÐ,ÔXØ‹Kñ1 ùs   ‚DD©rš   Útoolsrš   c                óf  •‡— |D �cg c]  }t        |«      ‘Œ }}|D �cg c]
  }|d   d   ‘Œ }}‰r¿t        ‰t        «      r&t        ˆfd„|D «       «      s›t	        d‰›d|› d�«      ‚t        ‰t
        «      r/|D �cg c]  }|d   d   ‰k(  sŒ|‘Œ }	}|	s\t	        d‰›d|› d�«      ‚t        ‰t        «      r,t        |«      dkD  rt	        dt        |«      › d	�«      ‚|d
   Šnt	        d‰› �«      ‚‰|d<   |D �cg c]  }t        |«      ‘Œ }}t        ‰
| �$  dd|i|¤ŽS c c}w c c}w c c}w c c}w )a  Bind tool-like objects to this chat model

        tool_choice: does not currently support "any", "auto" choices like OpenAI
            tool-calling API. should be a dict of the form to force this tool
            {"type": "function", "function": {"name": <<tool_name>>}}.
        ÚfunctionÚnamec              3   ó4   •K  — | ]  }‰d    d   |k(  –— Œ y­w)r²   r³   Nr›   )Ú.0r³   rš   s     €ru   Ú	<genexpr>z*ChatLlamaCpp.bind_tools.<locals>.<genexpr>f  s$   øè ø€ ð ÙHRÀ�K 
Ñ+¨FÑ3°tÕ;É
ùs   ƒzTool choice tool_choice=z1 was specified, but the only provided tools were re   r¢   zQtool_choice=True can only be specified when a single tool is passed in. Received z tools.r   z�Unrecognized tool_choice type. Expected dict having format like 
                    this {"type": "function", "function": {"name": <<tool_name>>}}Received: rš   r°   r›   )
r1   rl   r‘   Úanyrk   rm   Úboolr¦   ÚsuperÚbind)rp   r°   rš   r˜   ÚtoolÚformatted_toolsÚftÚ
tool_namesÚfÚchosenr¨   s     `       €ru   Ú
bind_toolszChatLlamaCpp.bind_toolsU  sŸ  ù€ ñ EJÓJÁE¸DÔ1°$Õ7ÀEˆÐJÙ7FÓG±°�b˜‘n VÓ,°ˆ
ÐGÙÜ˜+¤tÔ,Üó ÙHRóô ô %Ø3 { nð 5/Ø/9¨l¸!ð=óð ô ˜K¬Ô-á.óÙ.˜!°!°J±-ÀÑ2GÈ;Ó2V’A˜ð ð ñ Ü$Ø3 { nð 5/Ø/9¨l¸!ð=óð ô ˜K¬Ô.Ü�Ó'¨!Ò+Ü$ð/Ü/2°5«z¨l¸'ðCóð ð .¨aÑ0‘ä ð!à!, ð/óð ð !,ˆˆ}ÑÙDIÓJÁE¸DÔ1°$Õ7ÀEˆÐJÜ‰w‰|Ñ< /Ð<°VÑ<Ð<ùòI KùÚGùòùò. Ks   ‡DŸD$Á<D)ÂD)Ã:D.)Úinclude_rawÚschemarÂ   c                óð  — |rt        d|› �«      ‚t        |t        «      xr t        |«      }|€t        d«      ‚t	        |«      d   d   }dd|idœ}| j                  |g|¬«      }|rt        t        t        |«      gd¬«      }nt        |d¬	«      }|r^t        j                  t        d
«      |z  d„ ¬«      }	t        j                  d„ ¬«      }
|	j                  |
gd¬«      }t        |¬«      |z  S ||z  S )at  Model wrapper that returns outputs formatted to match the given schema.

        Args:
            schema: The output schema as a dict or a Pydantic class. If a Pydantic class
                then the model output will be an object of that class. If a dict then
                the model output will be a dict. With a Pydantic class the returned
                attributes will be validated, whereas with a dict they will not be. If
                `method` is "function_calling" and `schema` is a dict, then the dict
                must match the OpenAI function-calling spec or be a valid JSON schema
                with top level 'title' and 'description' keys specified.
            include_raw: If False then only the parsed structured output is returned. If
                an error occurs during model output parsing it will be raised. If True
                then both the raw model response (a BaseMessage) and the parsed model
                response will be returned. If an error occurs during output parsing it
                will be caught and returned as well. The final output is always a dict
                with keys "raw", "parsed", and "parsing_error".
            kwargs: Any other args to bind to model, ``self.bind(..., **kwargs)``.

        Returns:
            A Runnable that takes any ChatModel input and returns as output:

                If include_raw is True then a dict with keys:
                    raw: BaseMessage
                    parsed: Optional[_DictOrPydantic]
                    parsing_error: Optional[BaseException]

                If include_raw is False then just _DictOrPydantic is returned,
                where _DictOrPydantic depends on the schema:

                If schema is a Pydantic class then _DictOrPydantic is the Pydantic
                    class.

                If schema is a dict then _DictOrPydantic is a dict.

        Example: Pydantic schema (include_raw=False):
            .. code-block:: python

                from langchain_community.chat_models import ChatLlamaCpp
                from pydantic import BaseModel

                class AnswerWithJustification(BaseModel):
                    '''An answer to the user question along with justification for the answer.'''
                    answer: str
                    justification: str

                llm = ChatLlamaCpp(
                    temperature=0.,
                    model_path="./SanctumAI-meta-llama-3-8b-instruct.Q8_0.gguf",
                    n_ctx=10000,
                    n_gpu_layers=4,
                    n_batch=200,
                    max_tokens=512,
                    n_threads=multiprocessing.cpu_count() - 1,
                    repeat_penalty=1.5,
                    top_p=0.5,
                    stop=["<|end_of_text|>", "<|eot_id|>"],
                )
                structured_llm = llm.with_structured_output(AnswerWithJustification)

                structured_llm.invoke("What weighs more a pound of bricks or a pound of feathers")

                # -> AnswerWithJustification(
                #     answer='They weigh the same',
                #     justification='Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ.'
                # )

        Example: Pydantic schema (include_raw=True):
            .. code-block:: python

                from langchain_community.chat_models import ChatLlamaCpp
                from pydantic import BaseModel

                class AnswerWithJustification(BaseModel):
                    '''An answer to the user question along with justification for the answer.'''
                    answer: str
                    justification: str

                llm = ChatLlamaCpp(
                    temperature=0.,
                    model_path="./SanctumAI-meta-llama-3-8b-instruct.Q8_0.gguf",
                    n_ctx=10000,
                    n_gpu_layers=4,
                    n_batch=200,
                    max_tokens=512,
                    n_threads=multiprocessing.cpu_count() - 1,
                    repeat_penalty=1.5,
                    top_p=0.5,
                    stop=["<|end_of_text|>", "<|eot_id|>"],
                )
                structured_llm = llm.with_structured_output(AnswerWithJustification, include_raw=True)

                structured_llm.invoke("What weighs more a pound of bricks or a pound of feathers")
                # -> {
                #     'raw': AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_Ao02pnFYXD6GN1yzc0uXPsvF', 'function': {'arguments': '{"answer":"They weigh the same.","justification":"Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ."}', 'name': 'AnswerWithJustification'}, 'type': 'function'}]}),
                #     'parsed': AnswerWithJustification(answer='They weigh the same.', justification='Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ.'),
                #     'parsing_error': None
                # }

        Example: dict schema (include_raw=False):
            .. code-block:: python

                from langchain_community.chat_models import ChatLlamaCpp
                from pydantic import BaseModel
                from langchain_core.utils.function_calling import convert_to_openai_tool

                class AnswerWithJustification(BaseModel):
                    '''An answer to the user question along with justification for the answer.'''
                    answer: str
                    justification: str

                dict_schema = convert_to_openai_tool(AnswerWithJustification)
                llm = ChatLlamaCpp(
                    temperature=0.,
                    model_path="./SanctumAI-meta-llama-3-8b-instruct.Q8_0.gguf",
                    n_ctx=10000,
                    n_gpu_layers=4,
                    n_batch=200,
                    max_tokens=512,
                    n_threads=multiprocessing.cpu_count() - 1,
                    repeat_penalty=1.5,
                    top_p=0.5,
                    stop=["<|end_of_text|>", "<|eot_id|>"],
                )
                structured_llm = llm.with_structured_output(dict_schema)

                structured_llm.invoke("What weighs more a pound of bricks or a pound of feathers")
                # -> {
                #     'answer': 'They weigh the same',
                #     'justification': 'Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume and density of the two substances differ.'
                # }

        zReceived unsupported arguments zJschema must be specified when method is 'function_calling'. Received None.r²   r³   )Útyper²   r¯   T)r°   Úfirst_tool_only)Úkey_namerÆ   Úrawc                  ó   — y r€   r›   ©Ú_s    ru   Ú<lambda>z5ChatLlamaCpp.with_structured_output.<locals>.<lambda>*  s   € ÐRVr}   )ÚparsedÚparsing_errorc                  ó   — y r€   r›   rÊ   s    ru   rÌ   z5ChatLlamaCpp.with_structured_output.<locals>.<lambda>,  s   € Àdr}   )rÍ   rÎ   )Úexception_key)rÈ   )rk   rl   rÅ   r2   r1   rÁ   r'   r   r   r&   r/   Úassignr   Úwith_fallbacksr.   )rp   rÃ   rÂ   r˜   Úis_pydantic_schemaÚ	tool_namerš   ÚllmÚoutput_parserÚparser_assignÚparser_noneÚparser_with_fallbacks               ru   Úwith_structured_outputz#ChatLlamaCpp.with_structured_outputˆ  s#  € ñX ÜÐ>¸v¸hÐGÓHÐHÜ'¨´Ó5ÒWÔ:OÐPVÓ:WÐØˆ>Üð!óð ô +¨6Ó2°:Ñ>¸vÑFˆ	Ø)¸À	Ð7JÑKˆØ�o‰o˜v˜h°KˆoÓ@ˆÙÜ.AÜœD &Ó)Ð*¸Dô/‰Mô 5Ø"°DôˆMñ Ü/×6Ñ6Ü! %Ó(¨=Ñ8ÉôˆMô .×4Ñ4¹NÔKˆKØ#0×#?Ñ#?Ø�¨_ð $@ó $Ð ô  3Ô'Ð*>Ñ>Ð>à˜Ñ&Ð&r}   c                 ó:   — i d| j                   i¥| j                  ¥S )zÈReturn a dictionary of identifying parameters.

        This information is used by the LangChain callback system, which
        is used for tracing purposes make it possible to monitor LLMs.
        r:   )r:   ry   ©rp   s    ru   Ú_identifying_paramsz ChatLlamaCpp._identifying_params4  s/   € ð
ð
 ˜TŸ_™_Ð-ð
ð ×"Ñ"ð
ð 	
r}   c                  ó   — y)z7Get the type of language model used by this chat model.zllama-cpp-pythonr›   rÜ   s    ru   Ú	_llm_typezChatLlamaCpp._llm_typeD  s   € ð "r}   c                 óÜ   — | j                   | j                  | j                  | j                  | j                  | j
                  | j                  dœ}| j                  r| j                  |d<   |S )z>Get the default parameters for calling create_chat_completion.)rK   rL   rM   rS   rN   rx   rQ   r]   )rK   rL   rM   rS   rN   rP   rQ   r]   )rp   r{   s     ru   ry   zChatLlamaCpp._default_paramsI  s\   € ð Ÿ/™/Ø×+Ñ+Ø—Z‘ZØ—Z‘ZØŸ™Ø"Ÿi™iØ"×1Ñ1ñ
ˆð �<Š<Ø $§¡ˆF�9ÑØˆr}   )NNr€   )KÚ__name__Ú
__module__Ú__qualname__Ú__doc__r9   r   Ú__annotations__rm   r;   r   r<   r=   Úintr?   r@   rA   r¸   rB   rC   rD   rE   rG   rH   rI   rK   rL   ÚfloatrM   rN   rO   rP   r	   rQ   rS   rU   rV   rW   rX   r4   r‘   rZ   r   r[   r\   r   r   r]   r^   r5   r6   rv   r|   r   r„   r,   r–   r   rŸ   r   r+   rœ   r   r   r3   r   r0   r-   r   rÁ   rÚ   ÚpropertyrÝ   rß   ry   Ú__classcell__)r¨   s   @ru   r8   r8   =   sO  ø… ñð €FˆCÓàƒOØ+à#€Iˆx˜‰}Ó#Ø0à#€Iˆx˜‰}Ó#ØAà€Eˆ3ÓØà€GˆSÓð?ð €Dˆ#ƒNØ-à€FˆDÓØ1à€J�ÓØ@à€J�ÓØ/à€IˆtÓØ,à#€Iˆx˜‰}Ó#ðCð €GˆSÓð/ð #'€L�(˜3‘-Ó&ØFà €FˆH�S‰MÓ ØSà€J�ÓØ3à€K�ÓØ.à€Eˆ5ÓØ.à"€Hˆh�s‰mÓ"ØNà€Dˆ$ÓØ%à $€Dˆ(�4˜‘9Ñ
Ó$Ø@à€N�EÓØ2à€Eˆ3ƒOØ.à Ð˜Ó ØMà€HˆdÓØ1à €O�UÓ Ø)à#€N�EÓ#Ø+á#(¸Ô#>€L�$�s˜C�x‘.Ó>Ø?à€IˆtÓØ8à/3€L�(˜5  d Ñ+Ñ,Ó3ðð €GˆSÓðð €GˆTÓØ)á˜'Ô"ð: dò :ó #ð:ðx H¨T°#©YÑ$7ð ¸DÀÀcÀ¹Nó ð$Ø˜[Ñ)ðà	ˆd�3˜�8‰nÑ	óðJ¨Dð J°Zó Jð& %)Ø:>ñ	2à�{Ñ#ð2ð �t˜C‘yÑ!ð2ð Ð6Ñ7ð	2ð
 ð2ð 
ó2ð0 %)Ø:>ñ	(à�{Ñ#ð(ð �t˜C‘yÑ!ð(ð Ð6Ñ7ð	(ð
 ð(ð 
Ð%Ñ	&ó(ð\ 9=ò	1=à˜˜d 3¨ 8™n¨d°9©o¸xÈÐQÑRÑSð1=ð ˜e D¨$° OÑ4Ñ5ð	1=ð
 ð1=ð 
Ð$ kÐ1Ñ	2õ1=ðj :>ðj'ð "ò	j'à˜˜t T¨)¡_Ð4Ñ5Ñ6ðj'ð ð	j'ð
 ðj'ð 
Ð$ e¨D°)¨OÑ&<Ð<Ñ	=ój'ðX ð
 T¨#¨s¨(¡^ò 
ó ð
ð ð"˜3ò "ó ð"ð ð  c¨3 h¡ò ó ôr}   r8   Ú	tool_callra   c                 óL   — d| d   | d   t        j                  | d   «      dœdœS ©Nr²   Úidr³   Úargs)r³   Ú	arguments)rÅ   rí   r²   )ÚjsonÚdumps)rê   s    ru   Ú!_lc_tool_call_to_openai_tool_callrò   Z  s4   € àØ˜‰oà˜fÑ%ÜŸ™ I¨fÑ$5Ó6ñ
ñð r}   Úinvalid_tool_callc                 ó&   — d| d   | d   | d   dœdœS rì   r›   )ró   s    ru   Ú)_lc_invalid_tool_call_to_openai_tool_callrõ   e  s.   € ð Ø Ñ%à% fÑ-Ø*¨6Ñ2ñ
ñð r}   Ú_dictc           	      ó  — | j                  d«      }| j                  d«      }| j                  d«      }|dk(  rt        | j                  dd«      ||¬«      S |dk(  r�| j                  dd«      xs d}i }| j                  d	«      x}rt        |«      |d	<   g }g }| j                  d
«      x}	r.|	|d
<   |	D ]$  }
	 t        |
d¬«      }|sŒ|j	                  |«       Œ& t        ||||||¬«      S |dk(  rt        | j                  dd«      ||¬«      S |dk(  r;t        | j                  dd«      t        t        | j                  d«      «      |¬«      S |dk(  rKi }d| v r| d   |d<   t        | j                  dd«      t        t        | j                  d«      «      |||¬«      S t        | j                  dd«      t        t        |«      |¬«      S # t
        $ r1}t        |
t        |«      «      }|j	                  |«       Y d}~�ŒLd}~ww xY w)zˆConvert a dictionary to a LangChain message.

    Args:
        _dict: The dictionary.

    Returns:
        The LangChain message.
    Úroler³   rí   ÚuserÚcontentÚ )rú   rí   r³   Ú	assistantÚfunction_callÚ
tool_callsT)Ú	return_idN)rú   Úadditional_kwargsr³   rí   rþ   Úinvalid_tool_callsÚsystem©rú   r³   rí   r²   r»   Útool_call_id)rú   r  r   r³   rí   ©rú   rø   rí   )r’   r   r‘   r)   r“   rj   r(   rm   r   r   r   r   r    r   )rö   rø   r³   Úid_rú   r   rý   rþ   r  Úraw_tool_callsÚraw_tool_callÚtcrt   Ú
invalid_tcs                 ru   r�   r�   r  s&  € ð �9‰9�VÓ€DØ�9‰9�VÓ€DØ
�)‰)�D‹/€CØˆv‚~Ü E§I¡I¨i¸Ó$<ÀÈ4ÔPÐPØ	�Ò	ð —)‘)˜I rÓ*Ò0¨bˆØ"$ÐØ!ŸI™I oÓ6Ð6ˆ=Ð6Ü15°mÓ1DÐ˜oÑ.Øˆ
ØÐØ"ŸY™Y |Ó4Ð4ˆ>Ð4Ø.<Ð˜lÑ+Û!/�ð	.Ü(¨À$ÔG�Bñ
 Ø à"×)Ñ)¨"Õ-ð "0ô ØØ/ØØØ!Ø1ô
ð 	
ð 
�Ò	Ü U§Y¡Y¨y¸"Ó%=ÀDÈSÔQÐQØ	�Ò	ÜØ—I‘I˜i¨Ó,´4¼¸U¿Y¹YÀvÓ=NÓ3OÐTWô
ð 	
ð 
�ŠØÐØ�U‰?Ø(-¨f©Ð˜fÑ%ÜØ—I‘I˜i¨Ó,Üœc 5§9¡9¨^Ó#<Ó=Ø/ØØô
ð 	
ô Ø—I‘I˜i¨Ó,´4¼¸T³?Àsô
ð 	
øôE !ò :Ü!7¸ÄsÈ1ÃvÓ!N�JØ&×-Ñ-¨j×9Ò9ûð:ús   Â7G
Ç
	HÇ&G?Ç?Hrú   c                 ó    — | rIt        | t        «      r9g }| D ]0  }t        |t        «      rd|v r	|d   dk(  rŒ |j                  |«       Œ2 |S | }|S )zFormat message content.rÅ   Útool_use)rl   Úlistr‘   r“   )rú   Úformatted_contentÚblocks      ru   Ú_format_message_contentr  µ  sb   € á”:˜g¤tÔ,àÐÛˆEä˜5¤$Ô'Ø˜e‘OØ˜&‘M ZÒ/àà!×(Ñ(¨Õ/ð ð Ðð $ÐàÐr}   rˆ   c                 ó‚  — dt        | j                  «      i}| j                  xs | j                  j	                  d«      x}�||d<   t        | t        «      r| j                  |d<   |S t        | t        «      rd|d<   |S t        | t        «      �rd|d<   d| j                  v r| j                  d   |d<   | j                  s| j                  rK| j                  D �cg c]  }t        |«      ‘Œ c}| j                  D �cg c]  }t        |«      ‘Œ c}z   |d<   ngd| j                  v rX| j                  d   |d<   h d	£}|d   D ���cg c]+  }|j                  «       D ��ci c]  \  }}||v sŒ||“Œ c}}‘Œ- c}}}|d<   n	 d|v sd|v r|d   xs d|d<   |S t        | t        «      rd
|d<   |S t        | t         «      rd|d<   |S t        | t"        «      rBd|d<   | j$                  |d<   h d£}|j                  «       D ��ci c]  \  }}||v sŒ||“Œ }}}|S t'        d| › �«      ‚c c}w c c}w c c}}w c c}}}w c c}}w )zŠConvert a LangChain message to a dictionary.

    Args:
        message: The LangChain message.

    Returns:
        The dictionary.
    rú   r³   Nrø   rù   rü   rý   rþ   >   rí   rÅ   r²   r  r²   r»   r  >   rø   rú   r  zGot unknown type )r  rú   r³   r   r’   rl   r   rø   r   r   rþ   r  rò   rõ   Úitemsr   r   r    r  Ú	TypeError)	rˆ   Úmessage_dictr³   r	  Útool_call_supported_propsrê   rr   ÚvÚsupported_propss	            ru   r�   r�   É  sª  € ð 	Ô*¨7¯?©?Ó;ð$€Lð —‘ÒE × 9Ñ 9× =Ñ =¸fÓ EÐEˆÐRØ#ˆ�VÑô �'œ;Ô'Ø&Ÿ|™|ˆ�VÑðL ÐôK 
�Gœ\Ô	*Ø%ˆ�VÑðH ÐôG 
�GœYÕ	'Ø*ˆ�VÑØ˜g×7Ñ7Ñ7Ø,3×,EÑ,EÀoÑ,VˆL˜Ñ)Ø×Ò ×!;Ò!;à@G×@RÒ@Ró*Ù@R¸"Ô1°"Õ5Ð@Rñ*ð "×4Ò4óá4�Bô :¸"Õ=Ø4ññ*ˆL˜Ò&ð ˜W×6Ñ6Ñ6Ø)0×)BÑ)BÀ<Ñ)PˆL˜Ñ&Ú(BÐ%ð ".¨lÒ!;õ*á!;�Ið #,§/¡/Ô"3ÔVÑ"3™$˜!˜Q°qÐ<UÒ7U��A‘Ð"3ÔVØ!;ó*ˆL˜Ò&ð
 à˜lÑ*¨l¸lÑ.JØ&2°9Ñ&=Ò&EÀˆL˜Ñ#ð Ðô 
�Gœ]Ô	+Ø'ˆ�VÑð Ðô 
�Gœ_Ô	-Ø)ˆ�VÑð Ðô 
�Gœ[Ô	)Ø%ˆ�VÑØ'.×';Ñ';ˆ�^Ñ$â=ˆØ)5×);Ñ);Ô)=ÔVÑ)=¡  AÀÀoÒAU˜˜1™Ð)=ˆÑVð Ðô Ð+¨G¨9Ð5Ó6Ð6ùò;*ùòùó Wùô*ùó$ Ws6   ÃH$Ã>H)ÅH4ÅH.Å+H.Å0H4Ç?H;ÈH;È.H4Údefault_classc                 óˆ  — | j                  d«      }t        t        | j                  d«      «      }t        t        | j                  d«      xs d«      }i }| j                  d«      r!t        | d   «      }d|v r
|d   €d|d<   ||d<   g }| j                  d«      x}rc||d<   |D ]Y  }		 t	        |	d   j                  d«      |	d   j                  d	«      |	j                  d«      |	d
   ¬«      }
|j                  |
«       Œ[ |dk(  s	|t        k(  rt        ||¬«      S |dk(  s	|t        k(  rt        ||||¬«      S |dk(  s	|t        k(  rt        ||¬«      S |dk(  s	|t        k(  rt        || d   |¬«      S |dk(  s	|t        k(  rt        || d   |¬«      S |s	|t        k(  rt        |||¬«      S  |||¬«      S # t        $ r Y �Œw xY w)Nrí   rø   rú   rû   rý   r³   rþ   r²   rï   Úindex)r³   rî   rí   r  rù   )rú   rí   rü   )rú   r   rí   Útool_call_chunksr  r  r»   r  )rú   r  rí   r  )r’   r   rm   r‘   r$   r“   ÚKeyErrorr   r   r   r   r!   r   )rö   r  r  rø   rú   r   rý   r  r  Úrtcrê   s              ru   r§   r§     sù  € ð �)‰)�D‹/€CÜ”�U—Y‘Y˜vÓ&Ó'€DÜ”3˜Ÿ	™	 )Ó,Ò2°Ó3€GØ ÐØ‡y�y�Ô!Ü˜U ?Ñ3Ó4ˆØ�]Ñ" }°VÑ'<Ð'DØ$&ˆM˜&Ñ!Ø-:Ð˜/Ñ*ØÐØŸ™ <Ó0Ð0€~Ð0Ø*8Ð˜,Ñ'Û!ˆCð	Ü)Ø˜Z™×,Ñ,¨VÓ4Ø˜Z™×,Ñ,¨[Ó9Ø—w‘w˜t“}Ø˜g™,ô	�	ð !×'Ñ'¨	Õ2ð "ð ˆv‚~˜Ô*;Ò;Ü ¨°SÔ9Ð9Ø	�Ò	 ´Ò ?ÜØØ/ØØ-ô	
ð 	
ð 
�Ò	˜]Ô.@Ò@Ü!¨'°cÔ:Ð:Ø	�Ò	˜}Ô0DÒDÜ#¨G¸%À¹-ÈCÔPÐPØ	�Š˜=Ô,<Ò<ÜØ¨%°Ñ*?ÀCô
ð 	
ñ 
�Ô"2Ò2Ü¨°d¸sÔCÐCá W°Ô5Ð5øô/ ò Úðús   Â(AF4Æ4	GÇ G)Orð   Úoperatorr   Úpathlibr   Útypingr   r   r   r   r	   r
   r   r   r   r   r   Úlangchain_core.callbacksr   Úlangchain_core.language_modelsr   Ú*langchain_core.language_models.chat_modelsr   r   Úlangchain_core.messagesr   r   r   r   r   r   r   r   r   r   r   r   r    r!   Úlangchain_core.messages.toolr"   r#   r$   Ú"langchain_core.output_parsers.baser%   Ú*langchain_core.output_parsers.openai_toolsr&   r'   r(   r)   Úlangchain_core.outputsr*   r+   r,   Úlangchain_core.runnablesr-   r.   r/   Úlangchain_core.toolsr0   Ú%langchain_core.utils.function_callingr1   Úlangchain_core.utils.pydanticr2   Úpydanticr3   r4   r5   Útyping_extensionsr6   r8   r‘   rò   rõ   rm   r�   r  r�   r§   r›   r}   ru   Ú<module>r/     s*  ðÛ Ý Ý ÷÷ ÷ ñ õ >Ý =÷÷÷ ÷ ÷ ÷  RÑ QÝ ?÷ó ÷ SÑ Rß OÑ OÝ )Ý HÝ ?÷ñ õ
 #ôZ�=ô Zðz°ð ¸dó ð
Ø&ð
à	ó
ð@
 G¨C°¨HÑ$5ð @
¸+ó @
ðF Sð ¨Só ð(7 kð 7°dó 7ðt/6Ø�3˜�8Ñð/6Ø-1Ð2BÑ-Cð/6àô/6r}   