
    g3fi                        U d Z ddlZddlZddlmZ ddlmZ ddlZddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ d
Z ej&                  e      ZdedefdZdededefdZdedefdZdedefdZdedefdZdedefdZddeez  dedz  defdZ	 ddeez  dedz  defdZdedefdZ eee dZ!eeeegef   f   e"d<   y)zLoad prompts.    N)Callable)Path)StrOutputParser)BasePromptTemplate)ChatPromptTemplate)FewShotPromptTemplate)PromptTemplatezIhttps://raw.githubusercontent.com/hwchase17/langchain-hub/master/prompts/configreturnc                     d| vrt         j                  d       | j                  dd      }|t        vrd| d}t	        |      t        |   } ||       S )zLoad prompt from Config Dict.

    Args:
        config: Dict containing the prompt configuration.

    Returns:
        A PromptTemplate object.

    Raises:
        ValueError: If the prompt type is not supported.
    _typez-No `_type` key found, defaulting to `prompt`.promptzLoading z prompt not supported)loggerwarningpoptype_to_loader_dict
ValueError)r
   config_typemsgprompt_loaders       \/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_core/prompts/loading.pyload_prompt_from_configr      s`     fFG**Wh/K--%:;o'4M      var_namec                     |  d|v rb| |v rd|  d|  d}t        |      t        |j                  |  d            }|j                  dk(  r|j	                  d      }nt         ||| <   |S )z*Load template from the path if applicable._pathzBoth `z_path` and `z` cannot be provided.z.txtutf-8encoding)r   r   r   suffix	read_text)r   r
   r   template_pathtemplates        r   _load_templater$   ,   s     5V#v8*L
:OPCS/!VZZ8*E(:;<6)$...@H#xMr   c                    t        | d   t              r	 | S t        | d   t              rt        | d         }|j	                  d      5 }|j
                  dk(  rt        j                  |      }n1|j
                  dv rt        j                  |      }nd}t        |      ddd       | d<   | S d}t        |      # 1 sw Y   xY w)	zLoad examples if necessary.examplesr   r   .json>   .yml.yamlz=Invalid file format. Only json or yaml formats are supported.Nz;Invalid examples format. Only list or string are supported.)
isinstanceliststrr   openr    jsonloadyaml	safe_loadr   )r
   pathfr&   r   s        r   _load_examplesr4   @   s    &$d+ M 
F:&	,F:&'YYY( 	&A{{g%99Q< 11>>!,U o%	& &z M Lo	& 	&s   
AB==Cc                     | j                  d      x}r4|j                  d      dk7  x}rd| }t        |      t        di || d<   | S )zLoad output parser.output_parserr   defaultzUnsupported output parser  )getr   r   )r
   _configoutput_parser_typer   s       r   _load_output_parserr<   U   s_    **_--w-!(W!5!BBB./A.BCCS/!"1"<G"<Mr   c                     t        d|       } t        d|       } d| v r/d| v rd}t        |      t        | j                  d            | d<   nt	        | d         | d<   t        |       } t        |       } t        di | S )z+Load the "few shot" prompt from the config.r    prefixexample_prompt_pathexample_promptzGOnly one of example_prompt and example_prompt_path should be specified.r8   )r$   r   load_promptr   r   r4   r<   r   )r
   r   s     r   _load_few_shot_promptrB   _   s     Hf-FHf-F&v%   S/!#.vzz:O/P#Q #:6BR;S#T F#F (F *6**r   c                     t        d|       } t        |       } | j                  dd      }|dk(  rd| d}t        |      t	        di | S )z%Load the prompt template from config.r#   template_formatzf-stringjinja2zLoading templates with 'z' format is no longer supported since it can lead to arbitrary code execution. Please migrate to using the 'f-string' template format, which does not suffer from this issue.r8   )r$   r<   r9   r   r	   )r
   rD   r   s      r   _load_promptrF   u   sh     J/F (Fjj!2J?O(" '&7 8U V 	
 o#F##r   r2   r   c                 v    t        | t              r| j                  d      rd}t        |      t	        | |      S )a  Unified method for loading a prompt from LangChainHub or local fs.

    Args:
        path: Path to the prompt file.
        encoding: Encoding of the file.

    Returns:
        A PromptTemplate object.

    Raises:
        RuntimeError: If the path is a Lang Chain Hub path.
    zlc://zLoading from the deprecated github-based Hub is no longer supported. Please use the new LangChain Hub at https://smith.langchain.com/hub instead.)r*   r,   
startswithRuntimeError_load_prompt_from_file)r2   r   r   s      r   rA   rA      s=     $!9 	
 3!$11r   filec                    t        |       }|j                  dk(  r;|j                  |      5 }t        j                  |      }ddd       t        |      S |j                  j                  d      r;|j                  |      5 }t        j                  |      }ddd       t        |      S d|j                   }t        |      # 1 sw Y   t              S xY w# 1 sw Y   t              S xY w)zLoad prompt from file.r'   r   N)r)   r(   zGot unsupported file type )
r   r    r-   r.   r/   endswithr0   r1   r   r   )rK   r   	file_pathr3   r
   r   s         r   rJ   rJ      s    
 T
I7"^^X^. 	"!YYq\F	" #6** 
			"	"#4	5^^X^. 	'!^^A&F	' #6** +9+;+;*<=o	" #6**	' #6**s   CCCC/c                     | j                  d      }|r|d   d   j                  d      nd}| j                  d       |sd}t        |      t        j                  dd|i| S )	zLoad chat prompt from config.messagesr   r   r#   Ninput_variablesz'Can't load chat prompt without templater8   )r   r   r   from_template)r
   rP   r#   r   s       r   _load_chat_promptrS      se    zz*%H8@x{8$((4dH
JJ !7o++HXHHHr   )r   few_shotchatr   )N)#__doc__r.   loggingcollections.abcr   pathlibr   r0   $langchain_core.output_parsers.stringr   langchain_core.prompts.baser   langchain_core.prompts.chatr   langchain_core.prompts.few_shotr   langchain_core.prompts.promptr	   URL_BASE	getLogger__name__r   dictr   r,   r$   r4   r<   rB   rF   rA   rJ   rS   r   __annotations__r8   r   r   <module>rd      sN      $   @ : : A 8V			8	$!D !-? !0S $ 4 (4 D *  +$ ++@ +,$ $. $(2cDj 2C$J 2BT 20 .2+
*+ #d
++(
Id 
I'9 
I %H T#x0B(BCCD r   