
    NgM	                     `    d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	  G d dee	          Z
dS )	    )List)CallbackManagerForRetrieverRun)Document)BaseRetriever)WikipediaAPIWrapperc                   2    e Zd ZdZdededee         fdZdS )WikipediaRetrieveru:  `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                .    |                      |          S )N)r
   )load)selfr
   r   s      d/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/retrievers/wikipedia.py_get_relevant_documentsz*WikipediaRetriever._get_relevant_documentsJ   s     yyuy%%%    N)	__name__
__module____qualname____doc__strr   r   r   r    r   r   r	   r	   
   sO        = =~&&*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 C C C C C - - - - - - 3 3 3 3 3 3 G G G G G GC& C& C& C& C&(; C& C& C& C& C&r   