
    7|h                         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y)    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                 z    d|i}t        j                  | ||      }|j                          |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        [/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/llms/you.py_requestr      s8    
 G$G}}XwVDH==?    c              +     K   d|i}t        di |ddi}t        j                  | |d|      }|j                          d |D        }	 dd l}|j                  |      }|j                         D ]m  }	|	j                  dv r|	j                  d	k(  r|	j                   0|	j                  d
k(  rt        d|	j                         t        d|	j                          y # t        $ r t        d      w xY ww)Nr   streamT)r   r   r   c              3       K   | ]  }|  y w)N ).0
bytestrings     r   	<genexpr>z"_request_stream.<locals>.<genexpr>"   s     ::J:s   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&QH ;:L

$$\2  K;;44[[G#**[[G#25::,?@@%(;EKK=&IJJK  
E
 	

s   AC7	C BC7C44C7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y)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                 r    |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`   sL     %G  6"D22TDMMTVT!!r   c              +      K   |rt        d      d|i}t        | j                  fd| j                  i|D ]  }t	        |        y w)Nr@   rA   r   )text)r0   r4   rC   rD   r   )rE   r<   r=   r>   r   r1   r&   s          r   _streamzYou._streamo   se      %G  6"$""
,0MM
=C
 	.E "u--	.s   AA
c                 8    | 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                 D    | j                   xs t        j                  d   S )NYDC_API_KEY)r;   osenvironrM   s    r   rD   zYou._api_key   s    <2::m#<<r   c                      y)Nzyou.comr    rM   s    r   	_llm_typezYou._llm_type   s    r   )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   ;   s1   2 .3Q.Hg)*  "'T"K#  %):>	"" tCy!" 67	"
 " 
"$ %):>	.. tCy!. 67	.
 . 
/	"." !3 ! !
 =# = = 3  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  E 3 2 17 s S C DcN KKK+.KsD$KDQ# Qr   