hamtaa-texttools 2.1.0__py3-none-any.whl → 2.3.0__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.
@@ -5,17 +5,21 @@ from typing import Any, Literal
5
5
 
6
6
  from openai import AsyncOpenAI
7
7
 
8
- from ..core.exceptions import LLMError, PromptError, TextToolsError, ValidationError
9
- from ..core.internal_models import (
8
+ from ..core import (
9
+ AsyncOperator,
10
10
  Bool,
11
11
  ListDictStrStr,
12
12
  ListStr,
13
+ LLMError,
14
+ PromptError,
13
15
  ReasonListStr,
14
16
  Str,
17
+ TextToolsError,
18
+ TheToolUtils,
19
+ TokenUsage,
20
+ ValidationError,
15
21
  create_dynamic_model,
16
22
  )
17
- from ..core.operators.async_operator import AsyncOperator
18
- from ..core.utils import TheToolUtils
19
23
  from ..models import CategoryTree, ToolOutput, ToolOutputMetadata
20
24
 
21
25
 
@@ -29,6 +33,7 @@ class AsyncTheTool:
29
33
  self._operator = AsyncOperator(client=client, model=model)
30
34
  self.logger = logging.getLogger(self.__class__.__name__)
31
35
  self.raise_on_error = raise_on_error
36
+ self.model = model
32
37
 
33
38
  async def categorize(
34
39
  self,
@@ -62,7 +67,6 @@ class AsyncTheTool:
62
67
 
63
68
  Returns:
64
69
  ToolOutput
65
-
66
70
  """
67
71
  tool_name = "categorize"
68
72
  start = perf_counter()
@@ -92,7 +96,10 @@ class AsyncTheTool:
92
96
  )
93
97
 
94
98
  metadata = ToolOutputMetadata(
95
- tool_name=tool_name, execution_time=perf_counter() - start
99
+ tool_name=tool_name,
100
+ execution_time=perf_counter() - start,
101
+ processed_by=self.model,
102
+ token_usage=operator_output.token_usage,
96
103
  )
97
104
  tool_output = ToolOutput(
98
105
  result=operator_output.result,
@@ -107,6 +114,7 @@ class AsyncTheTool:
107
114
  final_categories = []
108
115
  analysis = ""
109
116
  logprobs_list = []
117
+ token_usage = TokenUsage()
110
118
 
111
119
  for _ in range(levels):
112
120
  if not parent_node.children:
@@ -150,9 +158,13 @@ class AsyncTheTool:
150
158
  analysis += level_operator_output.analysis
151
159
  if logprobs:
152
160
  logprobs_list.extend(level_operator_output.logprobs)
161
+ token_usage += level_operator_output.token_usage
153
162
 
154
163
  metadata = ToolOutputMetadata(
155
- tool_name=tool_name, execution_time=(perf_counter() - start)
164
+ tool_name=tool_name,
165
+ execution_time=perf_counter() - start,
166
+ processed_by=self.model,
167
+ token_usage=token_usage,
156
168
  )
157
169
  tool_output = ToolOutput(
158
170
  result=final_categories,
@@ -238,7 +250,10 @@ class AsyncTheTool:
238
250
  )
239
251
 
240
252
  metadata = ToolOutputMetadata(
241
- tool_name=tool_name, execution_time=perf_counter() - start
253
+ tool_name=tool_name,
254
+ execution_time=perf_counter() - start,
255
+ processed_by=self.model,
256
+ token_usage=operator_output.token_usage,
242
257
  )
243
258
  tool_output = ToolOutput(
244
259
  result=operator_output.result,
@@ -322,7 +337,10 @@ class AsyncTheTool:
322
337
  )
323
338
 
324
339
  metadata = ToolOutputMetadata(
325
- tool_name=tool_name, execution_time=perf_counter() - start
340
+ tool_name=tool_name,
341
+ execution_time=perf_counter() - start,
342
+ processed_by=self.model,
343
+ token_usage=operator_output.token_usage,
326
344
  )
327
345
  tool_output = ToolOutput(
328
346
  result=operator_output.result,
@@ -401,7 +419,10 @@ class AsyncTheTool:
401
419
  )
402
420
 
403
421
  metadata = ToolOutputMetadata(
404
- tool_name=tool_name, execution_time=perf_counter() - start
422
+ tool_name=tool_name,
423
+ execution_time=perf_counter() - start,
424
+ processed_by=self.model,
425
+ token_usage=operator_output.token_usage,
405
426
  )
406
427
  tool_output = ToolOutput(
407
428
  result=operator_output.result,
@@ -487,7 +508,10 @@ class AsyncTheTool:
487
508
  )
488
509
 
489
510
  metadata = ToolOutputMetadata(
490
- tool_name=tool_name, execution_time=perf_counter() - start
511
+ tool_name=tool_name,
512
+ execution_time=perf_counter() - start,
513
+ processed_by=self.model,
514
+ token_usage=operator_output.token_usage,
491
515
  )
492
516
  tool_output = ToolOutput(
493
517
  result=operator_output.result,
@@ -571,7 +595,10 @@ class AsyncTheTool:
571
595
  )
572
596
 
573
597
  metadata = ToolOutputMetadata(
574
- tool_name=tool_name, execution_time=perf_counter() - start
598
+ tool_name=tool_name,
599
+ execution_time=perf_counter() - start,
600
+ processed_by=self.model,
601
+ token_usage=operator_output.token_usage,
575
602
  )
576
603
  tool_output = ToolOutput(
577
604
  result=operator_output.result,
@@ -654,7 +681,10 @@ class AsyncTheTool:
654
681
  )
655
682
 
656
683
  metadata = ToolOutputMetadata(
657
- tool_name=tool_name, execution_time=perf_counter() - start
684
+ tool_name=tool_name,
685
+ execution_time=perf_counter() - start,
686
+ processed_by=self.model,
687
+ token_usage=operator_output.token_usage,
658
688
  )
659
689
  tool_output = ToolOutput(
660
690
  result=operator_output.result,
@@ -735,7 +765,10 @@ class AsyncTheTool:
735
765
  )
736
766
 
737
767
  metadata = ToolOutputMetadata(
738
- tool_name=tool_name, execution_time=perf_counter() - start
768
+ tool_name=tool_name,
769
+ execution_time=perf_counter() - start,
770
+ processed_by=self.model,
771
+ token_usage=operator_output.token_usage,
739
772
  )
740
773
  tool_output = ToolOutput(
741
774
  result=operator_output.result,
@@ -803,6 +836,7 @@ class AsyncTheTool:
803
836
  translation = ""
804
837
  analysis = ""
805
838
  logprobs_list = []
839
+ token_usage = TokenUsage()
806
840
 
807
841
  for chunk in chunks:
808
842
  chunk_operator_output = await TheToolUtils.run_with_timeout(
@@ -833,9 +867,13 @@ class AsyncTheTool:
833
867
  analysis += chunk_operator_output.analysis
834
868
  if logprobs:
835
869
  logprobs_list.extend(chunk_operator_output.logprobs)
870
+ token_usage += chunk_operator_output.token_usage
836
871
 
837
872
  metadata = ToolOutputMetadata(
838
- tool_name=tool_name, execution_time=perf_counter() - start
873
+ tool_name=tool_name,
874
+ execution_time=perf_counter() - start,
875
+ processed_by=self.model,
876
+ token_usage=token_usage,
839
877
  )
840
878
  tool_output = ToolOutput(
841
879
  result=translation,
@@ -868,7 +906,10 @@ class AsyncTheTool:
868
906
  )
869
907
 
870
908
  metadata = ToolOutputMetadata(
871
- tool_name=tool_name, execution_time=perf_counter() - start
909
+ tool_name=tool_name,
910
+ execution_time=perf_counter() - start,
911
+ processed_by=self.model,
912
+ token_usage=operator_output.token_usage,
872
913
  )
873
914
  tool_output = ToolOutput(
874
915
  result=operator_output.result,
@@ -951,7 +992,10 @@ class AsyncTheTool:
951
992
  )
952
993
 
953
994
  metadata = ToolOutputMetadata(
954
- tool_name=tool_name, execution_time=perf_counter() - start
995
+ tool_name=tool_name,
996
+ execution_time=perf_counter() - start,
997
+ processed_by=self.model,
998
+ token_usage=operator_output.token_usage,
955
999
  )
956
1000
  tool_output = ToolOutput(
957
1001
  result=operator_output.result,
@@ -1037,7 +1081,10 @@ class AsyncTheTool:
1037
1081
  )
1038
1082
 
1039
1083
  metadata = ToolOutputMetadata(
1040
- tool_name=tool_name, execution_time=perf_counter() - start
1084
+ tool_name=tool_name,
1085
+ execution_time=perf_counter() - start,
1086
+ processed_by=self.model,
1087
+ token_usage=operator_output.token_usage,
1041
1088
  )
1042
1089
  tool_output = ToolOutput(
1043
1090
  result=operator_output.result,
@@ -1122,7 +1169,10 @@ class AsyncTheTool:
1122
1169
  )
1123
1170
 
1124
1171
  metadata = ToolOutputMetadata(
1125
- tool_name=tool_name, execution_time=perf_counter() - start
1172
+ tool_name=tool_name,
1173
+ execution_time=perf_counter() - start,
1174
+ processed_by=self.model,
1175
+ token_usage=operator_output.token_usage,
1126
1176
  )
1127
1177
  tool_output = ToolOutput(
1128
1178
  result=operator_output.result,