o
    h2w                     @   s  d dl Zd dl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mZmZ ddlmZ ddlmZmZmZmZ dd	lmZmZmZmZmZ dd
lmZmZ ddlmZ e e!Z"e rdd dl#Z#e rvddl$m%Z%m&Z& ddlm'Z' ne(Z%da)e*e+e,e-e.e/dZ0eG dd dZ1i a2g dZ3d,ddZ4dd Z5d-ddZ6d.ddZ7dd Z8dd Z9G d d! d!Z:G d"d# d#e:Z;G d$d% d%e:Z<G d&d' d'e:Z=G d(d) d)e:Z>G d*d+ d+e%Z?dS )/    N)	dataclass)Dict)HfFolderhf_hub_downloadlist_spaces   )AutoTokenizer)is_offline_modeis_openai_availableis_torch_availablelogging   )TASK_MAPPINGTOOL_CONFIG_FILETool	load_toolsupports_remote)CHAT_MESSAGE_PROMPTdownload_prompt)evaluate)StoppingCriteriaStoppingCriteriaList)AutoModelForCausalLMF)printrangefloatintboolstrc                   @   s&   e Zd ZU eed< eed< eed< dS )PreTooltaskdescriptionrepo_idN)__name__
__module____qualname__r   __annotations__ r'   r'   O/var/www/html/ai/venv/lib/python3.10/site-packages/transformers/tools/agents.pyr   ;   s   
 r   )zimage-transformationztext-downloadztext-to-imageztext-to-videohuggingface-toolsc           	   	   C   s   t  r
td i S t| d}i }|D ];}|j}t|tdd}t|dd}t	|}W d    n1 s5w   Y  |
dd }t||d	 |d
||d < q|S )Nz;You are in offline mode, so remote tools are not available.)authorspace)	repo_typezutf-8)encoding/r!   r    r!   r"   name)r	   loggerinfor   idr   r   openjsonloadsplitr   )	organizationspacestools
space_infor"   resolved_config_filereaderconfigr    r'   r'   r(   get_remote_toolsM   s   

r@   c            
      C   s   t rd S td} | j}t }t D ]\}}t||}|j}t	||d dt
|j< qt sStD ]#}d}| D ]\}}	|	j|krH|	t
|< d} nq7|sRt| dq/da d S )Ntransformersr0   FTz is not implemented on the Hub.)_tools_are_initialized	importlibimport_moduler;   r@   r   itemsgetattrr!   r   HUGGINGFACE_DEFAULT_TOOLSr1   r	   "HUGGINGFACE_DEFAULT_TOOLS_FROM_HUBr    
ValueError)
main_moduletools_moduleremote_tools	task_nametool_class_name
tool_classr!   found	tool_nametoolr'   r'   r(   _setup_default_tools`   s,   


rS   c           	      C   s   |d u r	t  }n|}| D ]0\}}|| vs||v rqt|tr&|||< q|jd u r.|jn|j}|o6t|}t||d||< q|S )Nremote)	BASE_PYTHON_TOOLScopyrE   
isinstancer   r"   r    r   r   )	codetoolboxrU   cached_toolsresolved_toolsr1   rR   task_or_repo_id_remoter'   r'   r(   resolve_tools   s   


r_   c                 C   s   ddg}|  D ]0\}}|| vst|trq|jd u r|jn|j}| d| d}|r/|d7 }|d7 }|| qd|d S )Nz"from transformers import load_tool z = load_tool(""z, remote=True)
)rE   rX   r   r"   r    appendjoin)rY   rZ   rU   
code_linesr1   rR   r]   liner'   r'   r(   get_tool_creation_code   s   rh   c                 C   s   |  d}d}|t|k r)||  ds)|d7 }|t|k r)||  drd|d |  }|t|kr>|d fS |d7 }|}||  dsZ|d7 }||  drMd|||  }||fS )Nrc   r   ```r   )r8   lenlstrip
startswithre   strip)resultlinesidxexplanation	start_idxrY   r'   r'   r(   clean_code_for_chat   s   
rs   c                 C   st   d|  } |  d\}}| }| }| d}|d dv r%|dd  }|d dkr1|d d }d|}||fS )	NzI will use the following zAnswer:rc   r   )ri   z```pyz	```pythonr   r/   ri   )r8   rm   re   )rn   rq   rY   rf   r'   r'   r(   clean_code_for_run   s   


rt   c                   @   s~   e Zd ZdZdddZedeeef fddZ	dd	d
Z
dd ZdddddZdd ZdddddZdd Zdd ZdS )Agenta&  
    Base class for all agents which contains the main API methods.

    Args:
        chat_prompt_template (`str`, *optional*):
            Pass along your own prompt if you want to override the default template for the `chat` method. Can be the
            actual prompt template or a repo ID (on the Hugging Face Hub). The prompt should be in a file named
            `chat_prompt_template.txt` in this repo in this case.
        run_prompt_template (`str`, *optional*):
            Pass along your own prompt if you want to override the default template for the `run` method. Can be the
            actual prompt template or a repo ID (on the Hugging Face Hub). The prompt should be in a file named
            `run_prompt_template.txt` in this repo in this case.
        additional_tools ([`Tool`], list of tools or dictionary with tool values, *optional*):
            Any additional tools to include on top of the default ones. If you pass along a tool with the same name as
            one of the default tools, that default tool will be overridden.
    Nc                 C   s  t   | jj}t||dd| _t||dd| _t | _t	| _
|d urt|ttfr2dd |D }n
t|ts<|j|i}dd | D }| j| t|dkrgdd	d
 | D }td| d nt|dkrt| d }t| d||  d |   d S )Nchat)moderunc                 S   s   i | ]}|j |qS r'   )r1   ).0tr'   r'   r(   
<dictcomp>       z"Agent.__init__.<locals>.<dictcomp>c                 S   s   i | ]\}}|t v r||qS r'   )rG   ry   r1   rR   r'   r'   r(   r{      s    r   rc   c                 S   s    g | ]\}}d | d| qS z- : r'   )ry   nrz   r'   r'   r(   
<listcomp>   s     z"Agent.__init__.<locals>.<listcomp>zSThe following tools have been replaced by the ones provided in `additional_tools`:
.r   z has been replaced by z# as provided in `additional_tools`.)rS   	__class__r#   r   chat_prompt_templaterun_prompt_templaterG   rW   _toolboxr   logrX   listtupledictr1   rE   updaterj   re   r2   warningkeysprepare_for_new_chat)selfr   r   additional_tools
agent_namereplacementsnamesr1   r'   r'   r(   __init__   s,   



zAgent.__init__returnc                 C   s   | j S )z-Get all tool currently available to the agent)r   r   r'   r'   r(   rZ      s   zAgent.toolboxFc                 C   sp   d dd | j D }|r)| jd u r| jd|}n| j}|td|7 }|S | jd|}|d|}|S )Nrc   c                 S   s"   g | ]\}}d | d|j  qS r~   )r!   r}   r'   r'   r(   r      s   " z'Agent.format_prompt.<locals>.<listcomp>z<<all_tools>>z<<task>>z
<<prompt>>)re   rZ   rE   chat_historyr   replacer   r   )r   r    	chat_moder!   promptr'   r'   r(   format_prompt   s   
zAgent.format_promptc                 C   s
   || _ dS )z
        Set the function use to stream results (which is `print` by default).

        Args:
            streamer (`callable`): The function to call when streaming results from the LLM.
        N)r   )r   streamerr'   r'   r(   
set_stream  s   
zAgent.set_stream)return_coderU   c          
      K   s   | j |dd}| j|ddgd}||  d | _t|\}}| d|  |durd| d	|  |sU| d
 t|| j|| jd| _| j	
| t|| j| j	ddS t|| j|d}	|	 d| S dS )a  
        Sends a new request to the agent in a chat. Will use the previous ones in its history.

        Args:
            task (`str`): The task to perform
            return_code (`bool`, *optional*, defaults to `False`):
                Whether to just return code and not evaluate it.
            remote (`bool`, *optional*, defaults to `False`):
                Whether or not to use remote tools (inference endpoints) instead of local ones.
            kwargs (additional keyword arguments, *optional*):
                Any keyword argument to send to the agent when evaluating the code.

        Example:

        ```py
        from transformers import HfAgent

        agent = HfAgent("https://api-inference.huggingface.co/models/bigcode/starcoder")
        agent.chat("Draw me a picture of rivers and lakes")

        agent.chat("Transform the picture so that there is a rock in there")
        ```
        T)r   zHuman:z=====stoprc   ==Explanation from the agent==
N"

==Code generated by the agent==


==Result==rU   r[   rT   )r   generate_onerm   r   rs   r   r_   rZ   r[   
chat_stater   r   rh   
r   r    r   rU   kwargsr   rn   rq   rY   	tool_coder'   r'   r(   rv     s   
z
Agent.chatc                 C   s   d| _ i | _d| _dS )zG
        Clears the history of prior calls to [`~Agent.chat`].
        N)r   r   r[   r   r'   r'   r(   r   6  s   
zAgent.prepare_for_new_chatc          
      K   s   |  |}| j|dgd}t|\}}| d|  | d|  |s?| d t|| j|| jd| _t|| j| dS t	|| j|d}	|	 d	| S )
a  
        Sends a request to the agent.

        Args:
            task (`str`): The task to perform
            return_code (`bool`, *optional*, defaults to `False`):
                Whether to just return code and not evaluate it.
            remote (`bool`, *optional*, defaults to `False`):
                Whether or not to use remote tools (inference endpoints) instead of local ones.
            kwargs (additional keyword arguments, *optional*):
                Any keyword argument to send to the agent when evaluating the code.

        Example:

        ```py
        from transformers import HfAgent

        agent = HfAgent("https://api-inference.huggingface.co/models/bigcode/starcoder")
        agent.run("Draw me a picture of rivers and lakes")
        ```
        zTask:r   r   r   r   r   )staterT   rc   )
r   r   rt   r   r_   rZ   r[   r   rW   rh   r   r'   r'   r(   rx   >  s   

z	Agent.runc                 C   s   t N)NotImplementedErrorr   r   r   r'   r'   r(   r   c  s   zAgent.generate_onec                    s    fdd|D S )Nc                       g | ]}  |qS r'   )r   ry   r   r   r   r'   r(   r   i      z'Agent.generate_many.<locals>.<listcomp>r'   r   promptsr   r'   r   r(   generate_manyg  s   zAgent.generate_manyNNNF)r#   r$   r%   __doc__r   propertyr   r   r   rZ   r   r   rv   r   rx   r   r   r'   r'   r'   r(   ru      s    

	*%ru   c                       sL   e Zd ZdZ					d fdd	Zdd Zdd	 Zd
d Zdd Z  Z	S )OpenAiAgentu!  
    Agent that uses the openai API to generate code.

    <Tip warning={true}>

    The openAI models are used in generation mode, so even for the `chat()` API, it's better to use models like
    `"text-davinci-003"` over the chat-GPT variant. Proper support for chat-GPT models will come in a next version.

    </Tip>

    Args:
        model (`str`, *optional*, defaults to `"text-davinci-003"`):
            The name of the OpenAI model to use.
        api_key (`str`, *optional*):
            The API key to use. If unset, will look for the environment variable `"OPENAI_API_KEY"`.
        chat_prompt_template (`str`, *optional*):
            Pass along your own prompt if you want to override the default template for the `chat` method. Can be the
            actual prompt template or a repo ID (on the Hugging Face Hub). The prompt should be in a file named
            `chat_prompt_template.txt` in this repo in this case.
        run_prompt_template (`str`, *optional*):
            Pass along your own prompt if you want to override the default template for the `run` method. Can be the
            actual prompt template or a repo ID (on the Hugging Face Hub). The prompt should be in a file named
            `run_prompt_template.txt` in this repo in this case.
        additional_tools ([`Tool`], list of tools or dictionary with tool values, *optional*):
            Any additional tools to include on top of the default ones. If you pass along a tool with the same name as
            one of the default tools, that default tool will be overridden.

    Example:

    ```py
    from transformers import OpenAiAgent

    agent = OpenAiAgent(model="text-davinci-003", api_key=xxx)
    agent.run("Is the following `text` (in Spanish) positive or negative?", text="¡Este es un API muy agradable!")
    ```
    text-davinci-003Nc                    sV   t  std|d u rtjdd }|d u rtd|t_|| _t	 j
|||d d S )N<Using `OpenAiAgent` requires `openai`: `pip install openai`.OPENAI_API_KEYzYou need an openai key to use `OpenAIAgent`. You can get one here: Get one here https://openai.com/api/`. If you have one, set it in your env with `os.environ['OPENAI_API_KEY'] = xxx.r   r   r   )r
   ImportErrorosenvirongetrI   openaiapi_keymodelsuperr   )r   r   r   r   r   r   r   r'   r(   r     s   
zOpenAiAgent.__init__c                    s*   d j v r fdd|D S  |S )Ngptc                    r   r'   _chat_generater   r   r'   r(   r     r   z-OpenAiAgent.generate_many.<locals>.<listcomp>)r   _completion_generater   r'   r   r(   r     s   
zOpenAiAgent.generate_manyc                 C   s(   d| j v r| ||S | |g|d S )Nr   r   )r   r   r   r   r'   r'   r(   r     s   
zOpenAiAgent.generate_onec                 C   s.   t jjj| jd|dgd|d}|jd jjS )Nuserrolecontentr   )r   messagestemperaturer   )r   rv   completionscreater   choicesmessager   r   r   r   rn   r'   r'   r(   r     s   
zOpenAiAgent._chat_generatec                 C   *   t jj| j|d|dd}dd |d D S )Nr      )r   r   r   r   
max_tokensc                 S      g | ]}|d  qS textr'   ry   answerr'   r'   r(   r     r|   z4OpenAiAgent._completion_generate.<locals>.<listcomp>r   )r   
Completionr   r   r   r   r   rn   r'   r'   r(   r        z OpenAiAgent._completion_generate)r   NNNN
r#   r$   r%   r   r   r   r   r   r   __classcell__r'   r'   r   r(   r   l  s    '	r   c                       sP   e Zd ZdZ							d fdd	Zdd Zdd	 Zd
d Zdd Z  Z	S )AzureOpenAiAgentu	  
    Agent that uses Azure OpenAI to generate code. See the [official
    documentation](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/) to learn how to deploy an openAI
    model on Azure

    <Tip warning={true}>

    The openAI models are used in generation mode, so even for the `chat()` API, it's better to use models like
    `"text-davinci-003"` over the chat-GPT variant. Proper support for chat-GPT models will come in a next version.

    </Tip>

    Args:
        deployment_id (`str`):
            The name of the deployed Azure openAI model to use.
        api_key (`str`, *optional*):
            The API key to use. If unset, will look for the environment variable `"AZURE_OPENAI_API_KEY"`.
        resource_name (`str`, *optional*):
            The name of your Azure OpenAI Resource. If unset, will look for the environment variable
            `"AZURE_OPENAI_RESOURCE_NAME"`.
        api_version (`str`, *optional*, default to `"2022-12-01"`):
            The API version to use for this agent.
        is_chat_mode (`bool`, *optional*):
            Whether you are using a completion model or a chat model (see note above, chat models won't be as
            efficient). Will default to `gpt` being in the `deployment_id` or not.
        chat_prompt_template (`str`, *optional*):
            Pass along your own prompt if you want to override the default template for the `chat` method. Can be the
            actual prompt template or a repo ID (on the Hugging Face Hub). The prompt should be in a file named
            `chat_prompt_template.txt` in this repo in this case.
        run_prompt_template (`str`, *optional*):
            Pass along your own prompt if you want to override the default template for the `run` method. Can be the
            actual prompt template or a repo ID (on the Hugging Face Hub). The prompt should be in a file named
            `run_prompt_template.txt` in this repo in this case.
        additional_tools ([`Tool`], list of tools or dictionary with tool values, *optional*):
            Any additional tools to include on top of the default ones. If you pass along a tool with the same name as
            one of the default tools, that default tool will be overridden.

    Example:

    ```py
    from transformers import AzureOpenAiAgent

    agent = AzureAiAgent(deployment_id="Davinci-003", api_key=xxx, resource_name=yyy)
    agent.run("Is the following `text` (in Spanish) positive or negative?", text="¡Este es un API muy agradable!")
    ```
    N
2022-12-01c	           	         s   t  std|| _dt_|d u rtjdd }|d u r td|t_	|d u r.tjdd }|d u r6tdd| dt_
|t_|d u rJd	| v }|| _t j|||d
 d S )Nr   azureAZURE_OPENAI_API_KEYzYou need an Azure openAI key to use `AzureOpenAIAgent`. If you have one, set it in your env with `os.environ['AZURE_OPENAI_API_KEY'] = xxx.AZURE_OPENAI_RESOURCE_NAMEzYou need a resource_name to use `AzureOpenAIAgent`. If you have one, set it in your env with `os.environ['AZURE_OPENAI_RESOURCE_NAME'] = xxx.zhttps://z.openai.azure.comr   r   )r
   r   deployment_idr   api_typer   r   r   rI   r   api_baseapi_versionloweris_chat_modelr   r   )	r   r   r   resource_namer   r   r   r   r   r   r'   r(   r     s6   
zAzureOpenAiAgent.__init__c                    s&    j r fdd|D S  |S )Nc                    r   r'   r   r   r   r'   r(   r   .  r   z2AzureOpenAiAgent.generate_many.<locals>.<listcomp>)r   r   r   r'   r   r(   r   ,  s   zAzureOpenAiAgent.generate_manyc                 C   s$   | j r	| ||S | |g|d S )Nr   )r   r   r   r   r'   r'   r(   r   2  s   zAzureOpenAiAgent.generate_onec                 C   s2   t jj| jd|dgd|d}|d d d d S )Nr   r   r   )enginer   r   r   r   r   r   )r   ChatCompletionr   r   r   r'   r'   r(   r   8  s   
zAzureOpenAiAgent._chat_generatec                 C   r   )Nr   r   )r   r   r   r   r   c                 S   r   r   r'   r   r'   r'   r(   r   I  r|   z9AzureOpenAiAgent._completion_generate.<locals>.<listcomp>r   )r   r   r   r   r   r'   r'   r(   r   A  r   z%AzureOpenAiAgent._completion_generate)NNr   NNNNr   r'   r'   r   r(   r     s    2.	r   c                       s,   e Zd ZdZ	d fdd	Zdd Z  ZS )HfAgentuc  
    Agent that uses an inference endpoint to generate code.

    Args:
        url_endpoint (`str`):
            The name of the url endpoint to use.
        token (`str`, *optional*):
            The token to use as HTTP bearer authorization for remote files. If unset, will use the token generated when
            running `huggingface-cli login` (stored in `~/.huggingface`).
        chat_prompt_template (`str`, *optional*):
            Pass along your own prompt if you want to override the default template for the `chat` method. Can be the
            actual prompt template or a repo ID (on the Hugging Face Hub). The prompt should be in a file named
            `chat_prompt_template.txt` in this repo in this case.
        run_prompt_template (`str`, *optional*):
            Pass along your own prompt if you want to override the default template for the `run` method. Can be the
            actual prompt template or a repo ID (on the Hugging Face Hub). The prompt should be in a file named
            `run_prompt_template.txt` in this repo in this case.
        additional_tools ([`Tool`], list of tools or dictionary with tool values, *optional*):
            Any additional tools to include on top of the default ones. If you pass along a tool with the same name as
            one of the default tools, that default tool will be overridden.

    Example:

    ```py
    from transformers import HfAgent

    agent = HfAgent("https://api-inference.huggingface.co/models/bigcode/starcoder")
    agent.run("Is the following `text` (in Spanish) positive or negative?", text="¡Este es un API muy agradable!")
    ```
    Nc                    s`   || _ |d u rdt   | _n|ds|dr|| _nd| | _t j|||d d S )NzBearer BearerBasicr   )url_endpointr   	get_tokentokenrl   r   r   )r   r   r   r   r   r   r   r'   r(   r   l  s   
zHfAgent.__init__c                 C   s   d| j i}|dd|dd}tj| j||d}|jdkr+td td	 | 	|S |jdkr=t
d
|j d|  | d d }|D ]}||rY|d t|    S qG|S )NAuthorizationr   F)max_new_tokensreturn_full_textr   )inputs
parameters)r6   headersi  z=Getting rate-limited, waiting a tiny bit before trying again.r   zError r   r   generated_text)r   requestspostr   status_coder2   r3   timesleep_generate_onerI   r6   endswithrj   )r   r   r   r   r   responsern   stop_seqr'   r'   r(   r   |  s"   







zHfAgent.generate_one)NNNN)r#   r$   r%   r   r   r   r   r'   r'   r   r(   r   L  s
     r   c                       sB   e Zd ZdZd fdd	Zedd Zedd Zd	d
 Z	  Z
S )
LocalAgenta  
    Agent that uses a local model and tokenizer to generate code.

    Args:
        model ([`PreTrainedModel`]):
            The model to use for the agent.
        tokenizer ([`PreTrainedTokenizer`]):
            The tokenizer to use for the agent.
        chat_prompt_template (`str`, *optional*):
            Pass along your own prompt if you want to override the default template for the `chat` method. Can be the
            actual prompt template or a repo ID (on the Hugging Face Hub). The prompt should be in a file named
            `chat_prompt_template.txt` in this repo in this case.
        run_prompt_template (`str`, *optional*):
            Pass along your own prompt if you want to override the default template for the `run` method. Can be the
            actual prompt template or a repo ID (on the Hugging Face Hub). The prompt should be in a file named
            `run_prompt_template.txt` in this repo in this case.
        additional_tools ([`Tool`], list of tools or dictionary with tool values, *optional*):
            Any additional tools to include on top of the default ones. If you pass along a tool with the same name as
            one of the default tools, that default tool will be overridden.

    Example:

    ```py
    import torch
    from transformers import AutoModelForCausalLM, AutoTokenizer, LocalAgent

    checkpoint = "bigcode/starcoder"
    model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.bfloat16)
    tokenizer = AutoTokenizer.from_pretrained(checkpoint)

    agent = LocalAgent(model, tokenizer)
    agent.run("Draw me a picture of rivers and lakes.")
    ```
    Nc                    s"   || _ || _t j|||d d S )Nr   )r   	tokenizerr   r   )r   r   r  r   r   r   r   r'   r(   r     s   
zLocalAgent.__init__c                 K   s.   t j|fi |}tj|fi |}| ||S )a  
        Convenience method to build a `LocalAgent` from a pretrained checkpoint.

        Args:
            pretrained_model_name_or_path (`str` or `os.PathLike`):
                The name of a repo on the Hub or a local path to a folder containing both model and tokenizer.
            kwargs (`Dict[str, Any]`, *optional*):
                Keyword arguments passed along to [`~PreTrainedModel.from_pretrained`].

        Example:

        ```py
        import torch
        from transformers import LocalAgent

        agent = LocalAgent.from_pretrained("bigcode/starcoder", device_map="auto", torch_dtype=torch.bfloat16)
        agent.run("Draw me a picture of rivers and lakes.")
        ```
        )r   from_pretrainedr   )clspretrained_model_name_or_pathr   r   r  r'   r'   r(   r	    s   
zLocalAgent.from_pretrainedc                 C   s<   t | jdrt| jj d S | j D ]}|j  S d S )Nhf_device_mapr   )hasattrr   r   r  valuesr   device)r   paramr'   r'   r(   _model_device  s
   
zLocalAgent._model_devicec           	      C   s   | j |dd| j}|d jd }tt|| j g}| jj|d d|d}| j |d 	 |d  }|D ]}|
|rF|d t|  }q6|S )Npt)return_tensors	input_idsr   r   )r   stopping_criteriar   )r  tor  shaper   StopSequenceCriteriar   generatedecodetolistr  rj   )	r   r   r   encoded_inputssrc_lenr  outputsrn   r  r'   r'   r(   r     s   

zLocalAgent.generate_oner   )r#   r$   r%   r   r   classmethodr	  r   r  r   r   r'   r'   r   r(   r    s    #	

r  c                   @   s&   e Zd ZdZdd ZdefddZdS )r  a6  
    This class can be used to stop generation whenever a sequence of tokens is encountered.

    Args:
        stop_sequences (`str` or `List[str]`):
            The sequence (or list of sequences) on which to stop execution.
        tokenizer:
            The tokenizer used to decode the model outputs.
    c                 C   s    t |tr|g}|| _|| _d S r   )rX   r   stop_sequencesr  )r   r   r  r'   r'   r(   r     s   

zStopSequenceCriteria.__init__r   c                    s,   | j | d  t fdd| jD S )Nr   c                 3   s    | ]}  |V  qd S r   )r  )ry   stop_sequencedecoded_outputr'   r(   	<genexpr>  s    z0StopSequenceCriteria.__call__.<locals>.<genexpr>)r  r  r  anyr   )r   r  scoresr   r'   r"  r(   __call__  s   zStopSequenceCriteria.__call__N)r#   r$   r%   r   r   r   r'  r'   r'   r'   r(   r    s    
r  )r)   )FNr   )@importlib.utilrC   r6   r   r  dataclassesr   typingr   r   huggingface_hubr   r   r   models.autor   utilsr	   r
   r   r   baser   r   r   r   r   r   r   r   python_interpreterr   
get_loggerr#   r2   r   
generationr   r   r   objectrB   r   r   r   r   r   r   rV   r   rG   rH   r@   rS   r_   rh   rs   rt   ru   r   r   r   r  r  r'   r'   r'   r(   <module>   sZ   




 )b~G]