
    Z jq                     b   S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKJrJ	r	  S SK
JrJr  S SKJrJr  S SKrS SKrS SKrS SKrS SKJrJr  S SKJr  S SKJr   S SKr\R:                  " 5       S:w  a  S SKr\" 5       (       a,  S S	KJ r   S S
K!J"r"  S SK#J$r$  S SK%J&r&  S SK'J(r(J)r)J*r*J+r+J,r,  S SK-J.r.  SSS.r/\0" \Rb                  \Rd                  -   5      r3\0" \Rb                  \Rh                  -   \Rd                  -   S-   5      r5SS0SS0SS0SS0SS0SS0SS0S.r6Sr7SSRq                  \6Rs                  5       5       S3r: " S  S!5      r; " S" S#5      r<S$\=S-  S%\4S& jr>S'\?\=   S-  S%\@4S( jrAS3S)\=S-  S%\?\@   4S* jjrBS+\=S,\?\@   S-\@S%\=4S. jrCS%\=4S/ jrD\ES0:X  a  \<" S1S29  gg! \ a     GNOf = f)4    N)AsyncIterator	Awaitable)	AnnotatedAny)urljoinurlparse)AsyncInferenceClientChatCompletionStreamOutput)GenerationConfig)is_rich_availableWindows)filesize)Console)Live)Markdown)	BarColumnProgressProgressColumn
TextColumnTimeElapsedColumn)Text	localhosti@  )hostnameportz .!\"#$%&'()*+,\-/:<=>?@[]^_`{|}~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_ID}/chat_{DATETIME}.yaml` or `{SAVE_NAME}` if provided
- **!exit**: closes the interface
c                       \ rS rSrS\S\S\4S jrS\\\      S\	\\\
-  S-  4   4S	 jrS\4S
 jrS rS\4S jrS\S\4S jrSS\S\S\4S jjrSS\4S jjrS\4S jrS\4S jrSrg)RichInterfacej   model_iduser_idbase_urlc                 F    [        5       U l        Xl        X l        X0l        g N)r   _consoler&   r'   r(   )selfr&   r'   r(   s       f/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/transformers/cli/chat.py__init__RichInterface.__init__k   s    	      streamreturnNc           	      l  #    U R                   R                  SU R                   S35        [        U R                   SS9 nSnSn[        R                  " 5       nS nUI S h  vN   S h  vN nUR
                  S   R                  R                  n[        UR
                  S   SU5      n[        USS 5      n	U	b  [        U	S	U5      nU(       d  Ml  [        R                  " S
SU5      nX8-  n/ n
UR                  5        HN  nU
R                  U5        UR                  S5      (       a  U
R                  S5        M=  U
R                  S5        MP     [        SR                  U
5      R!                  5       SS9nUR#                  USS9  GM&   GN+ GN%
 S S S 5        O! , (       d  f       O= f[        R                  " 5       W-
  nUS:  aK  WS:  aE  XM-  nU R                   R                  5         U R                   R                  SU SUS SUS S35        U R                   R                  5         WW4$ 7f)Nz[bold blue]<z>:   )consolerefresh_per_second r   finish_reasonusagecompletion_tokensz<(/*)(\w*)>z\<\1\2\>z```
z  
zgithub-dark)
code_themeT)refreshz[dim]z tokens in z.1fzs (z tok/s)[/dim])r+   printr&   r   timechoicesdeltacontentgetattrresub
splitlinesappend
startswithr   joinstripupdate)r,   r1   liver   r:   
start_timer8   tokenoutputsr9   lineslinemarkdownelapsedtok_per_secs                  r-   stream_outputRichInterface.stream_outputq   s     	l4==/<=$--A>$D !J(,M%+|| )4e--*0088 'a(8/= Yw5$(/7JL](^% &&gF  OO-DLL&u-- T*V, . $BGGEN$8$8$:}U Hd3S  , )4| ?>>` ))+
*Q;,q0+5KMM!MM%(9':+gc]RUVabeUffs tu]""sO   >H4 !F!F"F&F*F+F.DFFF	H4
F*&BH4c                     U R                   R                  SU R                   S35      nU R                   R                  5         U$ )z!Gets user input from the console.[bold red]<z>:
)r+   inputr'   r>   )r,   rY   s     r-   rY   RichInterface.input   s8    ##k$,,t$DEr0   c                 8    U R                   R                  5         g)zClears the console.N)r+   clear)r,   s    r-   r\   RichInterface.clear   s    r0   r   c                     U R                   R                  SU R                   SU 35        U R                   R                  5         g)z%Prints a user message to the console.rX   z>:[/ bold red]
N)r+   r>   r'   )r,   r   s     r-   print_user_message RichInterface.print_user_message   s6    k$,,7GvNOr0   colorc                 z    U R                   R                  SU SU 35        U R                   R                  5         g)z,Prints text in a given color to the console.z[bold ]N)r+   r>   )r,   r   ra   s      r-   print_colorRichInterface.print_color   s1    fUG1TF34r0   messagedefaultc                     U(       a  SOSnU R                   R                  SU SU S35      nU R                   R                  5         UR                  5       R	                  5       nU(       d  U$ US;   $ )zFDisplays a yes/no prompt to the user, returning True for confirmation.zY/nzy/Nz[bold yellow]z (z): >   yyes)r+   rY   r>   rJ   lower)r,   rf   rg   default_hintresponses        r-   confirmRichInterface.confirm   sf     'uU==&&wir,s'ST>>#))+N<''r0   minimalc                     U R                   R                  [        U(       a  [        O[        5      5        U R                   R                  5         g)z'Prints the help message to the console.N)r+   r>   r   HELP_STRING_MINIMALHELP_STRING)r,   rp   s     r-   
print_helpRichInterface.print_help   s.    HG%8UVr0   modelc           
      $  ^^^ [         R                  " U R                  R                  S5       S3ST0SS9nUR	                  5          " S S[
        5      nSS	S
SS.mU R                  R                  [        T5      S-   S-   :  mUUU4S jn[        [        S5      [        SS9U" 5       [        5       U R                  S9nUR                  U" S5      S S9nSn[        XPR                  SS9   UR                  5        GH  nU(       a  UR!                  S5      (       d  M#  ["        R$                  " USS  5      n	U	R'                  S5      n
U
S:X  a  U	R'                  SS5      n  OU
S:X  a  [)        U	R'                  SS5      5      eU
S :X  d  M  U	R'                  S!5      nU	R'                  S"5      nU" U5      nU(       a0  US#:X  a  S$OS%nUR+                  XmUS&   UR'                  S'5      US(9  M  UR+                  XmS)S S*9  GM     S S S 5        U(       a)  U R                  R-                  [/        S+T S,35      5        O(U R                  R-                  [/        S+T S-35      5        U R                  R-                  5         g ! , (       d  f       N= f).N/z/load_modelrv   T)jsonr1   c                       \ rS rSrS rSrg)3RichInterface.print_model_load.<locals>.StatsColumn   c                    UR                   (       d  [        S5      $ UR                  R                  S5      S:X  a  [        R
                  " [        UR                  5      5      n[        R
                  " [        UR                   5      5      nUR                  (       a-  S[        R
                  " [        UR                  5      5       S3OSnUR                  b6  S[        UR                  S-  5       S[        UR                  S-  5      S 3nOSn[        U S	U U U 3S
S9$ [        [        UR                  5       S	[        UR                   5       35      $ )Nr7   unitbytesz  z/s<   :02drx   zprogress.download)style)
totalr   fieldsgetr   decimalint	completedspeedtime_remaining)r,   taskdonetotr   etas         r-   render:RichInterface.print_model_load.<locals>.StatsColumn.render   s   zz8O;;??6*g5#++C,?@D"**3tzz?;CJN**b!1!1#djj/!B C2FZ\E**6 "3t':':b'@#A"B!CH[H[^`H`DabeCfg 4&#ugcU ;CVWWs4>>231S_4EFGGr0    N)__name__
__module____qualname____firstlineno__r   __static_attributes__r   r0   r-   StatsColumnr{      s    Hr0   r   zLoading processorzLoading configzDownloading fileszLoading into memory)	processorconfigdownloadweights   F   c                 F   > TR                  X 5      nT(       a  T SU 3$ U$ )Nu     →  )r   )	stage_key
stage_textrv   show_model_prefixstage_labelss     r-   _label.RichInterface.print_model_load.<locals>._label   s-    %)))?J 
|44r0   z[bold]{task.description}(   )	bar_width)r5   r   )r   F)r5   	transients   data:    statusreadycachederrorrf   zUnknown errorloadingstageprogressr   r   itemscurrentr   )descriptionr   r   r~   r   )r   r   r   z_*z was already loaded.*_z is warm.*_)requestspostr(   rstripraise_for_statusr   r+   widthlenr   r   r   r   add_taskr   
iter_linesrH   ry   loadsr   RuntimeErrorrK   r>   r   )r,   rv   rm   r   r   r   task_idr   rQ   eventr   r   proglabelr~   r   r   s    `             @@r-   print_model_loadRichInterface.print_model_load   sQ   ==DMM$8$8$=#>k!JRY[`Qajno!!#	H. 	H& -&+,	
 !MM//3u:>B3FF	 12#MMM
 ##F;$7t#D(MMTB ++-4??9#=#=

48,8,W$"YYx7FW$&uyyO'LMMY&!IIg.E 99Z0D"5ME*/:*=w7 #$y/Y]YaYabiYjqu (  !aW[\1 . C6 MM2eW4J)K LMMM2eWK)@ AB? CBs   .BJA7J
Jr   c                     U R                   R                  SU R                   S35        U R                   R                  SU 35        U R                   R                  5         g)zFPrints the status of the model and generation settings to the console.z[bold blue]Model: r;   z[bold blue]N)r+   r>   r&   )r,   r   s     r-   print_statusRichInterface.print_status%  sK    0rBCk&23r0   )r+   r(   r&   r'   )F)r   r   r   r   strr.   r   r   r
   tupler   rU   rY   r\   r_   rd   boolrn   rt   r   r   r   r   r   r0   r-   r$   r$   j   s    ! !s !c !;#.H IJ;#	sC#I$$	%;#zs s 
 C 

(s 
(T 
(d 
($ 
Pc Pd#3 r0   r$   c                   ,   \ rS rSrSrS\S    S\S    3SSSSSS4S	\\\R                  " S
S94   S\\S-  \R                  " SS94   S\\
\   S-  \R                  " SS94   S\\S-  \R                  " SS94   S\\S-  \R                  " SS94   S\\\R                  " SS94   S\\S-  \R                  " SS94   S\\S-  \R                  " SS94   SS4S jjr\S 5       rS\S\S\\\\\4   4   S \S!\
\   S\\
\   \4   4S" jrS# rS$rg)%Chati,  (Chat with a model from the command line.zhttp://r   r   r   Nz./chat_history/r&   z9ID of the model to use (e.g. 'HuggingFaceTB/SmolLM3-3B').)helpr(   z7Base url to connect to (e.g. http://localhost:8000/v1).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 <base_url> <model_id> 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userzKUsername to display in chat interface. Defaults to the current user's name.system_promptzSystem prompt.save_folderzFolder to save chat history.examples_pathz"Path to a yaml file with examples.generation_configzPath 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.r2   c	                    X l         [        U R                   5      n	U	R                  [        S   :X  a2  U	R                  [        S   :X  a  U R                  U R                   5        Xl        XPl        X`l        [        U5      n
U
R                  SSS9  U
R                  " S	0 [        U5      D6  Xl        X!U R                  R                  5       S.U l        Ub  UO	[        5       U l        U(       a0  [#        U5       n[$        R&                  " U5      U l        SSS5        O[*        U l        [-        5       (       d  [/        S5      e[0        R2                  " U R5                  5       5        g! , (       d  f       NM= f)
r   r   r   T   )	do_samplemax_new_tokens)r(   r&   r   NzHYou need to install rich to use the chat interface. (`pip install rich`)r   )r(   r   r   DEFAULT_HTTP_ENDPOINTr   check_healthr&   r   r   load_generation_configrK   parse_generate_flagsr   to_dictsettingsget_usernamer   openyaml	safe_loadexamplesDEFAULT_EXAMPLESr   ImportErrorasynciorun
_inner_run)r,   r&   r(   r   r   r   r   r   r   parsedr   fs               r-   r.   Chat.__init__1  s&   F !$--(??3J??FKKShioSpDpdmm, *& ((9:S9=,^<=%-t{{ObObOde !,D,.	 m$ $q 1 %$ -DM !""hii 	DOO%& %$s   ;E**
E8c                     [        U S-   S5      n [        R                  " U5      nUR                  S:w  a  [	        SU  SUR                   S35      e g	! [        R
                   a    [	        SU  S35      ef = f)
Nrx   health   zThe server running on z returned status code z on health check (/health).zNo server currently running on z. To run a local server, please run `transformers serve` in aseparate shell. Find more information here: https://huggingface.co/docs/transformers/servingT)r   httpxr   status_code
ValueErrorConnectError)url
health_urloutputs      r-   r   Chat.check_healthw  s    S3Y1

	YYz*F!!S( ,SE1GHZHZG[[vw  )  !! 	1# 7o p 	s   AA $A9
user_input	interfacer   r   chatc                    SnUS:X  a'  [        U R                  5      nUR                  5         GO[US:X  a  UR                  5         GOCUR	                  S5      (       a  [        UR                  5       5      S:  a  UR                  5       n[        U5      S:X  a  US   OL[        R                  R                  U R                  U R                  S[        R                  " S5       S	35      n[        XU R                  S
9  UR!                  SU S3SS9  GOuUR	                  S5      (       ae  USS R#                  5       n	U	R                  5       n	U	 H   n
SU
;  d  M  UR!                  SU
 S3SS9    GO   UR$                  " S"0 ['        U	5      D6  OUR	                  S5      (       a  [        UR                  5       5      S:X  a  UR                  5       S   nX;   aB  UR                  5         / nUR)                  X;   S   5        UR+                  SX;   S   S.5        OmSU S[-        UR/                  5       5       S3nUR!                  USS9  O<US:X  a  UR1                  US9  O&SnUR!                  S U S!3SS9  UR                  5         XVU4$ )#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).
T!clear!help!save      chat_%Y-%m-%d_%H-%M-%S.jsonfilenamer   r   Chat saved to !greenr   ra   !setr4   N=(Invalid flag format, missing `=` after `;`. Please use the format `arg_1=value_1 arg_2=value_2 ...`.red!exampler   r   rolerB   Example * not found in list of available examples: .!statusr   F'/' is not a valid command. Showing help message.r   )new_chat_historyr   r\   rt   rH   r   splitospathrI   r   r&   r?   strftime	save_chatr   rd   rJ   rK   r   r_   rG   listkeysr   )r,   r   r   r   r   r   valid_commandsplit_inputr  new_generate_flagsflagexample_nameexample_errors                r-   handle_non_exit_user_commands"Chat.handle_non_exit_user_commands  s    !#D$6$67DOO7"  """7++J4D4D4F0G!0K$**,K {#q( AWW\\$"2"2DMMU4==YlKmJnnsCtu 
 xT]]K!!z'C7!S""6** ",AB!5!5!7!3!9!9!;*d?))Ftf MA A $ *   + I 45G HI"":..3z7G7G7I3Ja3O%++-a0L'!,,X-CF-KLV8Nv8VWX |n,VW[\d\i\i\kWlVmmno  %%=%F9$""&"1 "M!!:,6e'fns!t  "F**r0   c           	      :	  #    [        U R                  U R                  U R                  S9nUR	                  5         [        U R                  5      nUR                  SS9  UR                  U R                  5        U R                  n[        U R                  S9 IS h  vN nS n  Ub  UnS nUR                  U5        OUR                  5       nUS:X  a  GOUS:X  a'  [        U R                  5      nUR	                  5         M`  US:X  a  UR                  5         Mx  UR                  S5      (       a  [        UR                  5       5      S	:  a  UR                  5       n[        U5      S	:X  a  US
   OL[         R"                  R%                  U R&                  U R                  S[(        R*                  " S5       S35      n[-        XU R.                  S9  UR1                  SU S3SS9  GMG  UR                  S5      (       af  USS  R3                  5       n	U	R                  5       n	U	 H  n
SU
;  d  M  UR1                  SU
 S3SS9    O   UR4                  " S,0 [7        U	5      D6  GM  UR                  S5      (       a  [        UR                  5       5      S	:X  a  UR                  5       S
   nXR8                  ;   aX  UR	                  5         / nUR                  U R8                  U   S   5        UR;                  SU R8                  U   S   S.5        OSU S[=        U R8                  R?                  5       5       S3nUR1                  USS9  OiUS :X  a  URA                  US!9  GM  UR                  S5      (       a'  UR1                  S"U S#3SS9  UR                  5         GM   UR;                  SUS.5        URC                  5       U R                  S$.nURE                  USU R                  US%9nURG                  U5      I S h  vN u  nnUR;                  S&US.5        US':X  a-  UR1                  S(S)5        URI                  S*5      (       a  S+nGM  GM  S S S 5      IS h  vN   g  GN Ne! [J         a     M#  f = f N! , IS h  vN  (       d  f       g = f7f)-N)r&   r'   r(   T)rp   )r(   z!exitr   r   r   r   r   r   r   r  r  r  r  r  r  r  r4   r	  r
  r  r  r  r   r   r  r  r  r  r  r  r  r  )r   rv   )r1   rv   
extra_body	assistantlengthz2Generation stopped after reaching the token limit.yellowzContinue generating?u'   Please continue. Do not repeat text.”r   )&r$   r&   r   r(   r\   r  r   rt   r   r   r	   r_   rY   rH   r   r  r  r  rI   r   r?   r  r  r   rd   rJ   rK   r   r   rG   r  r  r   to_json_stringchat_completionrU   rn   KeyboardInterrupt)r,   r   r   r   clientpending_user_inputr   r   r  r!  r"  r#  r$  r(  r1   model_outputr8   s                    r-   r   Chat._inner_run  s    !4==$))VZVcVcd	 2 23 	T*""4==1'??6-1f)5%7
-1*!44Z@%.__%6
 "W,#x//0B0BC!) #w.!,,. #..w77C
@P@P@R<SVW<W&0&6&6&8  #;/14 (N!# $ 0 0$--5WjIkHllqAr" ! "8W!--^H:Q3OW^-_ #..v66 .8^-A-A-C*-?-E-E-G*$6D"$ ) 5 5*RSWRX YM )M +0 !6 !" !& %7 #MMU,@AS,TU #..z::s:CSCSCU?VZ[?['1'7'7'9!'<'==8%OO-#%D%88|9TU[9\] KKDMMR^D_`fDg(hi.6|nDnostx  uB  uB  uG  uG  uI  pJ  oK  KL  -MM%11}E1R#y0!..f.= #..s33!--#$ZL0_!`hm .  ",,.  V
$KL .4-B-B-D!%"J
 $33#"mm#-	 4 F 9B8O8OPV8W2W/L-KK NO$0!--.bdlm$,,-CDD1Z.$K  @??~ 3X ) Q @???s   BRQ)R"R'/Q.R+Q.RQ.RCQ.)R,AQ.23Q.%R(C=Q.%R(:Q."R%A!Q.Q,AQ.RR#Q?$R,Q..
Q<8R;Q<<R?RRR
RR)r(   r   r   r&   r   r   r   r   )r   r   r   r   __doc__r   r   r   typerArgumentr  Optionr.   staticmethodr   r$   dictr   r   r%  r   r   r   r0   r-   r   r   ,  s   2 +J78:OPV:W9XY 
 TXYjhl AD'C5p!qqrD' $J,eff
D' "INN[	
D'& $JLLkln
'D'. !tU\\?O-P!PQ/D'0 sELL6T$UUV1D'2 !tU\\?c-d!de3D'6 %$JLL g
7D'B 
CD'L   H+H+ !H+ sDcN*+	H+
 !H+ 4jH+ 
tDz++	,H+Ttr0   r   r   r2   c                     U c
  [        5       $ SU ;   aT  [        R                  R                  U 5      n[        R                  R	                  U 5      n[         R
                  " X5      $ [         R
                  " U 5      $ )Nr  )r   r  r  dirnamebasenamefrom_pretrained)r   r:  r  s      r-   r   r   I  se     !!##''//"3477##$56//BB//0ABBr0   r   c           	      (   U b  [        U 5      S:X  a  0 $ U  Vs0 s H0  nSUR                  S5      S   -   S-   UR                  S5      S   _M2     nnUR                  5        VVs0 s H+  u  p4X4R                  5       S;   a  UR                  5       OU_M-     nnnUR                  5        VVs0 s H  u  p4X4S:X  a  SOU_M     nnnS[        S	[
        4S
 jnUR                  5        VVs0 s H  u  p4X5" U5      (       d  SU S3OU_M     nnnSR                  UR                  5        VVs/ s H  u  p4U SU 3PM     snn5      nSU-   S-   nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      n [        R                  " U5      nU$ s  snf s  snnf s  snnf s  snnf s  snnf ! [        R                   a    [        S5      ef = f)zUParses the generate flags from the user input into a dictionary of `generate` kwargs.r   "r	  r   )truefalseNonenullsr2   c                 f    U R                  S5      n U R                  SSS5      R                  5       $ )N-r  r7   r   )removeprefixreplaceisdigit)rC  s    r-   	is_number'parse_generate_flags.<locals>.is_numberg  s,    NN3yyb!$,,..r0   z, z: {}z"null"z"true"r?  z"false"r@  z"[[z]"rc   r   zFailed to convert `generate_flags` into a valid JSON object.
`generate_flags` = {generate_flags}
Converted JSON string = {generate_flags_string})r   r  r   rk   r   r   rI   rG  ry   r   JSONDecodeErrorr   )r   r"  generate_flags_as_dictkvrI  generate_flags_stringprocessed_generate_flagss           r-   r   r   U  sJ   ^!4!9	
 ^ll]kUYcDJJsOA$66<djjoa>PP]kl
 KaJfJfJhJh$!	%661779A=Jh   KaJfJfJhiJh$!a;A=Jhi/S /T /
 RhQmQmQopQoa11QCq1DQop
 !II?U?[?[?]&^?]tq!Bqc{?]&^_  "77#= 299(FK199(FK199)WM199$D199$D 299#sC
#'::.C#D  $#W m j q
 '_"  
@
 	

s)   7G%2G-G*!G%,G+
<G1 1 Hr   c                      U (       a  SU S./$ / $ )z Returns a new chat conversation.systemr  r   )r   s    r-   r  r    s    =JX-89RPRRr0   r  r   r   c                     [         R                  " [         R                  R                  U 5      SS9  [	        U S5       n[
        R                  " X!S.USS9  SSS5        [         R                  R                  U 5      $ ! , (       d  f       N-= f)z!Saves the chat history to a file.T)exist_okw)r   chat_historyr4   )indentN)r  makedirsr  r:  r   ry   dumpabspath)r  r   r   r   s       r-   r  r    s]    KK)D9	h			x>!L 
77??8$$ 
	s   A??
Bc                      [         R                  " 5       S:X  a  [        R                  " 5       $ [        R
                  " [        R                  " 5       5      R                  $ )z)Returns the username of the current user.r   )platformrU  r  getloginpwdgetpwuidgetuidpw_namer   r0   r-   r   r     s8    I%{{}||BIIK(000r0   __main__z meta-llama/Llama-3.2-3b-Instruct)r&   r*   )Fr   ry   r  r_  rD   stringr?   collections.abcr   r   typingr   r   urllib.parser   r   r   r   r4  r   huggingface_hubr	   r
   transformersr   transformers.utilsr   readliner   rU  ra  richr   rich.consoler   	rich.liver   rich.markdownr   rich.progressr   r   r   r   r   	rich.textr   r   setascii_letters
whitespaceALLOWED_KEY_CHARSdigitsALLOWED_VALUE_CHARSr   rr   rI   r  rs   r$   r   r   r   r  r8  r   r  r  r   r   r   r0   r-   <module>rz     s     	  	   4 ! *     L ) 0	
 ??	!$&``%0$? ,,v/@/@@A 
6==(6+<+<<?bb 
 MN) QRNO./JK?@  	 	 ";;'7'<'<'>?@ A& DZ Zz	CcDj 	C=M 	C3$cT)9 3$d 3$lSC$J S$t* S
% %4: % %# %1c 1 z45 w  		s   F$ $F.-F.