Uplink functions only work intermittently

I am trying to display the contents of an LLM call to a label component. I noticed that even when the click event is getting registered ,sometimes the display(output of the function) is empty.

My click event looks like this

Code Sample:

def extract_file_content_click(self, **event_args):
      print("extract_file_content_click triggered!")
  
      selected_file_id = self.dropdown_files.selected_value
      print(f"Selected File ID: {selected_file_id}")
  
      user_query= self.user_query.text
      print(f"User Query: {user_query}") 
      
      #self.llm_output.text = anvil.server.call('ping')
      self.llm_output.text = anvil.server.call('get_file_content', selected_file_id, user_query)

When the uplink server function is like the folloiwng,

@anvil.server.callable
    def ping():
    return 'pong

it works. but even when I complicate it a little bit like the following:

@anvil.server.callable
def get_file_content(file_id, user_query):
    return f"function executed"

The output of the function only work intermittently. For example, for 3 straight clicks it wont show anything, and on the 4th try, the label component will show “function executed”. I am using firefox in debug mode (new tab) for testing.

Any guidance on how to even begin to troubleshoot this is much appreciated.

I haven’t heard of behavior like that before. If you share your entire uplink script (except your uplink key), that may help us help you.

One thing to understand (just in case) is that there’s a nontrivial latency for any type of server call. Could it be that you are clicking four times in quick succession, and that the label output you see is actually from the first click?

To help debug, you might print or log the server call output rather than change the label text (or, similarly, add to the label text with += rather than replacing it).

p.s. Welcome to the forum!

1 Like

My first inclination when reading this is @showvik.sizan is running into a cross between the non-blocking nature of skulpt events / browser clicks vs the the latency of a return.

If someone keeps pressing the same button 3-4 times, it will send each request to your uplink script every time they click, but you are also asking it to update the text on the screen by replacing it with the result, which it will only do for the last time they clicked, which is the last call it made to uplink after sending a whole bunch of calls.

…So this might be the best way to see that issue in action.

Also change your uplink script to print something within in the function, my guess is you will watch it print something for every single time you click.

2 Likes

Right, and this reminded me of a demo app I created to clarify these issues:

3 Likes

Thank you all for the thoughtful responses. My problem was that I had slightly different version of uplink scripts running within different terminal windows (pycharm) in my local machine. Anvil was distributing click events randomly between these two uplink sessions, hence the weird behavior. Thank you @ianbuywise and @hugetim for highlighting related factor that might precipitate errors like this.

2 Likes