o
    ưiV                     @   s   d dl Z d dlZd dlmZ d dlZd dlmZ er	 dd Zdd Zdej	fd	d
Z
dedefddZdedej	fddZdej	fddZdS )    N)TYPE_CHECKING)verbose_loggerc               
   C   s  zt  j} | dk rtd W n ty/ } ztd|  td W Y d}~nd}~ww d}d}d}d}d	}d
}d}|||d   | }	|||d   | }
tj|ddd}tj|ddd}tjdddd}ttj|	ddd d|d  }t| d| d|  ttj|
ddd tjddd tjd| d| dd zt	 
 }td td W |S  ttfy   td td  w )z/Create a styled blue box prompt for user input.
   z


zError getting terminal size: Nu   ┌u   ┐u   └u   ┘u   ─u   │P      blueT)fgboldz> cyan    z[2AF)nlz[1B )osget_terminal_sizelinesclickecho	Exceptionr   debugstyleinputstripKeyboardInterruptEOFError)terminal_heightetop_left	top_rightbottom_leftbottom_right
horizontalverticalwidthZtop_lineZbottom_lineZleft_borderZright_borderZprompt_textZempty_space
user_input r&   Y/home/app/Keep/.python/lib/python3.10/site-packages/litellm/proxy/client/cli/interface.pystyled_prompt   sL   





r(   c                  C   sD   g d} t d | D ]\}}t d|dd|  qt   dS )zDisplay available commands.))loginz*Authenticate with the LiteLLM proxy server)ZlogoutzClear stored authentication)Zwhoamiz"Show current authentication status)modelsz$Manage and view model configurations)credentialszManage API credentials)Zchatz&Interactive streaming chat with models)httpzMake HTTP requests to the proxy)keyszManage API keys)Zteamsz!Manage teams and team assignments)ZuserszManage users)versionzShow version information)helpzShow this help message)quitzExit the interactive sessionzAvailable commands:z  z<20r   N)r   r   )commandscmddescriptionr&   r&   r'   show_commandsO   s
   
r4   ctxc                 C   s>   ddl m} |  | jd}tjd| ddd t  dS )	z:Set up the interactive shell with banner and initial info.r   show_bannerbase_urlzConnected to LiteLLM server: 
green)r   N)!litellm.proxy.common_utils.bannerr7   objgetr   Zsechor4   )r5   r7   r8   r&   r&   r'   setup_shellg   s
   
r>   r%   returnc                 C   sn   |   dv rtd dS |   dkrtd t  dS |   dkr5t  ddlm} |  t  dS d	S )
zTHandle special commands like exit, help, clear. Returns True if command was handled.exitr0   zGoodbye!Tr/   r   clearr   r6   F)lowerr   r   r4   rB   r;   r7   )r%   r7   r&   r&   r'   handle_special_commandst   s   

rD   c           	   
   C   sZ  |   }|d }t|dkr|dd ng }ddlm} |j}||jvr3td|  td dS z/dg|g | t_	|j| }|
  |j||dd	 W d   W dS 1 s[w   Y  W dS  tjyz } z|  W Y d}~dS d}~w tjy   td
 Y dS  ty   Y dS  ty } ztd|  W Y d}~dS d}~ww )zParse and execute a command.r      N)mainzUnknown command: z&Type 'help' to see available commands.zlitellm-proxyF)parentZstandalone_modezCommand aborted.zError executing command: )splitlenr   rF   clir1   r   r   sysargvscopeZClickExceptionshowZAbort
SystemExitr   )	r%   r5   partscommandargsrF   rJ   r2   r   r&   r&   r'   execute_command   s<   



&rS   c              
   C   s   t |  	 z"td t }|sW qt|r!| dv rW dS W qt||  W n* ttfy8   td Y dS  t	yQ } ztd|  W Y d}~nd}~ww q)zRun the interactive shell.Tr9   r@   z	
Goodbye!zError: N)
r>   r   r   r(   rD   rC   rS   r   r   r   )r5   r%   r   r&   r&   r'   interactive_shell   s(   

rT   )r   rK   typingr   r   Zlitellm._loggingr   r(   r4   Contextr>   strboolrD   rS   rT   r&   r&   r&   r'   <module>   s   @,