
    dh                         S SK r S SKJrJrJrJrJrJrJr  S SK	r	S SK
Jr  S SKJr  S SKJr  S SKJr  SrSrS	\S
\S\S\\\4   4S jrS	\S
\S\S\\SS4   4S jr " S S\5      rg)    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                 t    SU0n[         R                  " XUS9nUR                  5         UR                  5       $ )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        T/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/llms/you.py_requestr      s6    
 G$G}}XVDH==?    c              +     #    SU0n[        S0 UDSS0D6n[        R                  " XSUS9nUR                  5         S U 5       n SS KnUR                  U5      nUR                  5        Hs  n	U	R                  S;   a  M  U	R                  S	:X  a  U	R                  v   M5  U	R                  S
:X  a  [        SU	R                   35      e[        SU	R                   35      e   g ! [         a    [        S5      ef = f7f)Nr   streamT)r   r   r   c              3   "   #    U H  ov   M     g 7f)N ).0
bytestrings     r   	<genexpr>"_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_streamr5      s      G$G(F(4(F}}Xt&QH ;:L

$$\2 ;;44[[G#**[[G#25::,?@@%(;EKK=&IJJ !  
E
 	

s   AC<C# BC<#C99C<c                      \ rS rSr% Sr\" SSS9r\S   \S'   \" SS	S9r	\
\   \S
'     SS\S\
\\      S\
\   S\S\4
S jjr  SS\S\
\\      S\
\   S\S\\   4
S jjr\S\4S j5       r\S\4S j5       r\S\4S j5       rSrg)You;   aE  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)r9   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                 |    U(       a  [        S5      eSU0n[        U R                  4SU R                  0UD6nUS   $ )N5Stop words are not implemented for You.com endpoints.queryr   answer)r1   r   _request_endpoint_api_key)selfr>   r?   r@   r   r2   r   s          r   _call	You._call`   sL     %G  6"D22TDMMTVT!!r   c              +      #    U(       a  [        S5      eSU0n[        U R                  4SU R                  0UD6 H  n[	        US9v   M     g 7f)NrB   rC   r   )text)r1   r5   rE   rF   r   )rG   r>   r?   r@   r   r2   r'   s          r   _streamYou._streamo   s_      %G  6"$""
,0MM
=C
E "u--
s   AAc                 :    U R                   S:X  a  [        $ [        $ )Nr9   )r<   SMART_ENDPOINTRESEARCH_ENDPOINTrG   s    r   rE   You._request_endpoint   s    ==G#!!  r   c                 N    U R                   =(       d    [        R                  S   $ )NYDC_API_KEY)r=   osenvironrQ   s    r   rF   You._api_key   s    <2::m#<<r   c                     g)Nzyou.comr    rQ   s    r   	_llm_typeYou._llm_type   s    r   r    )NN)__name__
__module____qualname____firstlineno____doc__r   r<   r   __annotations__r=   r	   strr   r
   r   rH   r   r   rL   propertyrE   rF   rY   __static_attributes__r    r   r   r7   r7   ;   s1   2 .3Q.Hg)*  "'T"K#  %):>	"" tCy!" 67	"
 " 
"$ %):>	.. tCy!. 67	.
 . 
/	"." !3 ! !
 =# = = 3  r   r7   )rU   typingr   r   r   r   r   r   r	   r    langchain_core.callbacks.managerr
   #langchain_core.language_models.llmsr   langchain_core.outputsr   pydanticr   rO   rP   ra   r   r5   r7   r    r   r   <module>ri      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   