
    dh                         S SK JrJrJrJrJrJrJr  S SKJ	r	J
r
  S SKJr  S SKJr  S SKJr  S SKJrJrJrJr   " S S\5      rg	)
    )AnyAsyncIteratorDictIteratorListMappingOptional)AsyncCallbackManagerForLLMRunCallbackManagerForLLMRun)LLM)GenerationChunk)get_from_dict_or_env)
ConfigDictField	SecretStrmodel_validatorc                      \ rS rSr% Sr\" SSS9r\\S'   \" SSS9r	\\S'   \" SS9r
\\   \S	'    \" S
SS9r\\S'    Sr\\   \S'    Sr\\   \S'    Sr\\   \S'    Sr\\\      \S'    Sr\\   \S'    \" \S9r\\\4   \S'    \" SS9r\S\\\4   4S j5       r\S\\\4   4S j5       r\S\4S j5       r \!" SS9\"S\S\4S j5       5       r#  S'S\S\\\      S \\$   S!\S\4
S" jjr%  S'S\S\\&\      S \\'   S!\S\4
S# jjr(  S'S\S\\&\      S \\$   S!\S\)\*   4
S$ jjr+  S'S\S\\&\      S \\'   S!\S\,\*   4
S% jjr-S&r.g)(Writer   a  Writer large language models.

To use, you should have the ``writer-sdk`` Python package installed, and the
environment variable ``WRITER_API_KEY`` set with your API key.

Example:
    .. code-block:: python

        from langchain_community.llms import Writer as WriterLLM
        from writerai import Writer, AsyncWriter

        client = Writer()
        async_client = AsyncWriter()

        chat = WriterLLM(
            client=client,
            async_client=async_client
        )
NT)defaultexcludeclientasync_client)r   api_keyzpalmyra-x-003-instructmodel)r   alias
model_name
max_tokensgffffff?temperaturetop_pstopbest_of)default_factorymodel_kwargs)populate_by_namereturnc                     U R                   U R                  U R                  U R                  U R                  S.U R
                  E$ )z2Get the default parameters for calling Writer API.)r   r   r    r!   r"   )r   r   r    r!   r"   r$   selfs    W/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/llms/writer.py_default_paramsWriter._default_paramsF   sC     //++ZZII||
 
 	
    c                 6    SU R                   0U R                  E$ )zGet the identifying parameters.r   )r   r+   r(   s    r*   _identifying_paramsWriter._identifying_paramsR   s%     T__
""
 	
r-   c                     g)zReturn type of llm.writer r(   s    r*   	_llm_typeWriter._llm_typeZ   s     r-   before)modevaluesc           
          SSK JnJn  UR	                  S5      (       d"  UR                  SU" [        USS5      S905        UR	                  S	5      (       d"  UR                  S	U" [        USS5      S905        [        UR	                  S5      5      UL a  [        UR	                  S	5      5      UL d  [        S
5      eU$ ! [         a  n[        S5      UeSnAff = f)z<Validates that api key is passed and creates Writer clients.r   )AsyncClientClientzXCould not import writerai python package. Please install it with `pip install writerai`.Nr   r   WRITER_API_KEY)r   r   zx'client' attribute must be with type 'Client' and 'async_client' must be with type 'AsyncClient' from 'writerai' package)	writerair:   r;   ImportErrorgetupdater   type
ValueError)clsr8   r:   r;   es        r*   validate_environmentWriter.validate_environment_   s    	4 zz(##MMf 4"I/?! zz.))MM"K 4"I/?!% H%&&0VZZ/0K?Y 
 K  	A 	s   C 
CCCpromptrun_managerkwargsc                     0 U R                   EUEnUb  UR                  SU05        U R                  R                  R                  " SSU0UD6R
                  S   R                  nU$ Nr!   rG   r   r3   )r/   r@   r   completionscreatechoicestext)r)   rG   r!   rH   rI   paramsrO   s          r*   _callWriter._call   sg     8D,,77MM64.){{&&--FVFvFNNqQVVr-   c                    #    0 U R                   EUEnUb  UR                  SU05        U R                  R                  R                  " SSU0UD6I S h  vN nUR
                  S   R                  nU$  N7frK   )r/   r@   r   rL   rM   rN   rO   )r)   rG   r!   rH   rI   rP   responserO   s           r*   _acallWriter._acall   sz      8D,,77MM64.)**66==VVVvVV"'' Ws   AA6A4 A6c              +   0  #    0 U R                   EUESS0EnUb  UR                  SU05        U R                  R                  R                  " SSU0UD6nU H:  nU(       a  UR                  UR                  5        [        UR                  S9v   M<     g 7fNstreamTr!   rG   )rO   r3   )r/   r@   r   rL   rM   on_llm_new_tokenvaluer   r)   rG   r!   rH   rI   rP   rT   chunks           r*   _streamWriter._stream   s      HD,,GG$GMM64.);;**11JJ6JE,,U[[9!u{{33 s   BBc                h  #    0 U R                   EUESS0EnUb  UR                  SU05        U R                  R                  R                  " SSU0UD6I S h  vN nU  S h  vN nU(       a#  UR                  UR                  5      I S h  vN   [        UR                  S97v   MK   NQ NH N 
 g 7frX   )r/   r@   r   rL   rM   rZ   r[   r   r\   s           r*   _astreamWriter._astream   s      HD,,GG$GMM64.)**66==VVVvVV# 	4%!225;;???!u{{33	 W	4? $sH   AB2B*B2B0#B,$B0'&B2B.B2,B0.B20B2r3   )NN)/__name__
__module____qualname____firstlineno____doc__r   r   r   __annotations__r   r   r	   r   r   strr   intr   floatr    r!   r   r"   dictr$   r   r   model_configpropertyr   r+   r/   r4   r   classmethodrE   r   rQ   listr
   rU   r   r   r^   r   ra   __static_attributes__r3   r-   r*   r   r      s   ( d3FC3dD9L#9#(#6GXi 6$<GLJL $J$S#&K%&M "E8E?!: !%D(49
$2 "GXc]! $)#>L$sCx.>Vt4L	
c!2 	
 	
 
WS#X%6 
 
 3   (#)$ )3 )  $)\ %):>	 tCy! 67	
  
  %)?C	 tCy! ;<	
  
" %):>	44 tCy!4 67	4
 4 
/	"4& %)?C	44 tCy!4 ;<	4
 4 
	'4 4r-   r   N)typingr   r   r   r   r   r   r	   langchain_core.callbacksr
   r   #langchain_core.language_models.llmsr   langchain_core.outputsr   langchain_core.utilsr   pydanticr   r   r   r   r   r3   r-   r*   <module>rx      s2    N N N 4 2 5 B Bx4S x4r-   