code: def _get_latest_service_state(
      settings, tabpy_state, new_ps_state, python_service
  ):
      """
      Update the endpoints from the latest remote state file.
  
      Returns
      --------
      (has_changes, endpoint_diff):
          has_changes: True or False
          endpoint_diff: Summary of what has changed, one entry for each changes
      """
      # Shortcut when nothing is changed
      changes = {"endpoints": {}}
  
      # update endpoints
      new_endpoints = new_ps_state.get_endpoints()
      diff = {}
      current_endpoints = python_service.ps.query_objects
      for endpoint_name, endpoint_info in new_endpoints.items():
          existing_endpoint = current_endpoints.get(endpoint_name)
          if (existing_endpoint is None) or endpoint_info[
              "version"
          ] != existing_endpoint["version"]:
              # Either a new endpoint or new endpoint version
              path_to_new_version = get_query_object_path(
                  settings[SettingsParameters.StateFilePath],
                  endpoint_name,
                  endpoint_info["version"],
              )
              endpoint_type = endpoint_info.get("type", "model")
              diff[endpoint_name] = (
                  endpoint_type,
                  endpoint_info["version"],
                  path_to_new_version,
              )
  
      # add removed models too
      for endpoint_name, endpoint_info in current_endpoints.items():
          if endpoint_name not in new_endpoints.keys():
              endpoint_type = current_endpoints[endpoint_name].get(
                  "type", "model"
              )
              diff[endpoint_name] = (endpoint_type, None, None)
  
      if diff:
          changes["endpoints"] = diff
  
      return (True, changes)
  
file_path: TabPy/tabpy/tabpy_server/psws/callbacks.py
imports: import logging
  from tabpy.tabpy_server.app.app_parameters import SettingsParameters
  from tabpy.tabpy_server.common.messages import LoadObject, DeleteObjects, ListObjects, ObjectList
  from tabpy.tabpy_server.common.endpoint_file_mgr import cleanup_endpoint_files
  from tabpy.tabpy_server.common.util import format_exception
  from tabpy.tabpy_server.management.state import TabPyState, get_query_object_path
  from tabpy.tabpy_server.management import util
  from time import sleep
  from tornado import gen
label_desc: Use image node_id 4 for calling a global function with example usage: _get_latest_service_state(settings, tabpy_state, new_ps_state, python_service) and returns: True,  changes