o
    Zh                     @   s   d Z ddlZddlmZ ddlmZmZ ddlZddlm	Z	 ddl
mZ ddlmZ dZd	ed
ede	fddZdeeef d
ede	fddZdS )z5Base interface for loading large language model APIs.    N)Path)AnyUnion)BaseLLM)
get_fields)get_type_to_cls_dictZallow_dangerous_deserializationconfigkwargsreturnc                 K   st   d| vrt d| d}t }||vrt d| d||  }i }tt|v r1|td|t< |di | |S )zLoad LLM from Config Dict._typez"Must specify an LLM Type in configzLoading z LLM not supportedFN )
ValueErrorpopr   $_ALLOW_DANGEROUS_DESERIALIZATION_ARGr   get)r   r	   Zconfig_typeZtype_to_cls_dictZllm_clsZload_kwargsr   r   W/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/llms/loading.pyload_llm_from_config   s   

r   filec                 K   s   t | tr
t| }n| }|jdkr+t|}t|}W d   n1 s%w   Y  n%|jdrLt|d}t	|}W d   n1 sFw   Y  nt
dt|fi |S )zLoad LLM from a file.z.jsonN)z.yamlz.ymlrzFile type must be json or yaml)
isinstancestrr   suffixopenjsonloadendswithyamlZ	safe_loadr   r   )r   r	   	file_pathfr   r   r   r   load_llm&   s   



r   )__doc__r   pathlibr   typingr   r   r   Z#langchain_core.language_models.llmsr   Zlangchain_core.utils.pydanticr   Zlangchain_community.llmsr   r   dictr   r   r   r   r   r   r   <module>   s    "