
    Ah                     4   S SK JrJr  S SKJr  S SKJr  S SKJrJ	r	  S SK
JrJr  S SKJr  S SKJr  S SKJr  S S	KJrJrJr  S
\S\4S jrSr\" SSSSS9   SS\S\S\\   S\\\      S\S\4S jj5       r\" SSSSS9  SS\S\S\\   S\S\4
S jj5       rg)    )AnyOptional)
deprecated)BaseLanguageModel)JsonKeyOutputFunctionsParser!PydanticAttrOutputFunctionsParser)BasePromptTemplateChatPromptTemplate)	BaseModel)Chain)LLMChain)_convert_schema_resolve_schema_referencesget_llm_kwargsentity_schemareturnc                 4    SSSSS[        U 5      S.0S/S.S.$ )	Ninformation_extractionz3Extracts the relevant information from the passage.objectinfoarray)typeitems)r   
propertiesrequired)namedescription
parameters)r   )r   s    d/var/www/html/shao/venv/lib/python3.13/site-packages/langchain/chains/openai_functions/extraction.py_get_extraction_functionr       s5    (L?=3QR  

 
    a<  Extract and save the relevant entities mentioned in the following passage together with their properties.

Only extract the properties mentioned in the 'information_extraction' function.

If a property is not present and is not required in the function parameters, do not include it in the output.

Passage:
{input}
z0.1.14a  LangChain has introduced a method called `with_structured_output` thatis available on ChatModels capable of tool calling.You can read more about the method here: <https://python.langchain.com/docs/modules/model_io/chat/structured_output/>. Please follow our extraction use case documentation for more guidelineson how to do information extraction with LLMs.<https://python.langchain.com/docs/use_cases/extraction/>. If you notice other issues, please provide feedback here:<https://github.com/langchain-ai/langchain/discussions/18154>z1.0a)  
            from pydantic import BaseModel, Field
            from langchain_anthropic import ChatAnthropic

            class Joke(BaseModel):
                setup: str = Field(description="The setup of the joke")
                punchline: str = Field(description="The punchline to the joke")

            # Or any other chat model that supports tools.
            # Please reference to to the documentation of structured_output
            # to see an up to date list of which models support
            # with_structured_output.
            model = ChatAnthropic(model="claude-3-opus-20240229", temperature=0)
            structured_llm = model.with_structured_output(Joke)
            structured_llm.invoke("Tell me a joke about cats.
                Make sure to call the Joke function.")
            )sincemessageremovalalternativeNschemallmprompttagsverbosec           	          [        U 5      nU=(       d    [        R                  " [        5      n[	        SS9n[        U5      n[        UUUUUUS9$ )a  Creates a chain that extracts information from a passage.

Args:
    schema: The schema of the entities to extract.
    llm: The language model to use.
    prompt: The prompt to use for extraction.
    verbose: Whether to run in verbose mode. In verbose mode, some intermediate
        logs will be printed to the console. Defaults to the global `verbose` value,
        accessible via `langchain.globals.get_verbose()`.

Returns:
    Chain that can be used to extract information from a passage.
r   )key_name)r'   r(   
llm_kwargsoutput_parserr)   r*   )r    r
   from_template_EXTRACTION_TEMPLATEr   r   r   )	r&   r'   r(   r)   r*   functionextraction_promptr.   r-   s	            r   create_extraction_chainr3   /   sZ    n (/HX"4"B"BCW"X0&AM)J # r!   pydantic_schemac                 d  ^   " U 4S jS[         5      n[        T S5      (       a  T R                  5       nOT R                  5       n[	        UUR                  S0 5      5      n[        U5      nU=(       d    [        R                  " [        5      n[        USS9n[        U5      n	[        UUU	UUS9$ )a  Creates a chain that extracts information from a passage using pydantic schema.

Args:
    pydantic_schema: The pydantic schema of the entities to extract.
    llm: The language model to use.
    prompt: The prompt to use for extraction.
    verbose: Whether to run in verbose mode. In verbose mode, some intermediate
        logs will be printed to the console. Defaults to the global `verbose` value,
        accessible via `langchain.globals.get_verbose()`

Returns:
    Chain that can be used to extract information from a passage.
c                   *   > \ rS rSr% \ Y    \S'   Srg)8create_extraction_chain_pydantic.<locals>.PydanticSchema   r    N)__name__
__module____qualname____firstlineno__list__annotations____static_attributes__)r4   s   r   PydanticSchemar7      s    ?##r!   rA   model_json_schemadefinitionsr   )r4   	attr_name)r'   r(   r-   r.   r*   )r   hasattrrB   r&   r   getr    r
   r/   r0   r   r   r   )
r4   r'   r(   r*   rA   openai_schemar1   r2   r.   r-   s
   `         r    create_extraction_chain_pydanticrH   t   s    n$ $  344'99;'..0.-,M
 (6HX"4"B"BCW"X5&M  )J # r!   )NNF)NF)typingr   r   langchain_core._apir   langchain_core.language_modelsr   .langchain_core.output_parsers.openai_functionsr   r   langchain_core.promptsr	   r
   pydanticr   langchain.chains.baser   langchain.chains.llmr   'langchain.chains.openai_functions.utilsr   r   r   dictr    r0   r>   strboolr3   rH   r9   r!   r   <module>rU      s4     * < J  ' ) D T 	  
		H 	!"L ,0 $	 '( 49
	
  G"FD 
		H 	!"L ,0	..	. '(. 	.
 .G"F.r!   