hamtaa-texttools 1.1.17__py3-none-any.whl → 1.1.18__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.
@@ -4,21 +4,20 @@ from collections.abc import Callable
4
4
 
5
5
  from openai import AsyncOpenAI
6
6
 
7
- from texttools.tools.internals.async_operator import AsyncOperator
8
- import texttools.tools.internals.models as Models
7
+ from texttools.internals.async_operator import AsyncOperator
8
+ import texttools.internals.models as Models
9
+ from texttools.internals.exceptions import (
10
+ TextToolsError,
11
+ PromptError,
12
+ LLMError,
13
+ ValidationError,
14
+ )
9
15
 
10
16
 
11
17
  class AsyncTheTool:
12
18
  """
13
- Async counterpart to TheTool.
14
-
15
- Each method configures the async operator with a specific YAML prompt,
19
+ Each method configures the operator with a specific YAML prompt,
16
20
  output schema, and flags, then delegates execution to `operator.run()`.
17
-
18
- Usage:
19
- async_client = AsyncOpenAI(...)
20
- tool = TheToolAsync(async_client, model="model-name")
21
- result = await tool.categorize("text ...", with_analysis=True)
22
21
  """
23
22
 
24
23
  def __init__(
@@ -66,42 +65,99 @@ class AsyncTheTool:
66
65
  - processed_at (datetime): Timestamp when the processing occurred
67
66
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
68
67
  - errors (list(str) | None): Errors occured during tool call
68
+
69
69
  """
70
- start = datetime.now()
71
-
72
- if mode == "category_tree":
73
- # Initializations
74
- output = Models.ToolOutput()
75
- levels = categories.get_level_count()
76
- parent_id = 0
77
- final_output = []
78
-
79
- for _ in range(levels):
80
- # Get child nodes for current parent
81
- parent_node = categories.get_node(parent_id)
82
- children = categories.get_children(parent_node)
83
-
84
- # Check if child nodes exist
85
- if not children:
86
- output.errors.append(
87
- f"No categories found for parent_id {parent_id} in the tree"
70
+ output = Models.ToolOutput()
71
+
72
+ try:
73
+ start = datetime.now()
74
+
75
+ if mode == "category_tree":
76
+ # Initializations
77
+ output = Models.ToolOutput()
78
+ levels = categories.get_level_count()
79
+ parent_id = 0
80
+ final_output = []
81
+
82
+ for _ in range(levels):
83
+ # Get child nodes for current parent
84
+ parent_node = categories.get_node(parent_id)
85
+ children = categories.get_children(parent_node)
86
+
87
+ # Check if child nodes exist
88
+ if not children:
89
+ output.errors.append(
90
+ f"No categories found for parent_id {parent_id} in the tree"
91
+ )
92
+ end = datetime.now()
93
+ output.execution_time = (end - start).total_seconds()
94
+ return output
95
+
96
+ # Extract category names and descriptions
97
+ category_list = [
98
+ f"Category Name: {node.name}, Description: {node.description}"
99
+ for node in children
100
+ ]
101
+ category_names = [node.name for node in children]
102
+
103
+ # Run categorization for this level
104
+ level_output = await self._operator.run(
105
+ # User parameters
106
+ text=text,
107
+ category_list=category_list,
108
+ with_analysis=with_analysis,
109
+ user_prompt=user_prompt,
110
+ temperature=temperature,
111
+ logprobs=logprobs,
112
+ top_logprobs=top_logprobs,
113
+ mode=mode,
114
+ validator=validator,
115
+ max_validation_retries=max_validation_retries,
116
+ priority=priority,
117
+ # Internal parameters
118
+ prompt_file="categorize.yaml",
119
+ output_model=Models.create_dynamic_model(category_names),
120
+ output_lang=None,
88
121
  )
89
- end = datetime.now()
90
- output.execution_time = (end - start).total_seconds()
91
- return output
92
-
93
- # Extract category names and descriptions
94
- category_list = [
95
- f"Category Name: {node.name}, Description: {node.description}"
96
- for node in children
97
- ]
98
- category_names = [node.name for node in children]
99
-
100
- # Run categorization for this level
101
- level_output = await self._operator.run(
122
+
123
+ # Check for errors from operator
124
+ if level_output.errors:
125
+ output.errors.extend(level_output.errors)
126
+ end = datetime.now()
127
+ output.execution_time = (end - start).total_seconds()
128
+ return output
129
+
130
+ # Get the chosen category
131
+ chosen_category = level_output.result
132
+
133
+ # Find the corresponding node
134
+ parent_node = categories.get_node(chosen_category)
135
+ if parent_node is None:
136
+ output.errors.append(
137
+ f"Category '{chosen_category}' not found in tree after selection"
138
+ )
139
+ end = datetime.now()
140
+ output.execution_time = (end - start).total_seconds()
141
+ return output
142
+
143
+ parent_id = parent_node.node_id
144
+ final_output.append(parent_node.name)
145
+
146
+ # Copy analysis/logprobs/process from the last level's output
147
+ output.analysis = level_output.analysis
148
+ output.logprobs = level_output.logprobs
149
+ output.process = level_output.process
150
+
151
+ output.result = final_output
152
+ end = datetime.now()
153
+ output.execution_time = (end - start).total_seconds()
154
+ return output
155
+
156
+ else:
157
+ output = await self._operator.run(
102
158
  # User parameters
103
159
  text=text,
104
- category_list=category_list,
160
+ category_list=categories,
105
161
  with_analysis=with_analysis,
106
162
  user_prompt=user_prompt,
107
163
  temperature=temperature,
@@ -110,66 +166,28 @@ class AsyncTheTool:
110
166
  mode=mode,
111
167
  validator=validator,
112
168
  max_validation_retries=max_validation_retries,
169
+ priority=priority,
113
170
  # Internal parameters
114
171
  prompt_file="categorize.yaml",
115
- output_model=Models.create_dynamic_model(category_names),
172
+ output_model=Models.create_dynamic_model(categories),
116
173
  output_lang=None,
117
174
  )
175
+ end = datetime.now()
176
+ output.execution_time = (end - start).total_seconds()
177
+ return output
118
178
 
119
- # Check for errors from operator
120
- if level_output.errors:
121
- output.errors.extend(level_output.errors)
122
- end = datetime.now()
123
- output.execution_time = (end - start).total_seconds()
124
- return output
125
-
126
- # Get the chosen category
127
- chosen_category = level_output.result
128
-
129
- # Find the corresponding node
130
- parent_node = categories.get_node(chosen_category)
131
- if parent_node is None:
132
- output.errors.append(
133
- f"Category '{chosen_category}' not found in tree after selection"
134
- )
135
- end = datetime.now()
136
- output.execution_time = (end - start).total_seconds()
137
- return output
179
+ except PromptError as e:
180
+ output.errors.append(f"Prompt error: {e}")
181
+ except LLMError as e:
182
+ output.errors.append(f"LLM error: {e}")
183
+ except ValidationError as e:
184
+ output.errors.append(f"Validation error: {e}")
185
+ except TextToolsError as e:
186
+ output.errors.append(f"TextTools error: {e}")
187
+ except Exception as e:
188
+ output.errors.append(f"Unexpected error: {e}")
138
189
 
139
- parent_id = parent_node.node_id
140
- final_output.append(parent_node.name)
141
-
142
- # Copy analysis/logprobs/process from the last level's output
143
- output.analysis = level_output.analysis
144
- output.logprobs = level_output.logprobs
145
- output.process = level_output.process
146
-
147
- output.result = final_output
148
- end = datetime.now()
149
- output.execution_time = (end - start).total_seconds()
150
- return output
151
-
152
- else:
153
- output = await self._operator.run(
154
- # User parameters
155
- text=text,
156
- category_list=categories,
157
- with_analysis=with_analysis,
158
- user_prompt=user_prompt,
159
- temperature=temperature,
160
- logprobs=logprobs,
161
- top_logprobs=top_logprobs,
162
- mode=mode,
163
- validator=validator,
164
- max_validation_retries=max_validation_retries,
165
- # Internal parameters
166
- prompt_file="categorize.yaml",
167
- output_model=Models.create_dynamic_model(categories),
168
- output_lang=None,
169
- )
170
- end = datetime.now()
171
- output.execution_time = (end - start).total_seconds()
172
- return output
190
+ return output
173
191
 
174
192
  async def extract_keywords(
175
193
  self,
@@ -211,27 +229,43 @@ class AsyncTheTool:
211
229
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
212
230
  - errors (list(str) | None): Errors occured during tool call
213
231
  """
214
- start = datetime.now()
215
- output = await self._operator.run(
216
- # User parameters
217
- text=text,
218
- with_analysis=with_analysis,
219
- output_lang=output_lang,
220
- user_prompt=user_prompt,
221
- temperature=temperature,
222
- logprobs=logprobs,
223
- top_logprobs=top_logprobs,
224
- mode=mode,
225
- number_of_keywords=number_of_keywords,
226
- validator=validator,
227
- max_validation_retries=max_validation_retries,
228
- priority=priority,
229
- # Internal parameters
230
- prompt_file="extract_keywords.yaml",
231
- output_model=Models.ListStrOutput,
232
- )
233
- end = datetime.now()
234
- output.execution_time = (end - start).total_seconds()
232
+ output = Models.ToolOutput()
233
+
234
+ try:
235
+ start = datetime.now()
236
+ output = await self._operator.run(
237
+ # User parameters
238
+ text=text,
239
+ with_analysis=with_analysis,
240
+ output_lang=output_lang,
241
+ user_prompt=user_prompt,
242
+ temperature=temperature,
243
+ logprobs=logprobs,
244
+ top_logprobs=top_logprobs,
245
+ mode=mode,
246
+ number_of_keywords=number_of_keywords,
247
+ validator=validator,
248
+ max_validation_retries=max_validation_retries,
249
+ priority=priority,
250
+ # Internal parameters
251
+ prompt_file="extract_keywords.yaml",
252
+ output_model=Models.ListStrOutput,
253
+ )
254
+ end = datetime.now()
255
+ output.execution_time = (end - start).total_seconds()
256
+ return output
257
+
258
+ except PromptError as e:
259
+ output.errors.append(f"Prompt error: {e}")
260
+ except LLMError as e:
261
+ output.errors.append(f"LLM error: {e}")
262
+ except ValidationError as e:
263
+ output.errors.append(f"Validation error: {e}")
264
+ except TextToolsError as e:
265
+ output.errors.append(f"TextTools error: {e}")
266
+ except Exception as e:
267
+ output.errors.append(f"Unexpected error: {e}")
268
+
235
269
  return output
236
270
 
237
271
  async def extract_entities(
@@ -272,26 +306,42 @@ class AsyncTheTool:
272
306
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
273
307
  - errors (list(str) | None): Errors occured during tool call
274
308
  """
275
- start = datetime.now()
276
- output = await self._operator.run(
277
- # User parameters
278
- text=text,
279
- with_analysis=with_analysis,
280
- output_lang=output_lang,
281
- user_prompt=user_prompt,
282
- temperature=temperature,
283
- logprobs=logprobs,
284
- top_logprobs=top_logprobs,
285
- validator=validator,
286
- max_validation_retries=max_validation_retries,
287
- priority=priority,
288
- # Internal parameters
289
- prompt_file="extract_entities.yaml",
290
- output_model=Models.ListDictStrStrOutput,
291
- mode=None,
292
- )
293
- end = datetime.now()
294
- output.execution_time = (end - start).total_seconds()
309
+ output = Models.ToolOutput()
310
+
311
+ try:
312
+ start = datetime.now()
313
+ output = await self._operator.run(
314
+ # User parameters
315
+ text=text,
316
+ with_analysis=with_analysis,
317
+ output_lang=output_lang,
318
+ user_prompt=user_prompt,
319
+ temperature=temperature,
320
+ logprobs=logprobs,
321
+ top_logprobs=top_logprobs,
322
+ validator=validator,
323
+ max_validation_retries=max_validation_retries,
324
+ priority=priority,
325
+ # Internal parameters
326
+ prompt_file="extract_entities.yaml",
327
+ output_model=Models.ListDictStrStrOutput,
328
+ mode=None,
329
+ )
330
+ end = datetime.now()
331
+ output.execution_time = (end - start).total_seconds()
332
+ return output
333
+
334
+ except PromptError as e:
335
+ output.errors.append(f"Prompt error: {e}")
336
+ except LLMError as e:
337
+ output.errors.append(f"LLM error: {e}")
338
+ except ValidationError as e:
339
+ output.errors.append(f"Validation error: {e}")
340
+ except TextToolsError as e:
341
+ output.errors.append(f"TextTools error: {e}")
342
+ except Exception as e:
343
+ output.errors.append(f"Unexpected error: {e}")
344
+
295
345
  return output
296
346
 
297
347
  async def is_question(
@@ -330,26 +380,42 @@ class AsyncTheTool:
330
380
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
331
381
  - errors (list(str) | None): Errors occured during tool call
332
382
  """
333
- start = datetime.now()
334
- output = await self._operator.run(
335
- # User parameters
336
- text=text,
337
- with_analysis=with_analysis,
338
- user_prompt=user_prompt,
339
- temperature=temperature,
340
- logprobs=logprobs,
341
- top_logprobs=top_logprobs,
342
- validator=validator,
343
- max_validation_retries=max_validation_retries,
344
- priority=priority,
345
- # Internal parameters
346
- prompt_file="is_question.yaml",
347
- output_model=Models.BoolOutput,
348
- mode=None,
349
- output_lang=None,
350
- )
351
- end = datetime.now()
352
- output.execution_time = (end - start).total_seconds()
383
+ output = Models.ToolOutput()
384
+
385
+ try:
386
+ start = datetime.now()
387
+ output = await self._operator.run(
388
+ # User parameters
389
+ text=text,
390
+ with_analysis=with_analysis,
391
+ user_prompt=user_prompt,
392
+ temperature=temperature,
393
+ logprobs=logprobs,
394
+ top_logprobs=top_logprobs,
395
+ validator=validator,
396
+ max_validation_retries=max_validation_retries,
397
+ priority=priority,
398
+ # Internal parameters
399
+ prompt_file="is_question.yaml",
400
+ output_model=Models.BoolOutput,
401
+ mode=None,
402
+ output_lang=None,
403
+ )
404
+ end = datetime.now()
405
+ output.execution_time = (end - start).total_seconds()
406
+ return output
407
+
408
+ except PromptError as e:
409
+ output.errors.append(f"Prompt error: {e}")
410
+ except LLMError as e:
411
+ output.errors.append(f"LLM error: {e}")
412
+ except ValidationError as e:
413
+ output.errors.append(f"Validation error: {e}")
414
+ except TextToolsError as e:
415
+ output.errors.append(f"TextTools error: {e}")
416
+ except Exception as e:
417
+ output.errors.append(f"Unexpected error: {e}")
418
+
353
419
  return output
354
420
 
355
421
  async def text_to_question(
@@ -390,26 +456,42 @@ class AsyncTheTool:
390
456
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
391
457
  - errors (list(str) | None): Errors occured during tool call
392
458
  """
393
- start = datetime.now()
394
- output = await self._operator.run(
395
- # User parameters
396
- text=text,
397
- with_analysis=with_analysis,
398
- output_lang=output_lang,
399
- user_prompt=user_prompt,
400
- temperature=temperature,
401
- logprobs=logprobs,
402
- top_logprobs=top_logprobs,
403
- validator=validator,
404
- max_validation_retries=max_validation_retries,
405
- priority=priority,
406
- # Internal parameters
407
- prompt_file="text_to_question.yaml",
408
- output_model=Models.StrOutput,
409
- mode=None,
410
- )
411
- end = datetime.now()
412
- output.execution_time = (end - start).total_seconds()
459
+ output = Models.ToolOutput()
460
+
461
+ try:
462
+ start = datetime.now()
463
+ output = await self._operator.run(
464
+ # User parameters
465
+ text=text,
466
+ with_analysis=with_analysis,
467
+ output_lang=output_lang,
468
+ user_prompt=user_prompt,
469
+ temperature=temperature,
470
+ logprobs=logprobs,
471
+ top_logprobs=top_logprobs,
472
+ validator=validator,
473
+ max_validation_retries=max_validation_retries,
474
+ priority=priority,
475
+ # Internal parameters
476
+ prompt_file="text_to_question.yaml",
477
+ output_model=Models.StrOutput,
478
+ mode=None,
479
+ )
480
+ end = datetime.now()
481
+ output.execution_time = (end - start).total_seconds()
482
+ return output
483
+
484
+ except PromptError as e:
485
+ output.errors.append(f"Prompt error: {e}")
486
+ except LLMError as e:
487
+ output.errors.append(f"LLM error: {e}")
488
+ except ValidationError as e:
489
+ output.errors.append(f"Validation error: {e}")
490
+ except TextToolsError as e:
491
+ output.errors.append(f"TextTools error: {e}")
492
+ except Exception as e:
493
+ output.errors.append(f"Unexpected error: {e}")
494
+
413
495
  return output
414
496
 
415
497
  async def merge_questions(
@@ -452,27 +534,43 @@ class AsyncTheTool:
452
534
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
453
535
  - errors (list(str) | None): Errors occured during tool call
454
536
  """
455
- start = datetime.now()
456
- text_combined = ", ".join(text)
457
- output = await self._operator.run(
458
- # User parameters
459
- text=text_combined,
460
- with_analysis=with_analysis,
461
- output_lang=output_lang,
462
- user_prompt=user_prompt,
463
- temperature=temperature,
464
- logprobs=logprobs,
465
- top_logprobs=top_logprobs,
466
- validator=validator,
467
- max_validation_retries=max_validation_retries,
468
- priority=priority,
469
- # Internal parameters
470
- prompt_file="merge_questions.yaml",
471
- output_model=Models.StrOutput,
472
- mode=mode,
473
- )
474
- end = datetime.now()
475
- output.execution_time = (end - start).total_seconds()
537
+ output = Models.ToolOutput()
538
+
539
+ try:
540
+ start = datetime.now()
541
+ text = ", ".join(text)
542
+ output = await self._operator.run(
543
+ # User parameters
544
+ text=text,
545
+ with_analysis=with_analysis,
546
+ output_lang=output_lang,
547
+ user_prompt=user_prompt,
548
+ temperature=temperature,
549
+ logprobs=logprobs,
550
+ top_logprobs=top_logprobs,
551
+ validator=validator,
552
+ max_validation_retries=max_validation_retries,
553
+ priority=priority,
554
+ # Internal parameters
555
+ prompt_file="merge_questions.yaml",
556
+ output_model=Models.StrOutput,
557
+ mode=mode,
558
+ )
559
+ end = datetime.now()
560
+ output.execution_time = (end - start).total_seconds()
561
+ return output
562
+
563
+ except PromptError as e:
564
+ output.errors.append(f"Prompt error: {e}")
565
+ except LLMError as e:
566
+ output.errors.append(f"LLM error: {e}")
567
+ except ValidationError as e:
568
+ output.errors.append(f"Validation error: {e}")
569
+ except TextToolsError as e:
570
+ output.errors.append(f"TextTools error: {e}")
571
+ except Exception as e:
572
+ output.errors.append(f"Unexpected error: {e}")
573
+
476
574
  return output
477
575
 
478
576
  async def rewrite(
@@ -515,26 +613,42 @@ class AsyncTheTool:
515
613
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
516
614
  - errors (list(str) | None): Errors occured during tool call
517
615
  """
518
- start = datetime.now()
519
- output = await self._operator.run(
520
- # User parameters
521
- text=text,
522
- with_analysis=with_analysis,
523
- output_lang=output_lang,
524
- user_prompt=user_prompt,
525
- temperature=temperature,
526
- logprobs=logprobs,
527
- top_logprobs=top_logprobs,
528
- validator=validator,
529
- max_validation_retries=max_validation_retries,
530
- priority=priority,
531
- # Internal parameters
532
- prompt_file="rewrite.yaml",
533
- output_model=Models.StrOutput,
534
- mode=mode,
535
- )
536
- end = datetime.now()
537
- output.execution_time = (end - start).total_seconds()
616
+ output = Models.ToolOutput()
617
+
618
+ try:
619
+ start = datetime.now()
620
+ output = await self._operator.run(
621
+ # User parameters
622
+ text=text,
623
+ with_analysis=with_analysis,
624
+ output_lang=output_lang,
625
+ user_prompt=user_prompt,
626
+ temperature=temperature,
627
+ logprobs=logprobs,
628
+ top_logprobs=top_logprobs,
629
+ validator=validator,
630
+ max_validation_retries=max_validation_retries,
631
+ priority=priority,
632
+ # Internal parameters
633
+ prompt_file="rewrite.yaml",
634
+ output_model=Models.StrOutput,
635
+ mode=mode,
636
+ )
637
+ end = datetime.now()
638
+ output.execution_time = (end - start).total_seconds()
639
+ return output
640
+
641
+ except PromptError as e:
642
+ output.errors.append(f"Prompt error: {e}")
643
+ except LLMError as e:
644
+ output.errors.append(f"LLM error: {e}")
645
+ except ValidationError as e:
646
+ output.errors.append(f"Validation error: {e}")
647
+ except TextToolsError as e:
648
+ output.errors.append(f"TextTools error: {e}")
649
+ except Exception as e:
650
+ output.errors.append(f"Unexpected error: {e}")
651
+
538
652
  return output
539
653
 
540
654
  async def subject_to_question(
@@ -577,27 +691,43 @@ class AsyncTheTool:
577
691
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
578
692
  - errors (list(str) | None): Errors occured during tool call
579
693
  """
580
- start = datetime.now()
581
- output = await self._operator.run(
582
- # User parameters
583
- text=text,
584
- number_of_questions=number_of_questions,
585
- with_analysis=with_analysis,
586
- output_lang=output_lang,
587
- user_prompt=user_prompt,
588
- temperature=temperature,
589
- logprobs=logprobs,
590
- top_logprobs=top_logprobs,
591
- validator=validator,
592
- max_validation_retries=max_validation_retries,
593
- priority=priority,
594
- # Internal parameters
595
- prompt_file="subject_to_question.yaml",
596
- output_model=Models.ReasonListStrOutput,
597
- mode=None,
598
- )
599
- end = datetime.now()
600
- output.execution_time = (end - start).total_seconds()
694
+ output = Models.ToolOutput()
695
+
696
+ try:
697
+ start = datetime.now()
698
+ output = await self._operator.run(
699
+ # User parameters
700
+ text=text,
701
+ number_of_questions=number_of_questions,
702
+ with_analysis=with_analysis,
703
+ output_lang=output_lang,
704
+ user_prompt=user_prompt,
705
+ temperature=temperature,
706
+ logprobs=logprobs,
707
+ top_logprobs=top_logprobs,
708
+ validator=validator,
709
+ max_validation_retries=max_validation_retries,
710
+ priority=priority,
711
+ # Internal parameters
712
+ prompt_file="subject_to_question.yaml",
713
+ output_model=Models.ReasonListStrOutput,
714
+ mode=None,
715
+ )
716
+ end = datetime.now()
717
+ output.execution_time = (end - start).total_seconds()
718
+ return output
719
+
720
+ except PromptError as e:
721
+ output.errors.append(f"Prompt error: {e}")
722
+ except LLMError as e:
723
+ output.errors.append(f"LLM error: {e}")
724
+ except ValidationError as e:
725
+ output.errors.append(f"Validation error: {e}")
726
+ except TextToolsError as e:
727
+ output.errors.append(f"TextTools error: {e}")
728
+ except Exception as e:
729
+ output.errors.append(f"Unexpected error: {e}")
730
+
601
731
  return output
602
732
 
603
733
  async def summarize(
@@ -638,26 +768,42 @@ class AsyncTheTool:
638
768
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
639
769
  - errors (list(str) | None): Errors occured during tool call
640
770
  """
641
- start = datetime.now()
642
- output = await self._operator.run(
643
- # User parameters
644
- text=text,
645
- with_analysis=with_analysis,
646
- output_lang=output_lang,
647
- user_prompt=user_prompt,
648
- temperature=temperature,
649
- logprobs=logprobs,
650
- top_logprobs=top_logprobs,
651
- validator=validator,
652
- max_validation_retries=max_validation_retries,
653
- priority=priority,
654
- # Internal parameters
655
- prompt_file="summarize.yaml",
656
- output_model=Models.StrOutput,
657
- mode=None,
658
- )
659
- end = datetime.now()
660
- output.execution_time = (end - start).total_seconds()
771
+ output = Models.ToolOutput()
772
+
773
+ try:
774
+ start = datetime.now()
775
+ output = await self._operator.run(
776
+ # User parameters
777
+ text=text,
778
+ with_analysis=with_analysis,
779
+ output_lang=output_lang,
780
+ user_prompt=user_prompt,
781
+ temperature=temperature,
782
+ logprobs=logprobs,
783
+ top_logprobs=top_logprobs,
784
+ validator=validator,
785
+ max_validation_retries=max_validation_retries,
786
+ priority=priority,
787
+ # Internal parameters
788
+ prompt_file="summarize.yaml",
789
+ output_model=Models.StrOutput,
790
+ mode=None,
791
+ )
792
+ end = datetime.now()
793
+ output.execution_time = (end - start).total_seconds()
794
+ return output
795
+
796
+ except PromptError as e:
797
+ output.errors.append(f"Prompt error: {e}")
798
+ except LLMError as e:
799
+ output.errors.append(f"LLM error: {e}")
800
+ except ValidationError as e:
801
+ output.errors.append(f"Validation error: {e}")
802
+ except TextToolsError as e:
803
+ output.errors.append(f"TextTools error: {e}")
804
+ except Exception as e:
805
+ output.errors.append(f"Unexpected error: {e}")
806
+
661
807
  return output
662
808
 
663
809
  async def translate(
@@ -698,27 +844,43 @@ class AsyncTheTool:
698
844
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
699
845
  - errors (list(str) | None): Errors occured during tool call
700
846
  """
701
- start = datetime.now()
702
- output = await self._operator.run(
703
- # User parameters
704
- text=text,
705
- target_language=target_language,
706
- with_analysis=with_analysis,
707
- user_prompt=user_prompt,
708
- temperature=temperature,
709
- logprobs=logprobs,
710
- top_logprobs=top_logprobs,
711
- validator=validator,
712
- max_validation_retries=max_validation_retries,
713
- priority=priority,
714
- # Internal parameters
715
- prompt_file="translate.yaml",
716
- output_model=Models.StrOutput,
717
- mode=None,
718
- output_lang=None,
719
- )
720
- end = datetime.now()
721
- output.execution_time = (end - start).total_seconds()
847
+ output = Models.ToolOutput()
848
+
849
+ try:
850
+ start = datetime.now()
851
+ output = await self._operator.run(
852
+ # User parameters
853
+ text=text,
854
+ target_language=target_language,
855
+ with_analysis=with_analysis,
856
+ user_prompt=user_prompt,
857
+ temperature=temperature,
858
+ logprobs=logprobs,
859
+ top_logprobs=top_logprobs,
860
+ validator=validator,
861
+ max_validation_retries=max_validation_retries,
862
+ priority=priority,
863
+ # Internal parameters
864
+ prompt_file="translate.yaml",
865
+ output_model=Models.StrOutput,
866
+ mode=None,
867
+ output_lang=None,
868
+ )
869
+ end = datetime.now()
870
+ output.execution_time = (end - start).total_seconds()
871
+ return output
872
+
873
+ except PromptError as e:
874
+ output.errors.append(f"Prompt error: {e}")
875
+ except LLMError as e:
876
+ output.errors.append(f"LLM error: {e}")
877
+ except ValidationError as e:
878
+ output.errors.append(f"Validation error: {e}")
879
+ except TextToolsError as e:
880
+ output.errors.append(f"TextTools error: {e}")
881
+ except Exception as e:
882
+ output.errors.append(f"Unexpected error: {e}")
883
+
722
884
  return output
723
885
 
724
886
  async def detect_entity(
@@ -759,26 +921,42 @@ class AsyncTheTool:
759
921
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
760
922
  - errors (list(str) | None): Errors occured during tool call
761
923
  """
762
- start = datetime.now()
763
- output = await self._operator.run(
764
- # User parameters
765
- text=text,
766
- with_analysis=with_analysis,
767
- output_lang=output_lang,
768
- user_prompt=user_prompt,
769
- temperature=temperature,
770
- logprobs=logprobs,
771
- top_logprobs=top_logprobs,
772
- validator=validator,
773
- max_validation_retries=max_validation_retries,
774
- priority=priority,
775
- # Internal parameters
776
- prompt_file="detect_entity.yaml",
777
- output_model=Models.EntityDetectorOutput,
778
- mode=None,
779
- )
780
- end = datetime.now()
781
- output.execution_time = (end - start).total_seconds()
924
+ output = Models.ToolOutput()
925
+
926
+ try:
927
+ start = datetime.now()
928
+ output = await self._operator.run(
929
+ # User parameters
930
+ text=text,
931
+ with_analysis=with_analysis,
932
+ output_lang=output_lang,
933
+ user_prompt=user_prompt,
934
+ temperature=temperature,
935
+ logprobs=logprobs,
936
+ top_logprobs=top_logprobs,
937
+ validator=validator,
938
+ max_validation_retries=max_validation_retries,
939
+ priority=priority,
940
+ # Internal parameters
941
+ prompt_file="detect_entity.yaml",
942
+ output_model=Models.EntityDetectorOutput,
943
+ mode=None,
944
+ )
945
+ end = datetime.now()
946
+ output.execution_time = (end - start).total_seconds()
947
+ return output
948
+
949
+ except PromptError as e:
950
+ output.errors.append(f"Prompt error: {e}")
951
+ except LLMError as e:
952
+ output.errors.append(f"LLM error: {e}")
953
+ except ValidationError as e:
954
+ output.errors.append(f"Validation error: {e}")
955
+ except TextToolsError as e:
956
+ output.errors.append(f"TextTools error: {e}")
957
+ except Exception as e:
958
+ output.errors.append(f"Unexpected error: {e}")
959
+
782
960
  return output
783
961
 
784
962
  async def propositionize(
@@ -819,26 +997,42 @@ class AsyncTheTool:
819
997
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
820
998
  - errors (list(str) | None): Errors occured during tool call
821
999
  """
822
- start = datetime.now()
823
- output = await self._operator.run(
824
- # User parameters
825
- text=text,
826
- with_analysis=with_analysis,
827
- output_lang=output_lang,
828
- user_prompt=user_prompt,
829
- temperature=temperature,
830
- logprobs=logprobs,
831
- top_logprobs=top_logprobs,
832
- validator=validator,
833
- max_validation_retries=max_validation_retries,
834
- priority=priority,
835
- # Internal parameters
836
- prompt_file="propositionize.yaml",
837
- output_model=Models.ListStrOutput,
838
- mode=None,
839
- )
840
- end = datetime.now()
841
- output.execution_time = (end - start).total_seconds()
1000
+ output = Models.ToolOutput()
1001
+
1002
+ try:
1003
+ start = datetime.now()
1004
+ output = await self._operator.run(
1005
+ # User parameters
1006
+ text=text,
1007
+ with_analysis=with_analysis,
1008
+ output_lang=output_lang,
1009
+ user_prompt=user_prompt,
1010
+ temperature=temperature,
1011
+ logprobs=logprobs,
1012
+ top_logprobs=top_logprobs,
1013
+ validator=validator,
1014
+ max_validation_retries=max_validation_retries,
1015
+ priority=priority,
1016
+ # Internal parameters
1017
+ prompt_file="propositionize.yaml",
1018
+ output_model=Models.ListStrOutput,
1019
+ mode=None,
1020
+ )
1021
+ end = datetime.now()
1022
+ output.execution_time = (end - start).total_seconds()
1023
+ return output
1024
+
1025
+ except PromptError as e:
1026
+ output.errors.append(f"Prompt error: {e}")
1027
+ except LLMError as e:
1028
+ output.errors.append(f"LLM error: {e}")
1029
+ except ValidationError as e:
1030
+ output.errors.append(f"Validation error: {e}")
1031
+ except TextToolsError as e:
1032
+ output.errors.append(f"TextTools error: {e}")
1033
+ except Exception as e:
1034
+ output.errors.append(f"Unexpected error: {e}")
1035
+
842
1036
  return output
843
1037
 
844
1038
  async def run_custom(
@@ -876,25 +1070,41 @@ class AsyncTheTool:
876
1070
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
877
1071
  - errors (list(str) | None): Errors occured during tool call
878
1072
  """
879
- start = datetime.now()
880
- output = await self._operator.run(
881
- # User paramaeters
882
- text=prompt,
883
- output_model=output_model,
884
- output_model_str=output_model.model_json_schema(),
885
- output_lang=output_lang,
886
- temperature=temperature,
887
- logprobs=logprobs,
888
- top_logprobs=top_logprobs,
889
- validator=validator,
890
- max_validation_retries=max_validation_retries,
891
- priority=priority,
892
- # Internal parameters
893
- prompt_file="run_custom.yaml",
894
- user_prompt=None,
895
- with_analysis=False,
896
- mode=None,
897
- )
898
- end = datetime.now()
899
- output.execution_time = (end - start).total_seconds()
1073
+ output = Models.ToolOutput()
1074
+
1075
+ try:
1076
+ start = datetime.now()
1077
+ output = await self._operator.run(
1078
+ # User paramaeters
1079
+ text=prompt,
1080
+ output_model=output_model,
1081
+ output_model_str=output_model.model_json_schema(),
1082
+ output_lang=output_lang,
1083
+ temperature=temperature,
1084
+ logprobs=logprobs,
1085
+ top_logprobs=top_logprobs,
1086
+ validator=validator,
1087
+ max_validation_retries=max_validation_retries,
1088
+ priority=priority,
1089
+ # Internal parameters
1090
+ prompt_file="run_custom.yaml",
1091
+ user_prompt=None,
1092
+ with_analysis=False,
1093
+ mode=None,
1094
+ )
1095
+ end = datetime.now()
1096
+ output.execution_time = (end - start).total_seconds()
1097
+ return output
1098
+
1099
+ except PromptError as e:
1100
+ output.errors.append(f"Prompt error: {e}")
1101
+ except LLMError as e:
1102
+ output.errors.append(f"LLM error: {e}")
1103
+ except ValidationError as e:
1104
+ output.errors.append(f"Validation error: {e}")
1105
+ except TextToolsError as e:
1106
+ output.errors.append(f"TextTools error: {e}")
1107
+ except Exception as e:
1108
+ output.errors.append(f"Unexpected error: {e}")
1109
+
900
1110
  return output