naeural-client 2.1.0__tar.gz → 2.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. {naeural_client-2.1.0 → naeural_client-2.1.1}/PKG-INFO +1 -1
  2. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/_ver.py +1 -1
  3. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/base/generic_session.py +17 -3
  4. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/base/instance.py +39 -0
  5. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/base/pipeline.py +3 -0
  6. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/code_cheker/base.py +74 -4
  7. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/default/instance/basic_telegram_bot_01_plugin.py +2 -0
  8. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/default/instance/custom_web_app_01_plugin.py +4 -7
  9. {naeural_client-2.1.0 → naeural_client-2.1.1}/pyproject.toml +1 -1
  10. {naeural_client-2.1.0 → naeural_client-2.1.1}/tutorials/ex01_part1_connect.py +13 -0
  11. {naeural_client-2.1.0 → naeural_client-2.1.1}/tutorials/ex10_telegram_echo_bot.py +8 -4
  12. naeural_client-2.1.1/tutorials/ex11_telegram_smart_bot.py +44 -0
  13. {naeural_client-2.1.0 → naeural_client-2.1.1}/.devcontainer/Dockerfile +0 -0
  14. {naeural_client-2.1.0 → naeural_client-2.1.1}/.devcontainer/devcontainer.json +0 -0
  15. {naeural_client-2.1.0 → naeural_client-2.1.1}/.gitattributes +0 -0
  16. {naeural_client-2.1.0 → naeural_client-2.1.1}/.github/workflows/python-publish.yml +0 -0
  17. {naeural_client-2.1.0 → naeural_client-2.1.1}/.gitignore +0 -0
  18. {naeural_client-2.1.0 → naeural_client-2.1.1}/.vscode/launch.json +0 -0
  19. {naeural_client-2.1.0 → naeural_client-2.1.1}/LICENSE +0 -0
  20. {naeural_client-2.1.0 → naeural_client-2.1.1}/README.md +0 -0
  21. {naeural_client-2.1.0 → naeural_client-2.1.1}/TODOs.md +0 -0
  22. {naeural_client-2.1.0 → naeural_client-2.1.1}/__init__.py +0 -0
  23. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/__init__.py +0 -0
  24. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/base/__init__.py +0 -0
  25. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/base/distributed_custom_code_presets.py +0 -0
  26. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/base/payload/__init__.py +0 -0
  27. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/base/payload/payload.py +0 -0
  28. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/base/plugin_template.py +0 -0
  29. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/base/responses.py +0 -0
  30. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/base/transaction.py +0 -0
  31. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/base_decentra_object.py +0 -0
  32. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/bc/__init__.py +0 -0
  33. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/bc/base.py +0 -0
  34. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/bc/chain.py +0 -0
  35. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/bc/ec.py +0 -0
  36. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/certs/__init__.py +0 -0
  37. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/certs/r9092118.ala.eu-central-1.emqxsl.com.crt +0 -0
  38. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/code_cheker/__init__.py +0 -0
  39. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/code_cheker/checker.py +0 -0
  40. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/comm/__init__.py +0 -0
  41. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/comm/amqp_wrapper.py +0 -0
  42. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/comm/mqtt_wrapper.py +0 -0
  43. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/const/README.md +0 -0
  44. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/const/__init__.py +0 -0
  45. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/const/apps.py +0 -0
  46. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/const/base.py +0 -0
  47. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/const/comms.py +0 -0
  48. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/const/environment.py +0 -0
  49. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/const/formatter.py +0 -0
  50. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/const/heartbeat.py +0 -0
  51. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/const/misc.py +0 -0
  52. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/const/payload.py +0 -0
  53. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/default/__init__.py +0 -0
  54. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/default/instance/__init__.py +0 -0
  55. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/default/instance/chain_dist_custom_job_01_plugin.py +0 -0
  56. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/default/instance/net_mon_01_plugin.py +0 -0
  57. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/default/instance/view_scene_01_plugin.py +0 -0
  58. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/default/session/mqtt_session.py +0 -0
  59. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/io_formatter/__init__.py +0 -0
  60. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/io_formatter/base/__init__.py +0 -0
  61. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/io_formatter/base/base_formatter.py +0 -0
  62. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/io_formatter/default/__init__.py +0 -0
  63. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/io_formatter/default/a_dummy.py +0 -0
  64. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/io_formatter/default/aixp1.py +0 -0
  65. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/io_formatter/default/default.py +0 -0
  66. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/io_formatter/io_formatter_manager.py +0 -0
  67. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/__init__.py +0 -0
  68. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/base_logger.py +0 -0
  69. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/logger_mixins/__init__.py +0 -0
  70. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/logger_mixins/class_instance_mixin.py +0 -0
  71. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/logger_mixins/computer_vision_mixin.py +0 -0
  72. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/logger_mixins/datetime_mixin.py +0 -0
  73. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/logger_mixins/download_mixin.py +0 -0
  74. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/logger_mixins/general_serialization_mixin.py +0 -0
  75. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/logger_mixins/json_serialization_mixin.py +0 -0
  76. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/logger_mixins/pickle_serialization_mixin.py +0 -0
  77. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/logger_mixins/process_mixin.py +0 -0
  78. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/logger_mixins/resource_size_mixin.py +0 -0
  79. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/logger_mixins/timers_mixin.py +0 -0
  80. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/logger_mixins/upload_mixin.py +0 -0
  81. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/logger_mixins/utils_mixin.py +0 -0
  82. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/small_logger.py +0 -0
  83. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/tzlocal/__init__.py +0 -0
  84. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/tzlocal/unix.py +0 -0
  85. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/tzlocal/utils.py +0 -0
  86. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/tzlocal/win32.py +0 -0
  87. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/logging/tzlocal/windows_tz.py +0 -0
  88. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/plugins_manager_mixin.py +0 -0
  89. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/utils/__init__.py +0 -0
  90. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/utils/comm_utils.py +0 -0
  91. {naeural_client-2.1.0 → naeural_client-2.1.1}/naeural_client/utils/dotenv.py +0 -0
  92. {naeural_client-2.1.0 → naeural_client-2.1.1}/requirements.txt +0 -0
  93. {naeural_client-2.1.0 → naeural_client-2.1.1}/tutorials/.example_env +0 -0
  94. {naeural_client-2.1.0 → naeural_client-2.1.1}/tutorials/8. custom_code_fastapi_assets/index.html +0 -0
  95. {naeural_client-2.1.0 → naeural_client-2.1.1}/tutorials/9. code_sandbox_from_scratch_assets/index.html +0 -0
  96. {naeural_client-2.1.0 → naeural_client-2.1.1}/tutorials/_example_pk_sdk.pem +0 -0
  97. {naeural_client-2.1.0 → naeural_client-2.1.1}/tutorials/ex01_part2_filter.py +0 -0
  98. {naeural_client-2.1.0 → naeural_client-2.1.1}/tutorials/ex02_first_deploy.py +0 -0
  99. {naeural_client-2.1.0 → naeural_client-2.1.1}/tutorials/ex03_custom_code_on_one_remote__example_1.py +0 -0
  100. {naeural_client-2.1.0 → naeural_client-2.1.1}/tutorials/ex04_custom_code_on_one_remote__example_2.py +0 -0
  101. {naeural_client-2.1.0 → naeural_client-2.1.1}/tutorials/ex05_custom_code_on_one_remote__example_3.py +0 -0
  102. {naeural_client-2.1.0 → naeural_client-2.1.1}/tutorials/ex06_custom_code_on_multiple_remotes__example_1.py +0 -0
  103. {naeural_client-2.1.0 → naeural_client-2.1.1}/tutorials/ex07_custom_code_on_multiple_remotes__example_2.py +0 -0
  104. {naeural_client-2.1.0 → naeural_client-2.1.1}/tutorials/ex08_custom_web_app.py +0 -0
  105. {naeural_client-2.1.0 → naeural_client-2.1.1}/tutorials/ex09_code_sandbox_from_scratch.py +0 -0
  106. {naeural_client-2.1.0 → naeural_client-2.1.1}/tutorials/video_presentation/1. hello_world.ipynb +0 -0
  107. {naeural_client-2.1.0 → naeural_client-2.1.1}/winrun.bat +0 -0
  108. {naeural_client-2.1.0 → naeural_client-2.1.1}/xperimental/.example_env +0 -0
  109. {naeural_client-2.1.0 → naeural_client-2.1.1}/xperimental/README.md +0 -0
  110. {naeural_client-2.1.0 → naeural_client-2.1.1}/xperimental/_archive/test.py +0 -0
  111. {naeural_client-2.1.0 → naeural_client-2.1.1}/xperimental/_tutorials/3. simple_real_time_custom_code.py +0 -0
  112. {naeural_client-2.1.0 → naeural_client-2.1.1}/xperimental/_tutorials/4. real_time_custom_code_2.py +0 -0
  113. {naeural_client-2.1.0 → naeural_client-2.1.1}/xperimental/_tutorials/8. chatbot.py +0 -0
  114. {naeural_client-2.1.0 → naeural_client-2.1.1}/xperimental/attach_example.py +0 -0
  115. {naeural_client-2.1.0 → naeural_client-2.1.1}/xperimental/decentralized/chain_dist_example.py +0 -0
  116. {naeural_client-2.1.0 → naeural_client-2.1.1}/xperimental/decentralized/chain_dist_example_initiator.py +0 -0
  117. {naeural_client-2.1.0 → naeural_client-2.1.1}/xperimental/decentralized/chain_dist_example_worker.py +0 -0
  118. {naeural_client-2.1.0 → naeural_client-2.1.1}/xperimental/ex1.py +0 -0
  119. {naeural_client-2.1.0 → naeural_client-2.1.1}/xperimental/hello.py +0 -0
  120. {naeural_client-2.1.0 → naeural_client-2.1.1}/xperimental/remote_exec.py +0 -0
  121. {naeural_client-2.1.0 → naeural_client-2.1.1}/xperimental/save_images.py +0 -0
  122. {naeural_client-2.1.0 → naeural_client-2.1.1}/xperimental/utils/get_documentation.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: naeural_client
3
- Version: 2.1.0
3
+ Version: 2.1.1
4
4
  Summary: `naeural_client` is the Python SDK required for client app development for the Naeural Edge Protocol Edge Protocol framework
5
5
  Project-URL: Homepage, https://github.com/Naeural Edge ProtocolEdgeProtocol/naeural_client
6
6
  Project-URL: Bug Tracker, https://github.com/Naeural Edge ProtocolEdgeProtocol/naeural_client/issues
@@ -1,4 +1,4 @@
1
- __VER__ = "2.1.0"
1
+ __VER__ = "2.1.1"
2
2
 
3
3
  if __name__ == "__main__":
4
4
  with open("pyproject.toml", "rt") as fd:
@@ -1724,25 +1724,32 @@ class GenericSession(BaseDecentrAIObject):
1724
1724
  **kwargs
1725
1725
  ):
1726
1726
 
1727
+ assert callable(message_handler), "The `message_handler` method parameter must be provided."
1728
+
1727
1729
  if telegram_bot_token is None:
1728
1730
  telegram_bot_token = os.getenv(telegram_bot_token_env_key)
1729
1731
  if telegram_bot_token is None:
1730
1732
  message = f"Warning! No Telegram bot token provided as via env {ENVIRONMENT.TELEGRAM_BOT_TOKEN_ENV_KEY} or explicitly as `telegram_bot_token` param."
1731
1733
  raise ValueError(message)
1732
1734
 
1733
- b64code = self._get_base64_code(message_handler)
1734
1735
 
1735
1736
  pipeline: Pipeline = self.create_pipeline(
1736
1737
  node=node,
1737
1738
  name=name,
1738
1739
  # default TYPE is "Void"
1739
1740
  )
1740
-
1741
+
1742
+ func_name, func_args, func_base64_code = pipeline._get_method_data(message_handler)
1743
+ if len(func_args) != 2:
1744
+ raise ValueError("The message handler function must have exactly 2 arguments: `instance` and `data`.")
1745
+
1741
1746
  instance = pipeline.create_plugin_instance(
1742
1747
  signature=signature,
1743
1748
  instance_id=self.log.get_unique_id(),
1744
1749
  telegram_bot_token=telegram_bot_token,
1745
- message_handler=b64code,
1750
+ message_handler=func_base64_code,
1751
+ message_handler_args=func_args, # mandatory message and user
1752
+ message_handler_name=func_name, # not mandatory
1746
1753
  **kwargs
1747
1754
  )
1748
1755
  return pipeline, instance
@@ -1852,3 +1859,10 @@ class GenericSession(BaseDecentrAIObject):
1852
1859
  # end for detach
1853
1860
 
1854
1861
  return lst_result_payload
1862
+
1863
+ def get_client_address(self):
1864
+ return self.bc_engine.address
1865
+
1866
+ @property
1867
+ def client_address(self):
1868
+ return self.get_client_address()
@@ -202,6 +202,7 @@ class Instance():
202
202
 
203
203
  return f"<Instance: {node_addr}/{pipeline_name}/{signature}/{instance_id}>"
204
204
 
205
+
205
206
  def _is_tainted(self):
206
207
  """
207
208
  Check if the instance has a proposed configuration.
@@ -213,6 +214,7 @@ class Instance():
213
214
  """
214
215
  return self.proposed_config is not None
215
216
 
217
+
216
218
  def _get_config_dictionary(self):
217
219
  """
218
220
  Get the configuration of the instance as a dictionary.
@@ -229,6 +231,7 @@ class Instance():
229
231
 
230
232
  return config_dict
231
233
 
234
+
232
235
  def _get_proposed_config_dictionary(self, full=False):
233
236
  """
234
237
  Get the proposed configuration of the instance as a dictionary.
@@ -249,6 +252,7 @@ class Instance():
249
252
 
250
253
  return proposed_config_dict
251
254
 
255
+
252
256
  def _apply_staged_config(self, verbose=False):
253
257
  """
254
258
  Apply the staged configuration to the instance.
@@ -264,6 +268,7 @@ class Instance():
264
268
  self.__staged_config = None
265
269
  return
266
270
 
271
+
267
272
  def _discard_staged_config(self, fail_reason: str):
268
273
  """
269
274
  Discard the staged configuration for the instance.
@@ -274,6 +279,7 @@ class Instance():
274
279
  self.__staged_config = None
275
280
  return
276
281
 
282
+
277
283
  def _stage_proposed_config(self):
278
284
  """
279
285
  Stage the proposed configuration for the instance.
@@ -291,6 +297,7 @@ class Instance():
291
297
  self.__was_last_operation_successful = None
292
298
  return
293
299
 
300
+
294
301
  def _handle_instance_command_success(self):
295
302
  """
296
303
  Handle the success of the instance command.
@@ -299,6 +306,7 @@ class Instance():
299
306
  self.__was_last_operation_successful = True
300
307
  return
301
308
 
309
+
302
310
  def _handle_instance_command_failure(self, fail_reason: str):
303
311
  """
304
312
  Handle the failure of the instance command.
@@ -307,6 +315,7 @@ class Instance():
307
315
  self.__was_last_operation_successful = False
308
316
  return
309
317
 
318
+
310
319
  def __register_transaction_for_instance_command(self, session_id: str = None, timeout: float = 0) -> list[Transaction]:
311
320
  """
312
321
  Register a new transaction for the instance command.
@@ -340,6 +349,7 @@ class Instance():
340
349
 
341
350
  return transactions
342
351
 
352
+
343
353
  def _get_instance_update_required_responses(self):
344
354
  """
345
355
  Get the responses required to update the instance.
@@ -356,6 +366,7 @@ class Instance():
356
366
 
357
367
  return responses
358
368
 
369
+
359
370
  def _get_instance_remove_required_responses(self):
360
371
  """
361
372
  Get the responses required to delete the instance.
@@ -371,6 +382,23 @@ class Instance():
371
382
 
372
383
  return responses
373
384
 
385
+ def _get_method_data(self, method: callable):
386
+ """
387
+ Get the full signature and definition of a method.
388
+
389
+ Parameters
390
+ ----------
391
+
392
+ method : callable
393
+ The method to get the signature and definition for.
394
+
395
+ Returns
396
+ -------
397
+ tuple
398
+ A tuple containing the name, arguments and base64 code of the method.
399
+ """
400
+ return self.pipeline._get_method_data(method)
401
+
374
402
  # API
375
403
  if True:
376
404
  @property
@@ -399,10 +427,12 @@ class Instance():
399
427
  """
400
428
  return self.__was_last_operation_successful
401
429
 
430
+
402
431
  def _sync_configuration_with_remote(self, config):
403
432
  self.config = {**self.config, **config}
404
433
  return
405
434
 
435
+
406
436
  def update_instance_config(self, config={}, **kwargs):
407
437
  """
408
438
  Update the configuration of the instance.
@@ -438,6 +468,7 @@ class Instance():
438
468
 
439
469
  return
440
470
 
471
+
441
472
  def send_instance_command(self, command, payload=None, command_params=None, wait_confirmation=True, session_id=None, timeout=10):
442
473
  """
443
474
  Send a command to the instance.
@@ -495,6 +526,7 @@ class Instance():
495
526
  return transactions
496
527
  return
497
528
 
529
+
498
530
  def close(self):
499
531
  """
500
532
  Close the instance.
@@ -502,20 +534,24 @@ class Instance():
502
534
  self.pipeline.remove_plugin_instance(self)
503
535
  return
504
536
 
537
+
505
538
  def stop(self):
506
539
  """
507
540
  Close the instance. Alias for `close`.
508
541
  """
509
542
  self.close()
510
543
 
544
+
511
545
  def P(self, *args, **kwargs):
512
546
  self.log.P(*args, **kwargs)
513
547
  return
514
548
 
549
+
515
550
  def D(self, *args, **kwargs):
516
551
  self.log.D(*args, **kwargs)
517
552
  return
518
553
 
554
+
519
555
  def temporary_attach(self, on_data=None, on_notification=None):
520
556
  """
521
557
  Attach a temporary callback to the instance.
@@ -542,6 +578,7 @@ class Instance():
542
578
 
543
579
  return attachment
544
580
 
581
+
545
582
  def temporary_detach(self, attachment):
546
583
  """
547
584
  Detach a temporary callback from the instance.
@@ -555,6 +592,7 @@ class Instance():
555
592
  self._remove_temporary_on_notification_callback(attachment)
556
593
  return
557
594
 
595
+
558
596
  def convert_to_specialized_class(self, specialized_class):
559
597
  """
560
598
  Convert the object to a specialized class.
@@ -564,6 +602,7 @@ class Instance():
564
602
  self.__class__ = specialized_class
565
603
  return self
566
604
 
605
+
567
606
  def send_instance_command_and_wait_for_response_payload(self, command, payload=None, command_params=None, timeout_command=10, timeout_response_payload=3, response_params_key="COMMAND_PARAMS"):
568
607
  """
569
608
  Send a command to the instance and wait for the response payload.
@@ -664,6 +664,7 @@ class Pipeline(BaseCodeChecker):
664
664
 
665
665
  return self.code_to_base64(plain_code, verbose=False)
666
666
 
667
+
667
668
  # Message handling
668
669
  if True:
669
670
  def _on_data(self, signature, instance_id, data):
@@ -1497,3 +1498,5 @@ class Pipeline(BaseCodeChecker):
1497
1498
  Return the node id of the pipeline.
1498
1499
  """
1499
1500
  return self.session.get_node_name(self.node_addr)
1501
+
1502
+
@@ -428,7 +428,15 @@ class BaseCodeChecker:
428
428
 
429
429
  return res
430
430
 
431
- def _get_method_from_custom_code(self, str_b64code, debug=False, result_vars=RESULT_VARS, self_var=None, modify=True, method_arguments=[]):
431
+ def _get_method_from_custom_code(
432
+ self,
433
+ str_b64code,
434
+ debug=False,
435
+ result_vars=RESULT_VARS,
436
+ self_var=None,
437
+ modify=True,
438
+ method_arguments=[]
439
+ ):
432
440
  exec_code__result_vars = result_vars
433
441
  exec_code__debug = debug
434
442
  exec_code__self_var = self_var
@@ -470,8 +478,9 @@ class BaseCodeChecker:
470
478
  exec_code__errors = ["Cannot encapsulate code in method. No return statement found."]
471
479
  return exec_code__result_var, exec_code__errors, exec_code__warnings
472
480
  # endif can encapsulate code in method
473
-
474
- exec(exec_code__code)
481
+ if exec_code__debug:
482
+ self.__msg("DEBUG EXEC: Encapsulated code: \n{}".format(exec_code__code))
483
+ exec(exec_code__code) # now we execute the method definition code not the actual method
475
484
  if exec_code__debug:
476
485
  self.__msg("DEBUG EXEC: locals(): \n{}".format(locals()))
477
486
  for _var in exec_code__result_vars:
@@ -521,11 +530,37 @@ class BaseCodeChecker:
521
530
  plain_code = '\n'.join([line.rstrip()[indent:] for line in plain_code])
522
531
 
523
532
  return plain_code
533
+
534
+ def _get_method_data(self, method: callable):
535
+ """
536
+ Get the full signature and definition of a method.
537
+
538
+ Parameters
539
+ ----------
540
+
541
+ method : callable
542
+ The method to get the signature and definition for.
543
+
544
+ Returns
545
+ -------
546
+ tuple
547
+ A tuple containing the name, arguments and base64 code of the method.
548
+ """
549
+ import inspect
550
+
551
+ name = method.__name__
552
+ args = list(map(str, inspect.signature(method).parameters.values()))
553
+ if args[0] in ['self', 'cls', 'plugin']:
554
+ args = args[1:]
555
+ source = self.get_function_source_code(method)
556
+ base64_code = self.code_to_base64(source)
557
+
558
+ return name, args, base64_code
524
559
 
525
560
 
526
561
  if __name__ == '__main__':
527
562
 
528
- def some_function(x):
563
+ def some_function(plugin, x):
529
564
  """
530
565
  A simple function that adds 1 to the input.
531
566
 
@@ -539,9 +574,44 @@ if __name__ == '__main__':
539
574
  _type_
540
575
  _description_
541
576
  """
577
+ print(f"Called by: {plugin}")
542
578
  return x + 1
543
579
 
580
+
581
+ class SomeClass:
582
+ def __init__(self, eng : BaseCodeChecker, str_b64code, func_args):
583
+ self.eng : BaseCodeChecker = eng
584
+ self._func, _, _ = eng._get_method_from_custom_code(
585
+ str_b64code=str_b64code,
586
+ self_var='plugin',
587
+ method_arguments=["plugin"] + func_args,
588
+ debug=False
589
+ )
590
+ return
591
+
592
+
593
+ def my_func(self, a):
594
+ res = self._func(x=a, plugin=self)
595
+ return res
596
+
597
+
544
598
  checker = BaseCodeChecker()
545
599
  source_code = checker.get_function_source_code(some_function)
546
600
  print("some_function:\n" + source_code)
601
+
602
+ name, args, b64code = checker._get_method_data(some_function)
603
+ print(f"Method name: {name}")
604
+ print(f"Method args: {args}")
605
+ print(f"Method code: {b64code}")
606
+
607
+ target = SomeClass(checker, str_b64code=b64code, func_args=args)
608
+
609
+ print(some_function(x=9.1, plugin=None))
610
+ print(target.my_func(9.1))
611
+
612
+
613
+
614
+
615
+
616
+
547
617
 
@@ -3,3 +3,5 @@ from ...const import PLUGIN_SIGNATURES
3
3
 
4
4
  class BasicTelegramBot01(Instance):
5
5
  signature = PLUGIN_SIGNATURES.BASIC_TELEGRAM_BOT_01
6
+
7
+
@@ -12,13 +12,10 @@ class CustomWebApp01(Instance):
12
12
  return deepcopy(self.config.get("ENDPOINTS", []))
13
13
 
14
14
  def get_endpoint_fields(self, method: callable):
15
- import inspect
16
-
17
- name = method.__name__
18
- args = list(map(str, inspect.signature(method).parameters.values()))[1:]
19
- base64_code = self.pipeline._get_base64_code(method)
20
-
21
- return name, args, base64_code
15
+ """
16
+ A aliast for get_method_data: it returns the name, args and base64 code of a method.
17
+ """
18
+ return self._get_method_data(method)
22
19
 
23
20
 
24
21
  def get_proposed_assets(self):
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "naeural_client"
7
- version = "2.1.0"
7
+ version = "2.1.1"
8
8
  authors = [
9
9
  { name="Stefan Saraev", email="saraevstefan@gmail.com" },
10
10
  { name="Andrei Ionut Damian", email="andrei.damian@me.com" },
@@ -3,6 +3,18 @@ This is a simple example of how to use the naeural_client SDK.
3
3
 
4
4
  In this example, we connect to the network, listen for heartbeats from
5
5
  Naeural Edge Protocol edge nodes and print the CPU of each node.
6
+
7
+
8
+
9
+ New connection algorithm:
10
+
11
+ 1. The client connects to the network.
12
+ 2. The client waits for the first 2 supervisors payload with network map.
13
+ 3. The client reads `partner_peers` - all nodes that recognize the client as allowed - based on supervisor(s) network map.
14
+ 4. The client sends a pipeline status to all `partner_peers`.
15
+ 5. The client then knows the `partner_peers` and can send messages to them.
16
+ IMPORTANT: Session will WAIT until network map is clarified.
17
+
6
18
  """
7
19
  import json
8
20
 
@@ -50,6 +62,7 @@ if __name__ == '__main__':
50
62
  on_heartbeat=filterer.on_heartbeat,
51
63
  )
52
64
 
65
+ session.P("Client address is: {}".format(session.get_client_address()), color='g')
53
66
 
54
67
  # Observation:
55
68
  # next code is not mandatory - it is used to keep the session open and cleanup the resources
@@ -6,6 +6,8 @@ from naeural_client import Session, CustomPluginTemplate, PLUGIN_TYPES
6
6
  def reply(plugin: CustomPluginTemplate, message: str, user: str):
7
7
  """
8
8
  This function is used to reply to a message.
9
+
10
+ The given parameters are mandatory
9
11
  """
10
12
  # for each user message we increase a counter
11
13
  plugin.int_cache[user] += 1 # int_cache is a default dict that allows persistence in the plugin
@@ -13,8 +15,9 @@ def reply(plugin: CustomPluginTemplate, message: str, user: str):
13
15
  result = f"The answer to your {plugin.int_cache[user]} question is in the question itself: {message}"
14
16
  return result
15
17
 
18
+
16
19
  if __name__ == "__main__":
17
- TELEGRAM_BOT_TOKEN_ENV_KEY = "TELEGRAM_BOT_TOKEN"
20
+ # TELEGRAM_BOT_TOKEN_ENV_KEY = "TELEGRAM_BOT_TOKEN" # this is the default - we can specify a env key here
18
21
  MY_NODE = None # we can specify a node here, if we want to connect to a specific
19
22
 
20
23
  session = Session() # assume .env is available and will be used for the connection and tokens
@@ -28,11 +31,12 @@ if __name__ == "__main__":
28
31
 
29
32
  # now we create a telegram bot pipeline & plugin instance
30
33
  # we can chose to use the token directly or use the environment key
31
- instance: PLUGIN_TYPES.BASIC_TELEGRAM_BOT_01
32
- pipeline, instance = session.create_telegram_simple_bot(
34
+ # instance: PLUGIN_TYPES.BASIC_TELEGRAM_BOT_01
35
+ pipeline, _ = session.create_telegram_simple_bot(
33
36
  node=node,
34
37
  name="telegram_bot_echo",
35
- telegram_bot_token_env_key=TELEGRAM_BOT_TOKEN_ENV_KEY,
38
+ # telegram_bot_token=os.getenv("TELEGRAM_BOT_TOKEN"), # we use the token directly
39
+ # telegram_bot_token_env_key=TELEGRAM_BOT_TOKEN_ENV_KEY, # not mandatory - we can use the default
36
40
  reply_function=reply,
37
41
  )
38
42
 
@@ -0,0 +1,44 @@
1
+ import os
2
+
3
+ from naeural_client import Session, CustomPluginTemplate, PLUGIN_TYPES
4
+
5
+ if __name__ == "__main__":
6
+ # TELEGRAM_BOT_TOKEN_ENV_KEY = "TELEGRAM_BOT_TOKEN" # we can specify the token here
7
+ MY_NODE = None # we can specify a node here, if we want to connect to a specific
8
+
9
+ SYSTEM_PROMPT = """
10
+ Hi! I am a simple echo bot. I will repeat everything you say to me.
11
+ """
12
+
13
+ session = Session() # assume .env is available and will be used for the connection and tokens
14
+
15
+ if MY_NODE:
16
+ node = MY_NODE
17
+ else:
18
+ session.wait_for_any_node() # we wait for any node to present itself as active
19
+ node = session.get_active_nodes()[0] # we get the first active node
20
+
21
+
22
+ # now we create a telegram bot pipeline & plugin instance
23
+ # we can chose to use the token directly or use the environment key
24
+ # instance: PLUGIN_TYPES.BASIC_TELEGRAM_BOT_01
25
+ pipeline, _ = session.create_telegram_conversational_bot(
26
+ node=node,
27
+ name="telegram_bot_echo",
28
+ # telegram_bot_token_env_key=TELEGRAM_BOT_TOKEN_ENV_KEY, # this is not mandatory
29
+ system_prompt=SYSTEM_PROMPT, # simple bot based on system prompt only
30
+ # rag_source=rag_db_url, # advanced
31
+ # bot_type="API" # "API", "HOSTED"
32
+ # api_token_env_key="BOT_API_TOKEN", # if bot_type is "API" - this is a default
33
+ )
34
+
35
+ pipeline.deploy() # we deploy the pipeline
36
+
37
+ # # Observation:
38
+ # # next code is not mandatory - it is used to keep the session open and cleanup the resources
39
+ # # in production, you would not need this code as the script can close after the pipeline will be sent
40
+ # session.run(
41
+ # wait=60, # we run the session for 60 seconds
42
+ # close_pipelines=True, # we close the pipelines after the session
43
+ # close_session=True, # we close the session after the session
44
+ # )
File without changes
File without changes
File without changes