
    eay                    p   d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	m
Z
mZmZmZmZ ddlmZ ddlmZmZmZ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m Z  d	dl!m"Z" d	dl#m$Z$ d	dl%m&Z& d	dl'm(Z( ddl)m*Z* erddl+m,Z, ddl-m.Z. ddl/m0Z0 dZ1dZ2dZ3dZ4dZ5dZ6dZ7i de1de1de1d e1d!e1d"e1d#e2d$e2d%e2d&e2d'e2d(e2d)e2d*e3d+e4d,e4d-di d.d/d0d1d2d3d4d5d6d7d8d9d:e5d;e5d<e6d=e6d>e6d?d@dAdBdCdDdEdFdGe7dHe7dIdJdKZ8dLZ9 G dM dNe          Z: G dO dPe;          Z< G dQ dRe           Z=dS )Sz}
The feed module provides a high-level API for interacting
with a list of `ChatMessage` objects through the backend methods.
    )annotationsN)Enum)partial)
isasyncgenisasyncgenfunctionisawaitableiscoroutinefunctionisgenerator)BytesIO)TYPE_CHECKINGAnyCallableClassVarDictListLiteral   )Margin)CDN_DIST)Column	ListPanel)Card)VSpacer)SVG)Button   )ChatMessage)Document)Model)Commu   🧑u   🤖u   ⚙️u   ❌zuhttps://upload.wikimedia.org/wikipedia/commons/thumb/0/04/ChatGPT_logo.svg/1024px-ChatGPT_logo.svg.png?20230318122128z=https://upload.wikimedia.org/wikipedia/commons/a/a4/GPT-4.pngzvhttps://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/WolframCorporateLogo.svg/1920px-WolframCorporateLogo.svg.pngclientcustomeremployeehumanpersonuseragentai	assistantbotchatbotmachinerobotsystem	exceptionerroradultbabyu   👶boyu   👦childu   🧒girlu   👧manu   👨womanu   👩chatgptgpt3gpt4dalleopenaihuggingfaceu   🤗
calculatoru   🧮	langchainu   🦜
translatoru   🌐wolframzwolfram alphau   🦙u   🐪)llamallama2a  
    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-loader-3" width="40" height="40" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
        <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
        <path d="M3 12a9 9 0 0 0 9 9a9 9 0 0 0 9 -9a9 9 0 0 0 -9 -9"></path>
        <path d="M17 12a5 5 0 1 0 -5 5"></path>
    </svg>
c                  "    e Zd ZdZdZdZdZdZdS )CallbackStateidlerunning
generatingstoppingstoppedN)__name__
__module____qualname__IDLERUNNING
GENERATINGSTOPPINGSTOPPED     /lib/python3.11/site-packages/panel/chat/feed.pyrE   rE   d   s'        DGJHGGGrT   rE   c                      e Zd ZdS )StopCallbackN)rK   rL   rM   rS   rT   rU   rW   rW   l   s        DrT   rW   c                  h    e Zd ZU dZ ej        ddd          Z ej        dd          Z ej	        d	g d
d          Z
 ej        dd          Z ej        i d          Z ej        ddd          Z ej        dd          Z ej        i d          Z ej        d          Z edd          Z ej        g d          Z ej        dd          Z ej        ddd          Z ej        d          Z ej        d dd!          Z ej        dd"          Z ej        dd#          Z  ej!        e"dd$%          Z# ej	         e$e%          d&'          Z& ej        dd(          Z'e( d)gZ)d*e*d+<    fd,Z+	 	 d{d|d7Z,d}d>Z-d~d fd?Z. ej/        d@dA          dB             Z0 ej/        dCddD          dE             Z1d~ddHZ2	 	 dddOZ3	 d~ddQZ4ddSZ5ddUZ6ddZZ7d[ Z8dd\Z9d] Z:	 	 	 dddaZ;	 	 	 d{ddcZ<dd Z=ddeZ>dddhZ?ddiZ@	 	 	 dddsZA	 	 	 dddyZBd~dzZC xZDS )ChatFeedu  
    A widget to display a list of `ChatMessage` objects and interact with them.

    This widget provides methods to:
    - Send (append) messages to the chat log.
    - Stream tokens to the latest `ChatMessage` in the chat log.
    - Execute callbacks when a user sends a message.
    - Undo a number of sent `ChatMessage` objects.
    - Clear the chat log of all `ChatMessage` objects.

    Reference: https://panel.holoviz.org/reference/chat/ChatFeed.html

    :Example:

    >>> async def say_welcome(contents, user, instance):
    >>>    yield "Welcome!"
    >>>    yield "Glad you're here!"

    >>> chat_feed = ChatFeed(callback=say_welcome, header="Welcome Feed")
    >>> chat_feed.send("Hello World!", user="New User", avatar="😊")
       )r   Nz
        Max pixel distance from the latest object in the Column to
        activate automatic scrolling upon update. Setting to 0
        disables auto-scrolling.)defaultboundsdocFz
        Callback to execute when a user sends a message or
        when `respond` is called. The signature must include
        the previous message value `contents`, the previous `user` name,
        and the component `instance`.)
allow_refsr]   summary)raiser_   verboseignorea/  
        How to handle exceptions raised by the callback.
        If "raise", the exception will be raised.
        If "summary", a summary will be sent to the chat feed.
        If "verbose", the full traceback will be sent to the chat feed.
        If "ignore", the exception will be ignored.
        )r[   objectsr]   	AssistantzO
        The default user name to use for the message provided by the callback.)r[   r]   zY
        Params to pass to Card, like `header`, `header_background`, `header_color`, etc.Tz?
        Whether the Card should be expandable and collapsible.)r[   readonlyr]   z%
       Whether the feed is disabled.z
        Params to pass to each ChatMessage, like `reaction_icons`, `timestamp_format`,
        `show_avatar`, `show_user`, and `show_timestamp`. Params passed
        that are not ChatFeed params will be forwarded into `message_params`.zl
        The header of the chat feed; commonly used for the title.
        Can be a string, pane, or widget.)r]      z
        Allows to create additional space around the component. May
        be specified as a two-tuple of the form (vertical, horizontal)
        or a four-tuple (top, right, bottom, left).z;
        The list of child objects that make up the layout. z]
        If placeholder is the default LoadingSpinner the text to display
        next to it.r   z
        Min duration in seconds of buffering before displaying the placeholder.
        If 0, the placeholder will be disabled.a)  
        A callable or list of callables that accept the value and return a
        Panel object to render the value. If a list is provided, will
        attempt to use the first renderer that does not raise an
        exception. If None, will attempt to infer the renderer
        from the value.d   z
        Min pixel distance from the latest object in the Column to
        display the scroll button. Setting to 0
        disables the scroll button.zj
        Whether to show an activity dot on the ChatMessage while
        streaming the callback response.zu
        Whether to scroll to the latest object on init. If not
        enabled the view will be on the first object.z~
        The placeholder wrapped in a ChatMessage object;
        primarily to prevent recursion error in _update_placeholder.)class_r^   r]   z+
        The current state of the callback.)rc   r]   z1
        The previous disabled state of the feed.zcss/chat_feed.csszClassVar[List[str]]_stylesheetsc                   d | _         |                    d          r't          |d         t                    s|d         g|d<   |                    d          |                    d          d|d<   |                    di           }t          |                                          D ]6}|t
          j        vr&|t          j        v r|                    |          ||<   7||d<    t                      j
        |i | t          | j        j        | j        j        | j        j        | j        j        | j        j        | j        j                  }t%          || j        | j        dg| j        d|| _        |                                }| j        | j        j                                        z   | j        j                                                            d	g           z   }|                    | j        j        | j        j        | j        | j        j        | j        j                                        j                             d
          ddg| j        j!                                        z   dg| j        j"        | j        j#        dgddi|           | j                                        }|                    d	d            |                    |           | $                    | j        dd           tK          | j        tM                      fi || _'        tQ          d          | _)        | j)        *                    | j+                   d S )N	rendererswidthsizing_modestretch_widthmessage_params)designrn   rm   	max_width	min_widthvisiblezchat-feed-log)auto_scroll_limitscroll_button_thresholdcss_classesstylesheetsrx   )Nrg   Fz	chat-feedzchat-feed-headerzchat-feed-titlepadding0px)marginalignheaderheighthide_headercollapsiblerw   header_css_classes
max_height
min_heighttitle_css_classesstylesrx   rc   T)rc   bidirectional)rt   ),_callback_futureget
isinstancelistkeysrY   paramr   popsuper__init__dictrq   rn   rm   rr   rs   rt   r   ru   rv   rj   	_chat_logcopyrx   rxcard_paramsupdater{   r|   r}   r~   in_rw   r   r   linkr   r   _cardr   _callback_triggeron_click_prepare_response)
selfrc   paramsrp   	param_keylinked_paramsr   card_stylesheetscard_overrides	__class__s
            rU   r   zChatFeed.__init__   sG    $::k"" 	8:f[6I4+P+P 	8#)+#6"7F;::g&6::m+D+D+L$3F=!  $4b99fkkmm,, 	B 	BI..9@Q3Q3Q,2JJy,A,Ay)#1 ',V,,, :$
.*"j*j*J&
 
 
  "4$($@())
 
 
 
 $((**J"%%''(J"%%''++M2>>? 	
 	:$*";:$
),,..155jAA$
(>(A(A(C(CC 23z,z,01u%( 	 	
 	
 	
 )..00=$///>***		$.)4	HHHNII
 
 
 

 "(!6!6!6''(>?????rT   Nr]   r   rootModel | NoneparentcommComm | Nonereturnr   c                v    | j                             ||||          }|p|j        d         }||f| j        |<   |S )Nid)r   
_get_modelref_models)r   r]   r   r   r   modelr   s          rU   r   zChatFeed._get_model'  sE     
%%c4>>}u!$'"FOSrT   events$Dict[str, param.parameterized.Event]msgDict[str, Any]r   Nonec                    d S NrS   )r   r   r   r   r   r]   r   s          rU   _update_modelzChatFeed._update_model0  s	     	rT   c                ~    | j                             |           t                                          |           d S r   )r   _cleanupr   )r   r   r   s     rU   r   zChatFeed._cleanup6  s7    
D!!!rT   r   )watchc                    | j                                         }|                    dd             | j        j        j        di | d S )Nrx   rS   )r   r   r   r   r   r   )r   r   s     rU   _update_card_paramszChatFeed._update_card_params:  sN    &++--t,,,
..+.....rT   placeholder_text)r   on_initc                    | j         '| j         j                            | j                   d S t	          t
          d dg          }t          | j        dd|i d          | _         d S )N)objectzrotating-placeholder)rn   rw    F)r&   show_timestampavatarreaction_iconsshow_copy_icon)_placeholderr   r   r   r   PLACEHOLDER_SVGr   )r   loading_avatars     rU   _update_placeholderzChatFeed._update_placeholder@  s    (#**$2G*HHHF<R;S
 
 
 (! ! 
 
 
rT   messageChatMessage | Nonec                    d}| j         dk    r,	 |                     | j                  }n# t          $ r Y nw xY w|)||| |<   dS ||                     | j                   dS dS ||                     |           dS dS )z
        Replace the placeholder from the chat log with the message
        if placeholder, otherwise simply append the message.
        Replacing helps lessen the chat log jumping around.
        Nr   )placeholder_thresholdindexr   
ValueErrorremoveappend)r   r   r   s      rU   _replace_placeholderzChatFeed._replace_placeholderR  s     %))

4#455    "%UD-..... ! KK      ! s   * 
77valuer   r&   
str | Noner   str | bytes | BytesIO | Nonec                H   d|v rd|v rt          d|          d|v r|                    d          |d<   nd|vrt          d|          t          |fd| j        i| j        }|r||d<   |r||d<   | j        rt          | j        dz
            |d	<   t          d
i |}|S )z6
        Builds a ChatMessage from the value.
        r   r   z4Cannot pass both 'value' and 'object' together; got z[If 'value' is a dict, it must contain an 'object' key, e.g. {'object': 'Hello World'}; got rl   r&   r   P   rm   rS   )r   r   r   rl   rp   rm   intr   )r   r   r&   r   rp   r   s         rU   _build_messagezChatFeed._build_messageg  s    eE 1 1]TY]]^^^#ii00E(OOU""C9>C C   eUUt~UATUU 	*%)N6" 	.'-N8$: 	;&)$*r/&:&:N7#////rT   r   c                   | j         t          j        k    }| j        duo| j                                        }|dS |s|rt          d          | j        }d}t          |t                    r+|	                    d|          }|	                    d          }|Dt          |t                    r|j        }|j        }|j        }|                    |||           |S t          |t                    r|                     |           |S t          |t                    sd|i}|                     |||          }|                     |           |S )z|
        Replace the placeholder message with the response or update
        the message's value with the response.
        NCallback was stopped.r&   r   r&   r   r   )_callback_staterE   rQ   r   	cancelledrW   callback_userr   r   r   r   r&   r   r   r   r   r   )r   r   r   is_stopping
is_stoppedr&   r   new_messages           rU   _upsert_messagezChatFeed._upsert_message  si    *m.DD*$6\4;P;Z;Z;\;\
=F 	8J 	86777!eT"" 	)99VT**DYYx((F%-- % zNN5tFN;;;N{++ 	%%e,,,L %&& 	&u%E))%d6)JJ!!+...rT   r   c                    |j         }t          |d          r|j        }n2t          |d          r|j        }nt          |d          r|j        }n|}||j        | fS )zH
        Extracts the contents from the message's panel object.
        r   rc   r   )_object_panelhasattrr   rc   r   r&   )r   r   r   contentss       rU   _gather_callback_argszChatFeed._gather_callback_args  sq     %5(## 	|HHUI&& 	}HHUG$$ 	{HHHt++rT   responsec                  K   d}	 t          |          r?t          j        | _        |2 3 d{V }|                     ||          }| j        |_        *6 nt          |          r9t          j        | _        |D ]$}|                     ||          }| j        |_        %nBt          |          r|                     | d{V |          }n|                     ||          }|rd|_        n# |rd|_        w xY w|S )zh
        Serializes the response by iterating over it and
        updating the message's value.
        NF)r   rE   rP   r   r   show_activity_dotr
   r   )r   r   response_messagetokens       rU   _serialize_responsezChatFeed._serialize_response  sn     
  	;(## T'4'?$#+ P P P P P P P%'+';';ECS'T'T$9=9O$66 $,8 X&& T'4'?$% P PE'+';';ECS'T'T$9=9O$66P X&& T#'#7#7hHX#Y#Y  #'#7#7BR#S#S  ;5: 2   ;5: 2::::s   "C( AB0C( (C3taskasyncio.Tasknum_entriesr   c                  K   | j         dk    rdS t          j                                                    }|                                s|t          | j                  k    rt          j                                                    |z
  }|| j         k    r|                     | j                   dS t          j	        d           d{V  |                                s|t          | j                  k    dS dS dS dS )z
        Schedules the placeholder to be added to the chat log
        if the callback takes longer than the placeholder threshold.
        r   Ng?)
r   asyncioget_event_looptimedonelenr   r   r   sleep)r   r   r   startdurations        rU   _schedule_placeholderzChatFeed._schedule_placeholder  s      %**F&((--//))++ 	%+T^1D1D"D"D-//4466>H$444D-...-$$$$$$$$$ ))++ 	%+T^1D1D"D"D"D"D 	% 	%"D"D 	% 	%rT   c                J  K   |                      |          }t          | j                  r | j        |  d {V }nKt          | j                  r | j        | }n,|                    d t          | j        g|R             d {V }|                     |           d {V  d S r   )r   r	   callbackr   run_in_executorr   r   )r   r   loopcallback_argsr   s        rU   _handle_callbackzChatFeed._handle_callback  s      227;;t}-- 	*T]M:::::::HH.. 	$t}m4HH!11gdm<m<<<       H &&x00000000000rT   c                N  K   | j         dS | j        | _        	 t          j                            |           5  d| _        t          j        | _        ddd           n# 1 swxY w Y   | j	        d         }t          |t                    s	 |                                  d{V  dS t          | j	                  }t          j                    }|                    |                     ||                    }|| _        t          j        |                     ||          |           d{V  n# t*          $ r t          j        | _        Y nt.          $ r}t1          dd          }| j        dk    r | j        d|d	fi | n\| j        d
k    r$ | j        dt7          j                     dfi | n-| j        dk    r Y d}~|                                  d{V  dS |Y d}~nd}~ww xY w|                                  d{V  dS # |                                  d{V  w xY w)zi
        Prepares the response by scheduling the placeholder and
        executing the callback.
        NT	ExceptionF)r&   respondr_   zEncountered `z@`. Set `callback_exception='verbose'` to see the full traceback.ra   z
```python
z
```rb   )r   disabled_was_disabledr   parameterizedbatch_call_watchersrE   rO   r   r   r   r   _cleanup_responser   r   r   create_taskr   r   gatherr   rW   rR   r  r   callback_exceptionsend	traceback
format_exc)r   _r   r   r   futureesend_kwargss           rU   r   zChatFeed._prepare_response  s     
 = F!]"	+$88>> = = $'4'<$= = = = = = = = = = = = = = = nR(Gg{33 6 ((***********3 dn--K)++D%%d&;&;GT&J&JKKF$*D!.**6;??           	9 	9 	9#0#8D    	 	 	K???K&)33	UA U U U  "   
 (I55	E	(<(>(>EEEUUUUUU(H44 ((*********** 	 ((***********$((**********sr   D. AD. A!!D. $A!%%D. 'BD. -H .G)	H 	G)A)G$=H G$H $G))H H$c                   K   t           j                            |           5  |                     d           t          j        | _        | j        | _        ddd           dS # 1 swxY w Y   dS )zF
        Events to always execute after the callback is done.
        N)	r   r  r  r   rE   rN   r   r  r  r   s    rU   r	  zChatFeed._cleanup_response%  s        44T:: 	/ 	/%%d+++#0#5D  .DM	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   3A""A&)A&ChatMessage | dict | Anyr  boolc                   t          |t                    r||t          d          |}n1t          |t                    sd|i}|                     |||          }|                     |           |r|                                  |S )a  
        Sends a value and creates a new message in the chat log.

        If `respond` is `True`, additionally executes the callback, if provided.

        Arguments
        ---------
        value : ChatMessage | dict | Any
            The message contents to send.
        user : str | None
            The user to send as; overrides the message message's user if provided.
        avatar : str | bytes | BytesIO | None
            The avatar to use; overrides the message message's avatar if provided.
        respond : bool
            Whether to execute the callback.

        Returns
        -------
        The message that was created.
        NzfCannot set user or avatar when explicitly sending a ChatMessage. Set them directly on the ChatMessage.r   r   )r   r   r   r   r   r   r  )r   r   r&   r   r  r   s         rU   r  zChatFeed.send0  s    6 e[)) 
	K6#5 K   GGeT** *!5)))%d6)JJGG 	LLNNNrT   strc                0   | j         (| j                                         rt          d          t          |t                    r||t          d          |r^t          |t          t          f          r(|                    |           |r||_	        |r||_
        n|                    |||           |S t          |t                    r|}n1t          |t                    sd|i}|                     |||          }|                     |           |S )a  
        Streams a token and updates the provided message, if provided.
        Otherwise creates a new message in the chat log, so be sure the
        returned message is passed back into the method, e.g.
        `message = chat.stream(token, message=message)`.

        This method is primarily for outputs that are not generators--
        notably LangChain. For most cases, use the send method instead.

        Arguments
        ---------
        value : str | dict | ChatMessage
            The new token value to stream.
        user : str | None
            The user to stream as; overrides the message's user if provided.
        avatar : str | bytes | BytesIO | None
            The avatar to use; overrides the message's avatar if provided.
        message : ChatMessage | None
            The message to update.

        Returns
        -------
        The message that was updated.
        Nr   zhCannot set user or avatar when explicitly streaming a ChatMessage. Set them directly on the ChatMessage.r   r   )r   r   rW   r   r   r   r  r   streamr&   r   r   r   r   )r   r   r&   r   r   s        rU   r  zChatFeed.stream[  s<   >  ,1F1P1P1R1R,6777e[)) 	t/?6CUG    		%#t-- @u%%% (#'GL ,%+GNu4???Ne[)) 	KGGeT** *!5)))%d6)JJG!!'***rT   c                D    | j         j                            d           dS )zP
        Executes the callback with the latest message in the chat log.
        clicksN)r   r   triggerr  s    rU   r  zChatFeed.respond  s$     	$,,X66666rT   c                    | j         d}nB| j        t          j        k    rt          j        | _        d}n| j                                         }|r!| j        | _        |                     d           |S )z
        Cancels the current callback task if possible.

        Returns
        -------
        Whether the task was successfully stopped or done.
        NFT)	r   r   rE   rP   rQ   cancelr  r  r   )r   r   s     rU   stopzChatFeed.stop  sy      (II!]%=== $1#9D II-4466I 	, .DM%%d+++rT   count	List[Any]c                d    |dk    rg S | j         j        }|| d         }|d|          | dd<   |S )a,  
        Removes the last `count` of messages from the chat log and returns them.

        Parameters
        ----------
        count : int
            The number of messages to remove, starting from the last message.

        Returns
        -------
        The messages that were removed.
        r   N)r   rc   )r   r"  messagesundone_entriess       rU   undozChatFeed.undo  sJ     A::I>)!5&''*7UF7#QQQrT   c                P    | j         j        }| j                                          |S )z
        Clears the chat log and returns the messages that were cleared.

        Returns
        -------
        The messages that were cleared.
        )r   rc   clear)r   cleared_entriess     rU   r)  zChatFeed.clear  s(     .0rT   r)   r%  List[ChatMessage]
role_names!Dict[str, str | List[str]] | Nonedefault_rolecustom_serializerr   List[Dict[str, Any]]c                N   |dg| j         gd}i }|                                D ]9\  }}t          |t                    r|g}|D ]}|||                                <   :g }	|D ]}
|
j                                        }||vr|st          d|
j        d|d          |                    ||          }|rF ||
j                  }t          |t                    s t          dt          |           d          nt          |
          }|	
                    ||d	           |	S )
zA
        Exports the chat log for use with transformers.
        Nr&   )r&   r)   zUser z not found in role_names; got .zCThe provided custom_serializer must return a string; it returned a z type)rolecontent)r   itemsr   r  lowerr&   r   r   r   typer   )r   r%  r,  r.  r/  
names_roler3  namesnameserialized_messagesr   lowercase_namer4  s                rU   _serialize_for_transformersz$ChatFeed._serialize_for_transformers  s    "01 J
 
%++-- 	0 	0KD% %%%   0 0+/
4::<<((0 ! 	K 	KG$\//11NZ/// +GL + +%+ + +  
 >>.,??D  '++GN;;!'3// $>)-g> > >   g,,&&'I'IJJJJ""rT   transformers	filter_byCallable | NoneformatLiteral['transformers']c                    | j         j                                        }| ||          }|dk    r | j        |fd|i|S t	          d|d          )a  
        Exports the chat log.

        Arguments
        ---------
        format : str
            The format to export the chat log as; currently only
            supports "transformers".
        filter_by : callable
            A function to filter the chat log by.
            The function must accept and return a list of ChatMessage objects.
        custom_serializer : callable
            A custom function to format the ChatMessage's object. The function must
            accept one positional argument, the ChatMessage object, and return a string.
            If not provided, uses the serialize method on ChatMessage.
        **serialize_kwargs
            Additional keyword arguments to use for the specified format.

            - format="transformers"
              role_names : dict(str, str | list(str)) | None
                  A dictionary mapping the role to the ChatMessage's user name.
                  Defaults to `{"user": ["user"], "assistant": [self.callback_user]}`
                  if not set. The keys and values are case insensitive as the strings
                  will all be lowercased. The values can be a string or a list of strings,
                  e.g. `{"user": "user", "assistant": ["executor", "langchain"]}`.
              default_role : str
                  The default role to use if the user name is not found in role_names.
                  If this is set to None, raises a ValueError if the user name is not found.

        Returns
        -------
        The chat log serialized in the specified format.
        Nr>  r/  zFormat z is not supported.)r   rc   r   r=  NotImplementedError)r   r?  rA  r/  serialize_kwargsr%  s         rU   	serializezChatFeed.serialize  s    P >)..00  y**H^##343 ,=AQ   ""HF"H"H"HIIIrT   c                   g }|Tt          |t                    rt          | |          s/t          |          r5t          |t                    s  ||           r|                    |            || j                            |          z   S )a  
        Iterates over the ChatInterface and any potential children in the
        applying the selector.

        Arguments
        ---------
        selector: type or callable or None
          The selector allows selecting a subset of Viewables by
          declaring a type or callable function to filter by.

        Returns
        -------
        viewables: list(Viewable)
        )r   r7  callabler   r   select)r   selectorselecteds      rU   rI  zChatFeed.select8  s     $'' ,6tX,F,F h (28T(B(B GOxPT~~  OOD!!!$*++H5555rT   )NNN)
r]   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r]   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   )NN)r   r   r&   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   r   r   )r   r   )NNT)
r   r  r&   r   r   r   r  r  r   r   )
r   r  r&   r   r   r   r   r   r   r   )r   r  )r   )r"  r   r   r#  )r   r#  )Nr)   N)
r%  r+  r,  r-  r.  r   r/  r   r   r0  )Nr>  N)r?  r@  rA  rB  r/  r@  )ErK   rL   rM   __doc__r   Integerru   r   r   ObjectSelectorr  Stringr   r   r   Booleanr   r  rp   	Parameterr}   r   r{   r   rc   r   Numberr   HookListrl   rv   r   view_latestClassSelectorr   r   r   rE   r   r  r   rj   __annotations__r   r   r   r   dependsr   r   r   r   r   r   r   r   r   r   r	  r  r  r  r!  r'  r)  r=  rF  rI  __classcell__)r   s   @rU   rY   rY   p   s         , &c) J$ & & &
 u~ 5) * * *H .-#L#L#L S   !EL ;R S S SM %*R .\ ] ] ]K  %- CB C C CK u}U 1( ) ) )H  UZ 1Q R R RN
 U_ "- . . .F VA $7 8 8 8F
 ej *> ? ? ?G $u|B 5    )EL9 K3 4 4 4  $   I ,emC	 O' ( ( (
 &d 9, - - -  %- 39 : : :K '5&ke RH I I IL +e*443F3F M. / / /O "EM% 64 5 5 5M -5)G)G)G(HLHHHHE@ E@ E@ E@ E@P 379=              U]=---/ / .-/
 U]%T4@@@
 
 A@
"! ! ! ! !0  /3	    < 9=) ) ) ) )V, , , ,       4% % % %(
1 
1 
1++ ++ ++ ++Z/ / /  /3) ) ) ) )\  /3&*9 9 9 9 9v7 7 7   0    (
 
 
 
 9=#.&*0# 0# 0# 0# 0#h &**8-1	0J 0J 0J 0J 0Jd6 6 6 6 6 6 6 6rT   rY   )>rL  
__future__r   r   r  enumr   	functoolsr   inspectr   r   r   r	   r
   ior   typingr   r   r   r   r   r   r   r   _paramr   io.resourcesr   layoutr   r   layout.cardr   layout.spacerr   
pane.imager   widgets.buttonr   r   r   bokeh.documentr   bokeh.modelr   pyviz_commsr    	USER_LOGOASSISTANT_LOGOSYSTEM_LOGO
ERROR_LOGO
GPT_3_LOGO
GPT_4_LOGOWOLFRAM_LOGODEFAULT_AVATARSr   rE   r  rW   rY   rS   rT   rU   <module>rq     s   
 # " " " " "                                                             # # # # # # & & & & & & & &       # # # # # #       # # # # # #             !''''''!!!!!!      	
 E
L
 H+i+ 	+ 		+
 Y+ i+ I+ ^+ 	.+ + 
>+ ~+ ~+ ^+" k#+$ %+& Z'+* V++ +, F-+. 
6/+0 V1+2 F3+4 
65+6 V7+: z;+< J=+> J?+@ ZA+B jC+D 6E+F &G+H I+J &K+L |M+N \O+ +R U+ + +Z    D   	 	 	 	 	9 	 	 	\6 \6 \6 \6 \6y \6 \6 \6 \6 \6rT   