
     `iF~                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	m
Z
 d dlmZ d dlmZmZ d dlmZ d dlmZ d dlZd dlmZmZ d dlmZmZmZ d d	lmZ d d
lmZm Z  d dl!m"Z"m#Z# 	 d dl$Z$n# e%$ r Y nw xY w ej&                    dk    rd dl'Z' e"            rd dl(m)Z) d dl*m+Z+ d dl,m-Z-  e#            rd dl.Z.d dlm/Z/m0Z0  e1ej2        ej3        z             Z4 e1ej2        ej5        z   ej3        z   dz             Z6ddiddiddiddiddiddiddidZ7dZ8dd9                    e7:                                           dZ; G d d           Z<e G d! d"                      Z=d#e
fd$Z> G d% d&e          Z?e@d'k    r9 e=            ZAd(eA_B        d)eA_B         e?eA          ZCeCD                                 dS dS )*    N)ArgumentParser	Namespace)AsyncIterator)	dataclassfield)Thread)Optional)AsyncInferenceClientChatCompletionStreamOutput)AutoTokenizerGenerationConfigPreTrainedTokenizer)BaseTransformersCLICommand)ServeArgumentsServeCommand)is_rich_availableis_torch_availableWindows)Console)Live)Markdown)AutoModelForCausalLMBitsAndBytesConfigz .!\"#$%&'()*+,\-/:<=>?@[]^_`{|}~textz5There is a Llama in my lawn, how can I get rid of it?zyWrite a Python function that integrates any Python function f(x) numerically over an arbitrary interval [x_start, x_end].z4How many helicopters can a human eat in one sitting?z4Count to 10 but skip every number ending with an 'e'zWhy aren't birds real?z2Why is it important to eat socks after meditating?z$Which number is larger, 9.9 or 9.11?)llamacode
helicopternumbersbirdssocksnumbers2a  

**TRANSFORMERS CHAT INTERFACE**

Chat interface to try out a model. Besides chatting with the model, here are some basic commands:
- **!help**: shows all available commands (set generation settings, save chat, etc.)
- **!status**: shows the current status of the model and generation settings
- **!clear**: clears the current conversation and starts a new one
- **!exit**: closes the interface
am  

**TRANSFORMERS CHAT INTERFACE HELP**

Full command list:
- **!help**: shows this help message
- **!clear**: clears the current conversation and starts a new one
- **!status**: shows the current status of the model and generation settings
- **!example {NAME}**: loads example named `{NAME}` from the config and uses it as the user input.
Available example names: `z`, `a%  `
- **!set {ARG_1}={VALUE_1} {ARG_2}={VALUE_2}** ...: changes the system prompt or generation settings (multiple
settings are separated by a space). Accepts the same flags and format as the `generate_flags` CLI argument.
If you're a new user, check this basic flag guide: https://huggingface.co/docs/transformers/llm_tutorial#common-options
- **!save {SAVE_NAME} (optional)**: saves the current chat and settings to file by default to
`./chat_history/{MODEL_NAME}/chat_{DATETIME}.yaml` or `{SAVE_NAME}` if provided
- **!exit**: closes the interface
c                       e Zd Zddee         dee         fdZdee         deee	f         fdZ
defdZd	 Zd
efdZd
edefdZddefdZdededefdZdS )RichInterfaceN
model_name	user_namec                 r    t                      | _        |d| _        n|| _        |	d| _        d S || _        d S )N	assistantuser)r   _consoler$   r%   )selfr$   r%   s      n/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/transformers/commands/chat.py__init__zRichInterface.__init__w   s?    		)DOO(DO#DNNN&DNNN    streamreturnc                   K   | j                             d| j         d           t          | j         d          5 }d}| d {V 2 3 d {V }|j        d         j        j        }|s!t          j        dd|          }||z  }g }|	                                D ]W}|
                    |           |                    d	          r|
                    d
           B|
                    d           Xt          d                    |                                          d          }|                    |d           6 	 d d d            n# 1 swxY w Y   | j                                          |S )Nz[bold blue]<z>:   )consolerefresh_per_second r   z<(/*)(\w*)>z\<\1\2\>z```
z  
zgithub-dark)
code_themeT)refresh)r)   printr$   r   choicesdeltacontentresub
splitlinesappend
startswithr   joinstripupdate)	r*   r.   liver   tokenoutputslineslinemarkdowns	            r+   stream_outputzRichInterface.stream_output   s     >4?>>>???$-A>>> &	4$D%+|||||| $4 $4 $4 $4 $4 $4 $4e-*08  &gFF  OO-- - -DLL&&&u-- - T****V,,,,#BGGENN$8$8$:$:}UUU Hd3333I  ,|&	4 &	4 &	4 &	4 &	4 &	4 &	4 &	4 &	4 &	4 &	4 &	4 &	4 &	4 &	4P 	s   ED?C3EEEc                 ~    | j                             d| j         d          }| j                                          |S )z!Gets user input from the console.[bold red]<z>:
)r)   inputr%   r8   )r*   rM   s     r+   rM   zRichInterface.input   s>    ##$F$.$F$F$FGGr-   c                 8    | j                                          dS )zClears the console.N)r)   clearr*   s    r+   rO   zRichInterface.clear   s    r-   r   c                     | j                             d| j         d|            | j                                          dS )z%Prints a user message to the console.rL   z>:[/ bold red]
N)r)   r8   r%   )r*   r   s     r+   print_user_messagez RichInterface.print_user_message   sE    P$.PP$PPQQQr-   colorc                 x    | j                             d| d|            | j                                          dS )z,Prints text in a given color to the console.z[bold ]Nr)   r8   )r*   r   rS   s      r+   print_colorzRichInterface.print_color   sC    3U33T33444r-   Fminimalc                     | j                             t          |rt          nt                               | j                                          dS )z'Prints the help message to the console.N)r)   r8   r   HELP_STRING_MINIMALHELP_STRING)r*   rX   s     r+   
print_helpzRichInterface.print_help   sE    HG%T%8%8UUVVVr-   generation_configmodel_kwargsc                     | j                             d| d           |r| j                             d|            | j                             d|            | j                                          dS )zFPrints the status of the model and generation settings to the console.z[bold blue]Model: r5   z[bold blue]Model kwargs: z[bold blue]NrV   )r*   r$   r]   r^   s       r+   print_statuszRichInterface.print_status   s    ????@@@ 	LM JL J JKKK=*;==>>>r-   )NN)F)__name__
__module____qualname__r	   strr,   r   r   tupleintrJ   rM   rO   rR   rW   boolr\   r   dictr`    r-   r+   r#   r#   v   s+       	' 	'8C= 	'HSM 	' 	' 	' 	',-8R*S ,X]^acf^fXg , , , ,\s      s    
 C    
 $    
s ?O _c      r-   r#   c                      e Zd ZU dZ edddi          Zee         ed<    edddi          Z	ee         ed<    eddd	i          Z
ee         ed
<    edddi          Zeed<    edddi          Zee         ed<    edddi          Zeed<    edddi          Zee         ed<    edddi          Zeed<    edddi          Zeed<    eddg dd          Zee         ed<    eddg dd          Zee         ed <    eddd!i          Zeed"<    eddd#i          Zee         ed$<    eddd%i          Zeed&<    eddd'i          Zeed(<    ed)d*d+d)gd          Zeed,<    eddd-i          Zeed.<    ed/dd0i          Zeed1<    ed2dd3i          Zeed4<   d5 ZdS )6ChatArgumentsz
    Arguments for the chat CLI.

    See the metadata arg for each argument's description -- the medatata will be printed with
    `transformers chat --help`
    Nhelpz_Name of the pre-trained model. The positional argument will take precedence if both are passed.)defaultmetadatamodel_name_or_pathzKUsername to display in chat interface. Defaults to the current user's name.r(   zSystem prompt.system_promptz./chat_history/zFolder to save chat history.save_folderz"Path to a yaml file with examples.examples_pathFz7Whether to show runtime warnings in the chat interface.verbosezPath to a local generation config file or to a HuggingFace repo containing a `generation_config.json` file. Other generation settings passed as CLI arguments will be applied on top of this generation config.r]   mainzLSpecific model version to use (can be a branch name, tag name or commit id).model_revisionautozDevice to use for inference.devicezA`torch_dtype` is deprecated! Please use `dtype` argument instead.)rv   bfloat16float16float32)rl   r9   torch_dtypezOverride the default `torch.dtype` and load the model under this dtype. If `'auto'` is passed, the dtype will be automatically derived from the model's weights.dtypez2Whether to trust remote code when loading a model.trust_remote_codezWhich attention implementation to use; you can run --attn_implementation=flash_attention_2, in which case you must install this manually by running `pip install flash-attn --no-build-isolation`.attn_implementationzIWhether to use 8 bit precision for the base model - works only with LoRA.load_in_8bitzIWhether to use 4 bit precision for the base model - works only with LoRA.load_in_4bitnf4zQuantization type.fp4bnb_4bit_quant_typez#Whether to use nested quantization.use_bnb_nested_quant	localhostz%Interface the server will listen to..host@  zPort the server will listen to.portc                     | j         E| j        | j         | _        dS | j         | j        k    r"t          d| j          d| j         d          dS dS )z(Only used for BC `torch_dtype` argument.Nz`torch_dtype` z and `dtype` zn have different values. `torch_dtype` is deprecated and will be removed in 4.59.0, please set `dtype` instead.)r{   r|   
ValueErrorrP   s    r+   __post_init__zChatArguments.__post_init__%  s     'z!!-


!TZ// MT%5 M MDJ M M M  	 (' 0/r-   )ra   rb   rc   __doc__r   ro   r	   rd   __annotations__r(   rp   rq   rr   rs   rg   r]   ru   rw   r{   r|   r}   r~   r   r   r   r   r   r   rf   r   ri   r-   r+   rk   rk      s          ).u
) ) )     %gh  D(3-    $)5IY@Z#[#[#[M8C=[[[u%6&JhAijjjKjjj#(5Im@n#o#o#oM8C=oooE%6;t2uvvvGTvvv (-u1
	( 	( 	(x} 	 	 	  %hi  NC    %&:X1YZZZFCZZZ!&WAAA
 
" " "K#    !5PAAA
 
  E8C=    $e)] ^  t    */ r
* * *#    ef  L$    ef  L$     %uUFZhmotgu=v=vwwwwww!&uHm?n!o!o!o$ooo kV=d4efffD#fffdf6W-XYYYD#YYY
 
 
 
 
r-   rk   argsc                      t          |           S )z;
    Factory function used to chat with a local model.
    )ChatCommand)r   s    r+   chat_command_factoryr   2  s     tr-   c                   "   e Zd Zedefd            Zd Zedefd            Zed!de	de
e         defd	            Zed!d
e
e         dee         fd            Zdee         defdZde	dedeeef         fdZededede
e         de
e         deeee         f         f
d            Zede	de
e         fd            Zde	dedef         fdZdede	dedeeeeef         f         dededee         deee         eef         fdZd Zd  ZdS )"r   parserc                    t           f}|                     d|          }|                    d          }|                    dt          dd           |                    dt          dd	d
           |                    t                     dS )z
        Register this command to argparse so it's available for the transformer-cli

        Args:
            parser: Root parser to register command-specific arguments
        chat)dataclass_typeszPositional argumentsmodel_name_or_path_or_addressNz7Name of the pre-trained model or address to connect to.)typerm   rl   generate_flagsa  Flags to pass to `generate`, using a space as a separator between flags. Accepts booleans, numbers, and lists of integers, more advanced parameterization should be set through --generation-config. Example: `transformers chat <model_repo> max_new_tokens=100 do_sample=False eos_token_id=[1,2]`. If you're a new user, check this basic flag guide: https://huggingface.co/docs/transformers/llm_tutorial#common-options*)r   rm   rl   nargs)func)rk   
add_parseradd_argument_groupadd_argumentrd   set_defaultsr   )r   r   chat_parsergroups       r+   register_subcommandzChatCommand.register_subcommand:  s     )*'''PP../EFF+J	 	 	
 	
 	
 	W  	 	
 	
 	
 	  &: ;;;;;r-   c                    |j         |j         }|                    d          s*|                    d          s|                    d          rkd| _        |j        dk    s|j        dk    rt          d          |j                             dd          \  |_        |_        |j        t          d	          nd
| _        |j         |_        t                      s$t                      s| j        rt          d          t                      st          d          t                      s| j        rt          d          || _        d S )Nhttphttpsr   Fr   uu   Looks like you’ve set both a server address and a custom host/port. Please pick just one way to specify the server.:   z\When connecting to a server, please specify a model name with the --model_name_or_path flag.TzYou need to install rich to use the chat interface. Additionally, you have not specified a remote endpoint and are therefore spawning a backend. Torch is required for this: (`pip install rich torch`)zHYou need to install rich to use the chat interface. (`pip install rich`)zYou have not specified a remote endpoint and are therefore spawning a backend. Torch is required for this: (`pip install rich torch`))r   r@   spawn_backendr   r   r   rsplitro   r   r   ImportErrorr   )r*   r   names      r+   r,   zChatCommand.__init__[  s   -95Dv&& M$//'*B*B MdooVaFbFb M%*"9++tyD/@/@$J  
 (,'I'P'PQTVW'X'X$	49*2$v   3
 &*"*.*L' "" 	,>,@,@ 	TEW 	x   #$$ 	hiii#%% 	$*< 	7  
 			r-   r/   c                      t          j                    dk    rt          j                    S t	          j        t          j                              j        S )z)Returns the username of the current user.r   )platformsystemosgetloginpwdgetpwuidgetuidpw_nameri   r-   r+   get_usernamezChatCommand.get_username  s<     ?	));== <	,,44r-   Nr   filenamec                    i }t          |          |d<   | |d<   |j        }|At          j        d          }|j         d| d}t
          j                            ||          }t          j        t
          j        	                    |          d           t          |d	          5 }t          j        ||d
           ddd           n# 1 swxY w Y   t
          j                            |          S )z!Saves the chat history to a file.settingschat_historyNz%Y-%m-%d_%H-%M-%Sz/chat_.jsonT)exist_okwr1   )indent)varsrq   timestrftimer   r   pathrA   makedirsdirnameopenjsondumpabspath)r   r   r   output_dictfoldertime_strfs          r+   	save_chatzChatCommand.save_chat  s    "&t**J&*N#!}%899H<SSHSSSHw||FH55H
BGOOH--====(C   	0AIk1Q////	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0wx(((s   'CCCrp   c                     | g }nd| dg}|S )zClears the chat history.Nr   roler;   ri   )rp   r   s     r+   clear_chat_historyzChatCommand.clear_chat_history  s&      DD%-@@ADr-   r   c                    t          |          dk    ri S d |D             }d |                                D             }d |                                D             }dt          dt          fdfd|                                D             }d	                    d
 |                                D                       }d|z   dz   }|                    dd          }|                    dd          }|                    dd          }|                    dd          }|                    dd          }|                    dd          }	 t          j        |          }n"# t          j        $ r t          d          w xY w|S )zUParses the generate flags from the user input into a dictionary of `generate` kwargs.r   c                     i | ]=}d |                     d          d         z   d z   |                     d          d         >S )"=r   r   )split).0flags     r+   
<dictcomp>z4ChatCommand.parse_generate_flags.<locals>.<dictcomp>  sD    !p!p!pY]#

3(:":S"@$**S//RSBT!p!p!pr-   c                 n    i | ]2\  }}||                                 d v r|                                 n|3S ))truefalse)lowerr   kvs      r+   r   z4ChatCommand.parse_generate_flags.<locals>.<dictcomp>  sJ     "
 "
 "
FJaAAGGII):::qwwyyy"
 "
 "
r-   c                 *    i | ]\  }}||d k    rdn|S )Nonenullri   r   s      r+   r   z4ChatCommand.parse_generate_flags.<locals>.<dictcomp>  s*    !m!m!mda!qF{{VV!m!m!mr-   sr/   c                 ~    |                      d          } |                     ddd                                          S )N-.r4   r   )removeprefixreplaceisdigit)r   s    r+   	is_numberz3ChatCommand.parse_generate_flags.<locals>.is_number  s5    s##A99S"a((00222r-   c                 >    i | ]\  }}| |          sd | d n|S )r   ri   )r   r   r   r   s      r+   r   z4ChatCommand.parse_generate_flags.<locals>.<dictcomp>  s9    !t!t!tTQPQ!YYq\\%HXXXXXq!t!t!tr-   z, c                 "    g | ]\  }}| d | S )z: ri   r   s      r+   
<listcomp>z4ChatCommand.parse_generate_flags.<locals>.<listcomp>  s&    *b*b*b41aa;;1;;*b*b*br-   {}z"null"r   z"true"r   z"false"r   z"[[z]"rU   r   r   zFailed to convert `generate_flags` into a valid JSON object.
`generate_flags` = {generate_flags}
Converted JSON string = {generate_flags_string})
lenitemsrd   rg   rA   r   r   loadsJSONDecodeErrorr   )r*   r   generate_flags_as_dictgenerate_flags_stringprocessed_generate_flagsr   s        @r+   parse_generate_flagsz ChatCommand.parse_generate_flags  s   ~!##I
 "q!pao!p!p!p"
 "
NdNjNjNlNl"
 "
 "
 "n!mNdNjNjNlNl!m!m!m	3 	3 	3 	3 	3 	3
 "u!t!t!tUkUqUqUsUs!t!t!t
 !%		*b*bCYC_C_CaCa*b*b*b c c !$&; ;c A !6 = =h O O 5 = =h O O 5 = =i Q Q 5 = =dC H H 5 = =dC H H !6 = =c3 G G	'+z2G'H'H$$# 	 	 	D  	 ('s   E$ $Fmodel_generation_configc                    |j         d|j         v r^t          j                            |j                   }t          j                            |j                   }t          j        ||          }n>t          j        |j                   }n$t          j        |          } |j	        di ddd | 
                    |j                  } |j	        di |}||fS )zj
        Returns a GenerationConfig object holding the generation parameters for the CLI command.
        Nr   T   )	do_samplemax_new_tokensri   )r]   r   r   r   basenamer   from_pretrainedcopydeepcopyrC   r   r   )r*   r   r   r   r   r]   parsed_generate_flagsr^   s           r+   get_generation_parameterizationz+ChatCommand.get_generation_parameterization  s     !-$000'//$*@AA7++D,BCC$4$DWh$W$W!!$4$DTE[$\$\!!
 !%.E F F$$RRTS'Q'QRRR !% 9 9$:M N N/(/HH2GHH !,..r-   	tokenizerr]   
eos_tokenseos_token_idsc                 v   |j         |j        }n|j         }g }|;|                    |                     |                    d                               |2|                    d |                    d          D                        t          |          dk    r|                    |j                   ||fS )z:Retrieves the pad token ID and all possible EOS token IDs.N,c                 ,    g | ]}t          |          S ri   )rf   )r   token_ids     r+   r   z0ChatCommand.parse_eos_tokens.<locals>.<listcomp>  s    %]%]%]c(mm%]%]%]r-   r   )pad_token_ideos_token_idextendconvert_tokens_to_idsr   r   r?   )r  r]   r  r  r  all_eos_token_idss         r+   parse_eos_tokenszChatCommand.parse_eos_tokens  s     )1,9LL,9L!$$Y%D%DZEUEUVYEZEZ%[%[\\\$$$%]%]MDWDWX[D\D\%]%]%]^^^ !!Q&&$$%6%CDDD...r-   
model_argsc                     | j         r)t          d| j        | j        | j        | j                  }n| j        rt          d          }nd }|S )NT)r   bnb_4bit_compute_dtyper   bnb_4bit_use_double_quantbnb_4bit_quant_storage)r   )r   r   r|   r   r   r   )r  quantization_configs     r+   get_quantization_configz#ChatCommand.get_quantization_config  sv    " 	'"4!'1'7$.$B*4*I'1'7# # # $ 	'"4!# # # #'""r-   r   c                    t          j        |j        |j        |j                  }|j        dv r|j        nt          t          |j                  }|                     |          }|j        |j	        |d|d}t          j        |j        fd|j        i|}t          |dd           |                    |j                  }||fS )N)revisionr}   )rv   Nrv   )r  r~   r|   
device_mapr  r}   hf_device_map)r   r   model_name_or_path_positionalru   r}   r|   getattrtorchr  r~   r   torw   )r*   r   r  r|   r  r^   models          r+   load_model_and_tokenizerz$ChatCommand.load_model_and_tokenizer)  s    !1.("4
 
 
	 #jN::

tz@Z@Z"::4@@+#'#; #6
 
 %4.
 
BFBX
\h
 
 5/4008HHT[))Eir-   
user_input	interfaceexamplesr^   r   c                    d}|dk    r0|                      |j                  }|                                 n|dk    r|                                 n|                    d          rt          |                                          dk     rf|                                }	t          |	          dk    r	|	d         }
nd}
|                     |||
          }
|                    d|
 d	d
           n|                    d          r|dd         	                                }|                                }|D ]#}d|vr|                    d| dd            n0$| 
                    |          } |j        di |} |j        di | nI|                    d          rt          |                                          dk    r|                                d         }||v r\|                                 g }|                    ||         d                    |                    d||         d         d           nd| dt          |                                           d}|                    |d           nU|dk    r|                    |j        ||           n1d}|                    d| dd           |                                 ||||fS )z
        Handles all user commands except for `!exit`. May update the chat history (e.g. reset it) or the
        generation config (e.g. set a new flag).
        Tz!clearz!helpz!save   r   NzChat saved in !green)r   rS   z!setr1   r   z(Invalid flag format, missing `=` after `z;`. Please use the format `arg_1=value_1 arg_2=value_2 ...`.red!exampler   r(   r   zExample z* not found in list of available examples: r   z!status)r$   r]   r^   F'z/' is not a valid command. Showing help message.ri   )r   rp   rO   r\   r@   r   r   r   rW   rB   r   rC   rR   r?   listkeysr`   ro   )r*   r#  r   r$  r%  r]   r^   r   valid_commandsplit_inputr   new_generate_flagsr   parsed_new_generate_flagsnew_model_kwargsexample_nameexample_errors                    r+   handle_non_exit_user_commandsz)ChatCommand.handle_non_exit_user_commandsD  s|    !!**4+=>>DOO7""  """"""7++ 7	#J4D4D4F4F0G0G!0K0K$**,,K;1$$&q>~~dD(;;H!!'C'C'C'C7!SSSS""6** -	# ",ABB!5!5!7!7!3!9!9!;!;* 8 8d??))At A A A $ *    E # -1,E,EFX,Y,Y)#;#4#;#X#X>W#X#X ##77&6777"":.. 	#3z7G7G7I7I3J3Ja3O3O%++--a0Lx''!!!,,Xl-CF-KLLLV8Nv8VWWXXXX p|ooW[\d\i\i\k\kWlWlooo  %%=%FFFF9$$""2"3) #     "M!!'f:'f'f'fns!ttt  """]$5|CCr-   c                 R    t          j        |                                            d S N)asynciorun
_inner_runrP   s    r+   r:  zChatCommand.run  s"    DOO%%&&&&&r-   c                   K   | j         rt          | j        j        | j        j        | j        j        | j        j        | j        j        | j        j        | j        j	        | j        j
        | j        j        | j        j        d          }t          |          }t          |j                  }d|_        |                                 | j        j        dz   | j        j        z   }| j        j        dk    rdn| j        j        }| j        }|j        t*          }n@t-          |j                  5 }t/          j        |          }d d d            n# 1 swxY w Y   |j        |                                 }	n|j        }	t7          j        |j                  }
|                     ||
          \  }}t=          |j        |	          }|                                 |                      |j!                  }|"                    d	           tG          | d
| j        j                   4 d {V }	 	 |$                                }|%                    d          rA|dk    rn| &                    |||||||          \  }}}}|r|%                    d          skn|'                    d|d           |(                    |d|)                                |d          }|*                    |           d {V }|'                    d|d           n# tV          $ r Y nw xY w	 d d d           d {V  d S # 1 d {V swxY w Y   d S )Nerror)rw   r|   r}   r~   r   r   r   r   r   r   	log_level)targetT@r   zhttp://localhost)r$   r%   )rX   r   r(  z!exit)r#  r   r$  r%  r]   r^   r   r+  r(   r   )r]   r!  )r.   
extra_bodyr'   ),r   r   r   rw   r|   r}   r~   r   r   r   r   r   r   r   r   r:  daemonstartro   ru   rr   DEFAULT_EXAMPLESr   yaml	safe_loadr(   r   r   r   r  r#   rO   r   rp   r\   r
   rM   r@   r6  r?   chat_completionto_json_stringrJ   KeyboardInterrupt)r*   
serve_argsserve_commandthreadr!  r   r   r%  r   r(   r   r]   r^   r$  r   clientr#  r/  r.   model_outputs                       r+   r;  zChatCommand._inner_run  sY      	'y'io"&)"=$(I$A!Y3!Y3$(I$A%)Y%CY^Y^!  J )44M=#4555F FMLLNNN	,s2TY5MM%)Y^{%B%B!!	y%'HHd()) -Q>!,,- - - - - - - - - - - - - - - 9$$&&DD9D"2"B4CZ"["[*.*N*NtUl*m*m'<!T-DPTUUU	&&t'9:: 	T***'4(B(B$).(B(BCC '	 '	 '	 '	 '	 '	 '	v&%!*!2!2J ",,S11 M%00!SWSuSu+5%)*3)12C-9%) Tv T TPD-1BL  - %J4I4I*4U4U %$% V
$K$KLLL#33#1B1Q1Q1S1S%*$ $ 4  F *3)@)@)H)H#H#H#H#H#H#HLKK N NOOOO(   EK& &'	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	sa   +EEE*L5-/LL58LL5A9LL5
LL5LL55
L?L?r8  )ra   rb   rc   staticmethodr   r   r,   rd   r   rk   r	   r   r-  rh   r   r   r   re   r  r   rf   r  r   r  r   r"  r#   r6  r:  r;  ri   r-   r+   r   r   9  s       <N < < < \<@# # #N 5# 5 5 5 \5 ) )m )x} )PS ) ) ) \)$  (3- 4:    \3(49 3( 3( 3( 3( 3(j/!/<L/	%	&/ / / /8 /&/+/ SM/  }	/
 
sDI~	/ / / \/6 #M #hGY>Z # # # \#& ]  uE[]jEj?k        6PDPD PD !	PD
 sDcN*+PD ,PD PD 4jPD 
tDz+T1	2PD PD PD PDh' ' 'U U U U Ur-   r   __main__z meta-llama/Llama-3.2-3b-Instructzhttp://localhost:8000)Er9  r  r   r   r   r<   stringr   argparser   r   collections.abcr   dataclassesr   r   	threadingr   typingr	   rE  huggingface_hubr
   r   transformersr   r   r   transformers.commandsr   transformers.commands.servingr   r   transformers.utilsr   r   readliner   r   r   rich.consoler   	rich.liver   rich.markdownr   r  r   r   setascii_letters
whitespaceALLOWED_KEY_CHARSdigitsALLOWED_VALUE_CHARSrD  rZ   rA   r.  r[   r#   rk   r   r   ra   r   r   r   r:  ri   r-   r+   <module>rf     s       				  				   . . . . . . . . ) ) ) ) ) ) ( ( ( ( ( ( ( (              L L L L L L L L         
 = < < < < < F F F F F F F F D D D D D D D D	OOOO 	 	 	D	 8?	!!JJJ '$$$$$$&&&&&& LLL       
 C,v/@@AA c
6=(6+<<?bb  
 MN) QRNO./JK?@   	  ";;'7'<'<'>'>??  &Y Y Y Y Y Y Y Yx \ \ \ \ \ \ \ \~y    w w w w w, w w wt z=??D)KD&)@D&;tDHHJJJJJ s   0A5 5A=<A=