
    3fi                     2   d dl 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 d dlmZ d dlmZ d dlmZ d d	lmZmZmZ d
edefdZdZ edddd      	 	 	 ddedede
dz  dee   dz  dedefd       Z edddd      	 	 ddedede
dz  dedef
d       Zy)    )Any)
deprecated)BaseLanguageModel)JsonKeyOutputFunctionsParser!PydanticAttrOutputFunctionsParser)BasePromptTemplateChatPromptTemplate)	BaseModel)Chain)LLMChain)_convert_schema_resolve_schema_referencesget_llm_kwargsentity_schemareturnc                 4    dddddt        |       didgddS )	Ninformation_extractionz3Extracts the relevant information from the passage.objectinfoarray)typeitems)r   
propertiesrequired)namedescription
parameters)r   )r   s    r/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_classic/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.14zLangChain 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://docs.langchain.com/oss/python/langchain/models#structured-outputs>.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 the documentation of structured_output
            # to see an up to date list of which models support
            # with_structured_output.
            model = ChatAnthropic(model="claude-opus-4-1-20250805", temperature=0)
            structured_model = model.with_structured_output(Joke)
            structured_model.invoke("Tell me a joke about cats.
                Make sure to call the Joke function.")
            )sincemessageremovalalternativeNschemallmprompttagsverbosec                     t        |       }|xs t        j                  t              }t	        d      }t        |      }t        ||||||      S )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.
        tags: Optional list of tags to associate with the chain.
        verbose: Whether to run in verbose mode. In verbose mode, some intermediate
            logs will be printed to the console.

    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_chainr2   /   sZ    b (/HX"4"B"BCW"X0&AM)J # r    a  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://docs.langchain.com/oss/python/langchain/models#structured-outputs>. 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>pydantic_schemac                 X     G  fddt               }t         d      r j                         }n j                         }t	        ||j                  di             }t        |      }|xs t        j                  t              }t        |d      }t        |      }	t        |||	||      S )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.

    Returns:
        Chain that can be used to extract information from a passage.
    c                   "    e Zd ZU eW     ed<   y)8create_extraction_chain_pydantic.<locals>.PydanticSchemar   N)__name__
__module____qualname__list__annotations__)r3   s   r   PydanticSchemar6      s    ?##r    r<   model_json_schemadefinitionsr   )r3   	attr_name)r&   r'   r,   r-   r)   )r
   hasattrr=   r%   r   getr   r	   r.   r/   r   r   r   )
r3   r&   r'   r)   r<   openai_schemar0   r1   r-   r,   s
   `         r    create_extraction_chain_pydanticrC   n   s    l$ $  34'99;'..0.-,M
 (6HX"4"B"BCW"X5&M  )J # r    )NNF)NF)typingr   langchain_core._apir   langchain_core.language_modelsr   .langchain_core.output_parsers.openai_functionsr   r   langchain_core.promptsr   r	   pydanticr
   langchain_classic.chains.baser   langchain_classic.chains.llmr   /langchain_classic.chains.openai_functions.utilsr   r   r   dictr   r/   r:   strboolr2   rC    r    r   <module>rQ      s0    * < J  / 1 D T 	  
	W
 	@ )-!	 % s)d
	
  ;:D 
		H 	!"L )-	--	- %- 	-
 -G"F-r    