
    dhM	                     X    S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	   " S S\\	5      r
g)	    )List)CallbackManagerForRetrieverRun)Document)BaseRetriever)WikipediaAPIWrapperc                   4    \ rS rSrSrS\S\S\\   4S jr	Sr
g)	WikipediaRetriever
   u  `Wikipedia API` retriever.

Setup:
    Install the ``wikipedia`` dependency:

    .. code-block:: bash

        pip install -U wikipedia

Instantiate:
    .. code-block:: python

        from langchain_community.retrievers import WikipediaRetriever

        retriever = WikipediaRetriever()

Usage:
    .. code-block:: python

        docs = retriever.invoke("TOKYO GHOUL")
        print(docs[0].page_content[:100])

    .. code-block:: none

        Tokyo Ghoul (Japanese: 東京喰種（トーキョーグール）, Hepburn: Tōkyō Gūru) is a Japanese dark fantasy

Use within a chain:
    .. code-block:: python

        from langchain_core.output_parsers import StrOutputParser
        from langchain_core.prompts import ChatPromptTemplate
        from langchain_core.runnables import RunnablePassthrough
        from langchain_openai import ChatOpenAI

        prompt = ChatPromptTemplate.from_template(
            """Answer the question based only on the context provided.

        Context: {context}

        Question: {question}"""
        )

        llm = ChatOpenAI(model="gpt-3.5-turbo-0125")

        def format_docs(docs):
            return "\n\n".join(doc.page_content for doc in docs)

        chain = (
            {"context": retriever | format_docs, "question": RunnablePassthrough()}
            | prompt
            | llm
            | StrOutputParser()
        )

        chain.invoke(
            "Who is the main character in `Tokyo Ghoul` and does he transform into a ghoul?"
        )

    .. code-block:: none

         'The main character in Tokyo Ghoul is Ken Kaneki, who transforms into a ghoul after receiving an organ transplant from a ghoul named Rize.'
queryrun_managerreturnc                     U R                  US9$ )N)r   )load)selfr   r   s      `/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/retrievers/wikipedia.py_get_relevant_documents*WikipediaRetriever._get_relevant_documentsJ   s     yyuy%%     N)__name__
__module____qualname____firstlineno____doc__strr   r   r   r   __static_attributes__r   r   r   r	   r	   
   s)    =~&&*H&	h&r   r	   N)typingr   langchain_core.callbacksr   langchain_core.documentsr   langchain_core.retrieversr   'langchain_community.utilities.wikipediar   r	   r   r   r   <module>r"      s%     C - 3 GC&(; C&r   