
    ;3h9                        d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	 d dl
Z
d dlmZ ddlmZ ddlmZ  e
j"                  dd	
      Z e
j"                  ddd      Zej)                  ed       ddedefdZde	e   ddfdZej1                          e
j2                  ddd      fde	e   fd       Zedk(  r e        yy)    N)partial)AnyDictListOptional)print   )Agent)_load_agent_configrichziA squad of lightweight composable AI applications built on Hugging Face's Inference Client and MCP stack.)rich_markup_modehelprunzRun the Agent in the CLIT)namer   invoke_without_command)r   promptreturnc                    K   t        j                         }|j                  d t        t        j
                  | d             d {   S 7 w)N )prompt_suffix)asyncioget_running_looprun_in_executorr   typerr   )r   loops     b/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/huggingface_hub/inference/_mcp/cli.py_ainputr      s;     ##%D%%dGELL&X[,\]]]]s   AAAA
agent_pathc                 D  K   t        |       \  }}|j                  dg       }t        j                         dt        j                         }t        j                  t
        j                        }dfd}	 |j                  t
        j                  |       t        |d   |d   ||      4 d{   }|j                          d{    t        dt        |j                         d	       |j                  D ]%  }t        d
|j                  j                   d       ' 	 j!                          	 t#                d{   }	d	 |j+                  |	      2 3 d{   }
j)                         rs n8t-        |
d      r|
j.                  d   j0                  }|j2                  rt        |j2                  dd       |j4                  st|j4                  D ]  }|j6                  rt        d|j6                   dd       |j                  j                  r"t        |j                  j                   d       |j                  j8                  syt        |j                  j8                   d        t        d|
j                   d|
j:                   d|
j2                   dd       Vt                7 7 7 # t$        $ r t        dd       Y n^t&        $ r% sj)                         rY t        dd       Y n2w xY w7 6 b# t<        $ r}t        d| dd       dY d}~yd}~ww xY wddd      d{  7   n# 1 d{  7  sw Y   nxY w|r0|j?                         s |jA                  t
        j                         y|r%t        j
                  t
        j                  |       yy# |r0|j?                         s |jA                  t
        j                         w |r%t        j
                  t
        j                  |       w w xY ww)z
    Tiny Agent loop.

    Args:
        agent_path (`str`, *optional*):
            Path to a local folder containing an `agent.json` and optionally a custom `PROMPT.md` file or a built-in agent stored in a Hugging Face dataset.

    serversTNc                      r d j                          t        dd       y t        dd       t        j                  d       y )NFz4
[red]Interrupted. Press Ctrl+C again to quit.[/red]Tflushz
[red]Exiting...[/red]   )setr   os_exit)abort_eventfirst_sigints   r   _sigint_handlerz"run_agent.<locals>._sigint_handler5   s:     LOOIQUV't4
    providermodel)r,   r-   r    r   z[bold blue]Agent loaded with z tools:[/bold blue]u   [blue] • z[/blue]z"
[red]EOF received, exiting.[/red]r"   z7
[red]Keyboard interrupt during input processing.[/red])r(   choicesr    )endr#   z<Tool >)r0   r   z

[green]Tool[z] 
z	[/green]
z#
[bold red]Error during agent run: [/bold red])r   N)!r   getr   Eventr   signal	getsignalSIGINTadd_signal_handlerr
   
load_toolsr   lenavailable_toolsfunctionr   clearr   EOFErrorKeyboardInterruptis_setr   hasattrr.   deltacontent
tool_callsid	argumentstool_call_id	Exception	is_closedremove_signal_handler)r   configr   r    r   original_sigint_handlerr*   agentt
user_inputchunkrC   caller(   r)   s                 @@r   	run_agentrT       s|     (
3NFF$*JJy"$=G--/KL##%D$..v}}=
?B?J'/	
 6	( 6	(
 ""$$$1#e6K6K2L1MM`ab** >AJJOO#4G<=> !!#'.yJ#'L(',yyy'U  e&--/!"5)4$)MM!$4$:$:E$}} %emm4 H$//,1,<,< !TD'+ww(-twwiq.Ar(J'+}}'9'9(-1C1C0D3(O'+}}'>'>(-1H1H0IPR(S!T ""25::,bASAS@TTVW\WdWdVeeo p&*
 GO 6	( % "1 ?tL( 'K,>,>,@ X`de'U0 ! (@;OW[\#'L(i6	( 6	( 6	( 6	( 6	(r (&&v}}5$MM&--)@A % (&&v}}5$MM&--)@A %s  A5P :9O 3K4O 7MKA+M8KKKL L$L%L(A+LBLA'L MO MKL!M#L=M LMLMLL	L>!L94M9L>>MO MO M%MM%!O (AP APP zPath to a local folder containing an agent.json file or a built-in agent stored in the 'tiny-agents/tiny-agents' Hugging Face dataset (https://huggingface.co/datasets/tiny-agents/tiny-agents)F)r   show_defaultpathc                     	 t        j                  t        |              y # t        $ r$ t	        dd       t        j                  d      t        $ r}t	        d| dd       |d }~ww xY w)Nz8
[red]Application terminated by KeyboardInterrupt.[/red]Tr"   r$   )codez)
[bold red]An unexpected error occurred: r3   )r   r   rT   r@   r   r   ExitrI   )rV   rS   s     r   r   r      sd    IdO$ #IQUVjjc"" :1#[IQUVs   ! 4A-A((A-__main__)u   » )r   r&   r6   	functoolsr   typingr   r   r   r   r   r   r   rN   r
   utilsr   Typerapprun_cli	add_typerstrr   rT   callbackArgumentr   __name__ r+   r   <module>rg      s     	   , ,    % ekk	t
 %++		#
 gE "^# ^# ^
`B`B	`BF 	(%..H 
3- * zE r+   