File tree Expand file tree Collapse file tree 5 files changed +148
-205
lines changed 
components/display-messages/chat Expand file tree Collapse file tree 5 files changed +148
-205
lines changed Original file line number Diff line number Diff line change @@ -13,9 +13,9 @@ def server(input):
1313
1414    # Define a callback to run when the user submits a message 
1515    @chat .on_user_submit   # <<  
16-     async  def  handle_user_input ( user_input :  str ):  # << 
16+     async  def  _ ( ):  # << 
1717        # Simply echo the user's input back to them 
18-         await  chat .append_message (f"You said: { user_input }  )  # << 
18+         await  chat .append_message (f"You said: { chat . user_input () }  )  # << 
1919
2020
2121app  =  App (app_ui , server )
Original file line number Diff line number Diff line change 1313
1414# Define a callback to run when the user submits a message 
1515@chat .on_user_submit   # <<  
16- async  def  handle_user_input ( user_input :  str ):  # << 
16+ async  def  _ ( ):  # << 
1717    # Simply echo the user's input back to them 
18-     await  chat .append_message (f"You said: { user_input }  )  # << 
18+     await  chat .append_message (f"You said: { chat . user_input () }  )  # << 
Original file line number Diff line number Diff line change 1414
1515# Define a callback to run when the user submits a message 
1616@chat .on_user_submit  
17- async  def  handle_user_input ( user_input :  str ):
17+ async  def  _ ( ):
1818    # Append a response to the chat 
19-     await  chat .append_message (f"You said: { user_input }  )
19+     await  chat .append_message (f"You said: { chat . user_input () }  )
Original file line number Diff line number Diff line change 1212    """ 
1313    Hi! This is a simple Shiny `Chat` UI. Enter a message below and I will 
1414    simply repeat it back to you. For more examples, see this 
15-     [folder of examples](https://github.com/posit-dev/py-shiny/tree/main/shiny/templates /chat). 
15+     [folder of examples](https://github.com/posit-dev/py-shiny/tree/main/examples /chat). 
1616    """ 
1717)
1818
2828
2929# Define a callback to run when the user submits a message 
3030@chat .on_user_submit  
31- async  def  handle_user_input (user_input : str ):
31+ async  def  _ ():
32+     # Get the chat messages. 
33+     messages  =  chat .messages ()
34+     # Typically you'd pass messages to an LLM for response generation, 
35+     # but for this example, we'll just echo the user's input 
36+     user  =  messages [- 1 ]["content" ]
3237    # Append a response to the chat 
33-     await  chat .append_message (f"You said: { user_input }  )
38+     await  chat .append_message (f"You said: { user }  )
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments