a
    bgL                     @   s   d dl Z d dlmZmZmZmZm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 e eZG dd de
ZdS )	    N)AnyDictListMappingOptional)CallbackManagerForLLMRun)LLM)convert_to_secret_strget_from_dict_or_envget_pydantic_field_names)
ConfigDictField	SecretStrmodel_validatorc                   @   s`  e Zd ZU dZdZeed< dZeed< dZ	e
ed< dZeed	< d
Ze
ed< d
Zeed< dZe
ed< dZe
ed< d
Zeed< eedZeeef ed< eedZeeee
f  ed< dZee ed< eddZeddeeeef edddZeeeef dddZ ee!eef ddd Z"eedd!d"Z#d&eee$e  ee% eed#d$d%Z&dS )'GooseAIa  GooseAI large language models.

    To use, you should have the ``openai`` python package installed, and the
    environment variable ``GOOSEAI_API_KEY`` set with your API key.

    Any parameters that are valid to be passed to the openai.create call can be passed
    in, even if not explicitly saved on this class.

    Example:
        .. code-block:: python

            from langchain_community.llms import GooseAI
            gooseai = GooseAI(model_name="gpt-neo-20b")

    Nclientzgpt-neo-20b
model_namegffffff?temperature   
max_tokens   top_p
min_tokensr   frequency_penaltypresence_penaltyn)default_factorymodel_kwargs
logit_biasgooseai_api_keyignore)extrabefore)mode)valuesreturnc              
   C   s   t | }|di }t|D ]P}||vr||v r@td| dtd| d| d| d ||||< q||d< tt|dd	}||d< z&d
dl	}|
 |_d|_|j|d< W n ty   tdY n0 |S )z>Build extra kwargs from additional params that were passed in.r   zFound z supplied twice.z	WARNING! z/ is not default parameter.
                    zJ was transferred to model_kwargs.
                    Please confirm that z is what you intended.r   ZGOOSEAI_API_KEYr   Nzhttps://api.goose.ai/v1r   zTCould not import openai python package. Please install it with `pip install openai`.)r   getlist
ValueErrorloggerwarningpopr	   r
   openaiZget_secret_valueZapi_keyZapi_baseZ
CompletionImportError)clsr$   Zall_required_field_namesr!   
field_namer   r,    r0   n/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/llms/gooseai.pybuild_extraI   s:    


zGooseAI.build_extra)r%   c              	   C   s4   | j | j| j| j| j| j| j| jd}i || jS )z3Get the default parameters for calling GooseAI API.)r   r   r   r   r   r   r   r   )	r   r   r   r   r   r   r   r   r   )selfZnormal_paramsr0   r0   r1   _default_paramsm   s    
zGooseAI._default_paramsc                 C   s   i d| j i| jS )zGet the identifying parameters.r   )r   r4   r3   r0   r0   r1   _identifying_params|   s    zGooseAI._identifying_paramsc                 C   s   dS )zReturn type of llm.Zgooseair0   r5   r0   r0   r1   	_llm_type   s    zGooseAI._llm_type)promptstoprun_managerkwargsr%   c                 K   s\   | j }|dur&d|v rtd||d< i ||}| jjf | j|d|}|jd j}|S )zCall the GooseAI API.Nr9   z2`stop` found in both the input and default params.)Zenginer8   r   )r4   r(   r   creater   choicestext)r3   r8   r9   r:   r;   paramsresponser>   r0   r0   r1   _call   s    zGooseAI._call)NN)'__name__
__module____qualname____doc__r   r   __annotations__r   strr   floatr   intr   r   r   r   r   r   dictr   r   r   r   r   r   r   Zmodel_configr   classmethodr2   propertyr4   r   r6   r7   r   r   rA   r0   r0   r0   r1   r      sD   
"  
r   )loggingtypingr   r   r   r   r   Zlangchain_core.callbacksr   Z#langchain_core.language_models.llmsr   Zlangchain_core.utilsr	   r
   r   Zpydanticr   r   r   r   	getLoggerrB   r)   r   r0   r0   r0   r1   <module>   s   
