
    Ngq                         d dl Z d dlZd dl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mZmZ d dlmZmZmZmZ d dlmZ  e j        e          Z G d d	e          ZdS )
    N)AnyDictListMappingOptional)CallbackManagerForLLMRun)LLM)convert_to_secret_strget_from_dict_or_envpre_init)
ConfigDictField	SecretStrmodel_validator)enforce_stop_tokensc                      e Zd ZU dZdZeed<   	  ee          Z	e
eef         ed<   	 dZee         ed<    ed	          Z ed
          ede
eef         defd                        Zede
de
fd            Zedeeef         fd            Zedefd            Z	 	 ddedeee                  dee         dedef
dZdS )StochasticAIa2  StochasticAI large language models.

    To use, you should have the environment variable ``STOCHASTICAI_API_KEY``
    set with your API key.

    Example:
        .. code-block:: python

            from langchain_community.llms import StochasticAI
            stochasticai = StochasticAI(api_url="")
     api_url)default_factorymodel_kwargsNstochasticai_api_keyforbid)extrabefore)modevaluesreturnc                 l   t          t          | j                                                            }|                    di           }t          |          D ]U}||vrO||v rt          d| d          t                              | d| d           |                    |          ||<   V||d<   |S )z>Build extra kwargs from additional params that were passed in.r   zFound z supplied twice.zJ was transferred to model_kwargs.
                    Please confirm that z is what you intended.)	setlistmodel_fieldskeysget
ValueErrorloggerwarningpop)clsr   all_required_field_namesr   
field_names        a/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/llms/stochasticai.pybuild_extrazStochasticAI.build_extra*   s     $'tC,<,A,A,C,C'D'D#E#E 

>2..v,, 	; 	;J!999&&$%Jj%J%J%JKKK# N N)3N N N   %+JJz$:$:j!!&~    c                 L    t          t          |dd                    }||d<   |S )z,Validate that api key exists in environment.r   STOCHASTICAI_API_KEY)r
   r   )r)   r   r   s      r,   validate_environmentz!StochasticAI.validate_environment=   s7      5 )?AWXX 
  
 *>%&r.   c                 *    i d| j         id| j        iS )zGet the identifying parameters.endpoint_urlr   )r   r   selfs    r,   _identifying_paramsz StochasticAI._identifying_paramsF   s+    
t|,
t01
 	
r.   c                     dS )zReturn type of llm.stochasticai r4   s    r,   	_llm_typezStochasticAI._llm_typeN   s	     ~r.   promptstoprun_managerkwargsc                 \   | j         pi }i ||}t          j        | j        ||d| j                                         ddd          }|                                 |                                }d}|st          j        |d         d         | j                                         ddd          }	|	                                 |	                                d         }
|
                    d	          }|d
u}t          j
        d           ||d         }|t          ||          }|S )at  Call out to StochasticAI's complete endpoint.

        Args:
            prompt: The prompt to pass into the model.
            stop: Optional list of stop words to use when generating.

        Returns:
            The string generated by the model.

        Example:
            .. code-block:: python

                response = StochasticAI("Tell me a joke.")
        )r;   paramszapplication/json)apiKeyAcceptzContent-Type)urljsonheadersFdataresponseUrl)rC   rE   
completionNg      ?r   )r   requestspostr   r   get_secret_valueraise_for_statusrD   r$   timesleepr   )r5   r;   r<   r=   r>   r@   response_postresponse_post_json	completedresponse_getresponse_get_jsontexts               r,   _callzStochasticAI._callS   sl   * "(b%F%f% "f55!6GGIIK, 2 
 
 
 	&&(((*//11	 	#<&v.}=!%!:!K!K!M!MO0$6   L ))+++ , 1 1 3 3F ;$((66DD(IJsOOO  	 Aw 'tT22Dr.   )NN)__name__
__module____qualname____doc__r   str__annotations__r   dictr   r   r   r   r   r   r   model_configr   classmethodr-   r   r1   propertyr   r6   r:   r   r   rU   r9   r.   r,   r   r      s        
 
 GS#(5#>#>#>L$sCx.>>> 15(9-444:  L _(###c3h C    [ $#" $ 4    X 
WS#X%6 
 
 
 X
 3    X %):>	6 66 tCy!6 67	6
 6 
6 6 6 6 6 6r.   r   )loggingrM   typingr   r   r   r   r   rI   langchain_core.callbacksr   #langchain_core.language_models.llmsr	   langchain_core.utilsr
   r   r   pydanticr   r   r   r   langchain_community.llms.utilsr   	getLoggerrV   r&   r   r9   r.   r,   <module>rh      s     5 5 5 5 5 5 5 5 5 5 5 5 5 5  = = = = = = 3 3 3 3 3 3 V V V V V V V V V V B B B B B B B B B B B B > > > > > >		8	$	$y y y y y3 y y y y yr.   