sunholo 0.105.0__py3-none-any.whl → 0.105.1__py3-none-any.whl

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.
@@ -60,7 +60,7 @@ class GenAIFunctionProcessor:
60
60
  ```
61
61
  """
62
62
 
63
- def __init__(self, config: ConfigManager=None, model_name=None):
63
+ def __init__(self, config: ConfigManager=None, model_name=None, trace=None, parent_observation_id=None):
64
64
  """
65
65
  Initializes the GenAIFunctionProcessor with the given configuration.
66
66
 
@@ -84,6 +84,9 @@ class GenAIFunctionProcessor:
84
84
  elif model_name:
85
85
  self.model_name = model_name
86
86
 
87
+ self.trace = trace
88
+ self.parent_observation_id = parent_observation_id
89
+
87
90
  self.last_api_requests_and_responses = []
88
91
  self._validate_functions()
89
92
 
@@ -430,6 +433,12 @@ class GenAIFunctionProcessor:
430
433
  # Initialize token queue to ensure sequential processing
431
434
  token_queue = deque()
432
435
 
436
+ span = self.trace.span(
437
+ name=f"GenAIFunctionProcesser_{self.__class__.__name__}",
438
+ parent_observation_id=self.parent_observation_id,
439
+ input = {'content': content},
440
+ ) if self.trace else None
441
+
433
442
  while guardrail < guardrail_max:
434
443
 
435
444
  token_queue.append(f"\n----Loop [{guardrail}] Start------\nFunctions: {list(self.funcs.keys())}\n")
@@ -442,10 +451,22 @@ class GenAIFunctionProcessor:
442
451
  log.info(f"== Start input content for loop [{guardrail}]\n ## Content: {content_parse}")
443
452
  this_text = "" # reset for this loop
444
453
  response = None
454
+ loop_span = span.span(
455
+ name=f"loop_{guardrail}",
456
+ model=self.model_name,
457
+ input = {'content': content},
458
+ ) if span else None
445
459
 
446
460
  try:
447
461
  token_queue.append("\n= Calling Agent =\n")
448
- response:GenerateContentResponse = chat.send_message(content, stream=True, request_options=RequestOptions(
462
+
463
+ gen = loop_span.generation(
464
+ name=f"loop_{guardrail}",
465
+ model=self.model_name,
466
+ input = {'content': content},
467
+ ) if loop_span else None
468
+
469
+ response: GenerateContentResponse = chat.send_message(content, stream=True, request_options=RequestOptions(
449
470
  retry=retry.Retry(
450
471
  initial=10,
451
472
  multiplier=2,
@@ -479,6 +500,9 @@ class GenAIFunctionProcessor:
479
500
  f"Session tokens: [{loop_metadata.total_token_count}]/[{usage_metadata['total_token_count']}] \n"
480
501
  ))
481
502
  loop_metadata = None
503
+ gen.end(output=dict(response)) if gen else None
504
+ else:
505
+ gen.end(output="No response received") if gen else None
482
506
 
483
507
  for chunk in response:
484
508
  if not chunk:
@@ -495,7 +519,7 @@ class GenAIFunctionProcessor:
495
519
 
496
520
  except ValueError as err:
497
521
  token_queue.append(f"{str(err)} for {chunk=}")
498
-
522
+ fn_span = loop_span.span(name="function_execution", input=response) if loop_span else None
499
523
  try:
500
524
  executed_responses = self.process_funcs(response)
501
525
  except Exception as err:
@@ -504,9 +528,11 @@ class GenAIFunctionProcessor:
504
528
  token_queue.append(f"{str(err)} for {response=}")
505
529
 
506
530
  log.info(f"[{guardrail}] {executed_responses=}")
531
+ fn_span.end(output=executed_responses) if fn_span else None
507
532
 
508
533
  if executed_responses:
509
534
  token_queue.append("\n-- Agent Actions:\n")
535
+ fn_exec = loop_span.span(name="function_actions", input=executed_responses) if loop_span else None
510
536
  for executed_response in executed_responses:
511
537
  token = ""
512
538
  fn = executed_response.function_response.name
@@ -522,6 +548,7 @@ class GenAIFunctionProcessor:
522
548
  callback.on_llm_new_token(token=token)
523
549
 
524
550
  log.info(f"{fn_log} created a result={type(fn_result)=}")
551
+ fn_exec_one = fn_exec.span(name=fn_log, input=fn_result) if fn_exec else None
525
552
 
526
553
  fn_result_json = None
527
554
  # Convert MapComposite to a standard Python dictionary
@@ -574,11 +601,15 @@ class GenAIFunctionProcessor:
574
601
 
575
602
  this_text += token
576
603
  token_queue.append(token)
604
+ fn_exec_one.end(output=token) if fn_exec_one else None
605
+
577
606
  else:
578
607
  token = "\nNo function executions were found\n"
579
608
  token_queue.append(token)
580
609
  this_text += token
581
610
 
611
+ fn_exec.end(output=this_text) if fn_exec else None
612
+
582
613
  if this_text:
583
614
  content.append(f"Agent: {this_text}")
584
615
  # if text includes gs:// try to download it
@@ -595,6 +626,7 @@ class GenAIFunctionProcessor:
595
626
  content.append(f"Agent: No response was found for loop [{guardrail}]")
596
627
 
597
628
  token_queue.append(f"\n----Loop [{guardrail}] End------\n{usage_metadata}\n----------------------")
629
+ loop_span.end(output=content, metadata=loop_metadata) if loop_span else None
598
630
 
599
631
  go_on_check = self.check_function_result("decide_to_go_on", {"go_on": False})
600
632
  if go_on_check:
@@ -617,6 +649,7 @@ class GenAIFunctionProcessor:
617
649
  usage_metadata["functions_called"] = functions_called
618
650
 
619
651
  big_text = "\n".join(big_result[-loop_return:])
652
+ span.end(output=big_text, metadata=usage_metadata) if span else None
620
653
 
621
654
  return big_text, usage_metadata
622
655
 
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sunholo
3
- Version: 0.105.0
3
+ Version: 0.105.1
4
4
  Summary: Large Language Model DevOps - a package to help deploy LLMs to the Cloud.
5
5
  Home-page: https://github.com/sunholo-data/sunholo-py
6
- Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.105.0.tar.gz
6
+ Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.105.1.tar.gz
7
7
  Author: Holosun ApS
8
8
  Author-email: multivac@sunholo.com
9
9
  License: Apache License, Version 2.0
@@ -88,7 +88,7 @@ sunholo/gcs/metadata.py,sha256=oQLcXi4brsZ74aegWyC1JZmhlaEV270HS5_UWtAYYWE,898
88
88
  sunholo/genai/__init__.py,sha256=dBl6IA3-Fx6-Vx81r0XqxHlUq6WeW1iDX188dpChu8s,115
89
89
  sunholo/genai/images.py,sha256=EyjsDqt6XQw99pZUQamomCpMOoIah9bp3XY94WPU7Ms,1678
90
90
  sunholo/genai/init.py,sha256=yG8E67TduFCTQPELo83OJuWfjwTnGZsyACospahyEaY,687
91
- sunholo/genai/process_funcs_cls.py,sha256=aO23nFLYCJEQ1ZR1rWefSNaqpUg4KXJGIua_ouDVR8E,29658
91
+ sunholo/genai/process_funcs_cls.py,sha256=c3pNWj8jWahMEwIbejm9euBr31WW0z50H5CPr9FW7cY,31310
92
92
  sunholo/genai/safety.py,sha256=mkFDO_BeEgiKjQd9o2I4UxB6XI7a9U-oOFjZ8LGRUC4,1238
93
93
  sunholo/invoke/__init__.py,sha256=o1RhwBGOtVK0MIdD55fAIMCkJsxTksi8GD5uoqVKI-8,184
94
94
  sunholo/invoke/async_class.py,sha256=G8vD2H94fpBc37mSJSQODEKJ67P2mPQEHabtDaLOvxE,8033
@@ -147,9 +147,9 @@ sunholo/vertex/init.py,sha256=1OQwcPBKZYBTDPdyU7IM4X4OmiXLdsNV30C-fee2scQ,2875
147
147
  sunholo/vertex/memory_tools.py,sha256=tBZxqVZ4InTmdBvLlOYwoSEWu4-kGquc-gxDwZCC4FA,7667
148
148
  sunholo/vertex/safety.py,sha256=S9PgQT1O_BQAkcqauWncRJaydiP8Q_Jzmu9gxYfy1VA,2482
149
149
  sunholo/vertex/type_dict_to_json.py,sha256=uTzL4o9tJRao4u-gJOFcACgWGkBOtqACmb6ihvCErL8,4694
150
- sunholo-0.105.0.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
151
- sunholo-0.105.0.dist-info/METADATA,sha256=VJ8EeXPxQ19YS2iUjsBY5W5V-4vBdxtHwowutoeMMiE,8312
152
- sunholo-0.105.0.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
153
- sunholo-0.105.0.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
154
- sunholo-0.105.0.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
155
- sunholo-0.105.0.dist-info/RECORD,,
150
+ sunholo-0.105.1.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
151
+ sunholo-0.105.1.dist-info/METADATA,sha256=XxAhxZcKvX8_GXcUpvePkoRnEIuCCcwATuCSk_gn3BA,8312
152
+ sunholo-0.105.1.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
153
+ sunholo-0.105.1.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
154
+ sunholo-0.105.1.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
155
+ sunholo-0.105.1.dist-info/RECORD,,