
    Ng                         d dl Z d dlmZmZmZmZmZmZmZ d dl	Z	d dl
mZ d dlmZ d dlmZ d dlmZ dZdZd	ed
ededeeef         fdZd	ed
ededeeddf         fdZ G d de          ZdS )    N)AnyDict	GeneratorIteratorListLiteralOptional)CallbackManagerForLLMRun)LLM)GenerationChunk)Fieldzhttps://chat-api.you.com/smartz!https://chat-api.you.com/researchbase_urlapi_keykwargsreturnc                     d|i}t          j        | ||          }|                                 |                                S )z
    NOTE: This function can be replaced by a OpenAPI-generated Python SDK in the future,
    for better input/output typing support.
    	x-api-key)headersjson)requestspostraise_for_statusr   )r   r   r   r   responses        X/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/llms/you.py_requestr      sD    
 G$G}XwVDDDH==??    c              +     K   d|i}t          di |ddi}t          j        | |d|          }|                                 d |D             }	 dd l}|                    |          }n# t          $ r t          d          w xY w|                                D ]Y}	|	j        dv r|	j        d	k    r
|	j	        V  !|	j        d
k    rt          d|	j	                   t          d|	j                   d S )Nr   streamT)r   r   r   c              3      K   | ]}|V  d S )N ).0
bytestrings     r   	<genexpr>z"_request_stream.<locals>.<genexpr>"   s"      :::J::::::r   r   zPCould not import `sseclient`. Please install it with `pip install sseclient-py`.)search_resultsdonetokenerrorzError in response: zUnknown event type r    )dictr   r   r   	sseclient	SSEClientImportErroreventseventdata
ValueErrorNotImplementedError)
r   r   r   r   paramsr   event_sourcer)   clientr-   s
             r   _request_streamr4      s]      G$G((F((4(((F}Xwt&QQQH ;::::L

$$\22 
 
 
E
 
 	

  K K;444[G##*[G##?5:??@@@%&IEK&I&IJJJK Ks   A* *Bc                   `   e Zd ZU dZ edd          Zed         ed<    edd          Ze	e
         ed	<   	 	 dd
e
de	ee
                  de	e         dede
f
dZ	 	 dd
e
de	ee
                  de	e         dedee         f
dZede
fd            Zede
fd            Zede
fd            ZdS )Youa  Wrapper around You.com's conversational Smart and Research APIs.

    Each API endpoint is designed to generate conversational
    responses to a variety of query types, including inline citations
    and web results when relevant.

    Smart Endpoint:
    - Quick, reliable answers for a variety of questions
    - Cites the entire web page URL

    Research Endpoint:
    - In-depth answers with extensive citations for a variety of questions
    - Cites the specific web page snippet relevant to the claim

    To connect to the You.com api requires an API key which
    you can get at https://api.you.com.

    For more information, check out the documentations at
    https://documentation.you.com/api-reference/.

    Args:
        endpoint: You.com conversational endpoints. Choose from "smart" or "research"
        ydc_api_key: You.com API key, if `YDC_API_KEY` is not set in the environment
    smartzCYou.com conversational endpoints. Choose from "smart" or "research")description)r7   researchendpointNz>You.com API key, if `YDC_API_KEY` is not set in the envriomentydc_api_keypromptstoprun_managerr   r   c                 n    |rt          d          d|i}t          | j        fd| j        i|}|d         S )N5Stop words are not implemented for You.com endpoints.queryr   answer)r0   r   _request_endpoint_api_key)selfr<   r=   r>   r   r1   r   s          r   _callz	You._call`   sW      	%G   6"D2TTDMTVTT!!r   c              +      K   |rt          d          d|i}t          | j        fd| j        i|D ]}t	          |          V  d S )Nr@   rA   r   )text)r0   r4   rC   rD   r   )rE   r<   r=   r>   r   r1   r&   s          r   _streamzYou._streamo   s        	%G   6"$"
 
,0M
=C
 
 	. 	.E "u-------	. 	.r   c                 4    | j         dk    rt          S t          S )Nr7   )r:   SMART_ENDPOINTRESEARCH_ENDPOINTrE   s    r   rC   zYou._request_endpoint   s    =G##!!  r   c                 4    | j         pt          j        d         S )NYDC_API_KEY)r;   osenvironrM   s    r   rD   zYou._api_key   s    <2:m#<<r   c                     dS )Nzyou.comr    rM   s    r   	_llm_typezYou._llm_type   s    yr   )NN)__name__
__module____qualname____doc__r   r:   r   __annotations__r;   r	   strr   r
   r   rF   r   r   rI   propertyrC   rD   rS   r    r   r   r6   r6   ;   s         2 .3UQ. . .Hg)*    "'T" " "K#    %):>	" "" tCy!" 67	"
 " 
" " " "$ %):>	. .. tCy!. 67	.
 . 
/	". . . ." !3 ! ! ! X!
 =# = = = X= 3    X  r   r6   )rP   typingr   r   r   r   r   r   r	   r    langchain_core.callbacks.managerr
   #langchain_core.language_models.llmsr   langchain_core.outputsr   pydanticr   rK   rL   rY   r   r4   r6   r    r   r   <module>r`      s^   				 J J J J J J J J J J J J J J J J J J  E E E E E E 3 3 3 3 3 3 2 2 2 2 2 2      17 s S C DcN    KKK+.KsD$K K K KDQ Q Q Q Q# Q Q Q Q Qr   