hamtaa-texttools 1.1.17__py3-none-any.whl → 1.1.19__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,19 +4,20 @@ from collections.abc import Callable
4
4
 
5
5
  from openai import OpenAI
6
6
 
7
- from texttools.tools.internals.sync_operator import Operator
8
- import texttools.tools.internals.models as Models
7
+ from texttools.internals.sync_operator import Operator
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 TheTool:
12
18
  """
13
19
  Each method configures the operator with a specific YAML prompt,
14
20
  output schema, and flags, then delegates execution to `operator.run()`.
15
-
16
- Usage:
17
- client = OpenAI(...)
18
- tool = TheTool(client, model="model-name")
19
- result = tool.categorize("text ...", with_analysis=True)
20
21
  """
21
22
 
22
23
  def __init__(
@@ -43,6 +44,8 @@ class TheTool:
43
44
  """
44
45
  Categorize a text into a category / category tree.
45
46
 
47
+ Important Note: category_tree mode is EXPERIMENTAL, you can use it but it isn't reliable.
48
+
46
49
  Arguments:
47
50
  text: The input text to categorize
48
51
  categories: The category / category_tree to give to LLM
@@ -66,41 +69,97 @@ class TheTool:
66
69
  - errors (list(str) | None): Errors occured during tool call
67
70
 
68
71
  """
69
- start = datetime.now()
70
-
71
- if mode == "category_tree":
72
- # Initializations
73
- output = Models.ToolOutput()
74
- levels = categories.get_level_count()
75
- parent_id = 0
76
- final_output = []
77
-
78
- for _ in range(levels):
79
- # Get child nodes for current parent
80
- parent_node = categories.get_node(parent_id)
81
- children = categories.get_children(parent_node)
82
-
83
- # Check if child nodes exist
84
- if not children:
85
- output.errors.append(
86
- f"No categories found for parent_id {parent_id} in the tree"
72
+ output = Models.ToolOutput()
73
+
74
+ try:
75
+ start = datetime.now()
76
+
77
+ if mode == "category_tree":
78
+ # Initializations
79
+ output = Models.ToolOutput()
80
+ levels = categories.get_level_count()
81
+ parent_id = 0
82
+ final_output = []
83
+
84
+ for _ in range(levels):
85
+ # Get child nodes for current parent
86
+ parent_node = categories.get_node(parent_id)
87
+ children = categories.get_children(parent_node)
88
+
89
+ # Check if child nodes exist
90
+ if not children:
91
+ output.errors.append(
92
+ f"No categories found for parent_id {parent_id} in the tree"
93
+ )
94
+ end = datetime.now()
95
+ output.execution_time = (end - start).total_seconds()
96
+ return output
97
+
98
+ # Extract category names and descriptions
99
+ category_list = [
100
+ f"Category Name: {node.name}, Description: {node.description}"
101
+ for node in children
102
+ ]
103
+ category_names = [node.name for node in children]
104
+
105
+ # Run categorization for this level
106
+ level_output = self._operator.run(
107
+ # User parameters
108
+ text=text,
109
+ category_list=category_list,
110
+ with_analysis=with_analysis,
111
+ user_prompt=user_prompt,
112
+ temperature=temperature,
113
+ logprobs=logprobs,
114
+ top_logprobs=top_logprobs,
115
+ mode=mode,
116
+ validator=validator,
117
+ max_validation_retries=max_validation_retries,
118
+ priority=priority,
119
+ # Internal parameters
120
+ prompt_file="categorize.yaml",
121
+ output_model=Models.create_dynamic_model(category_names),
122
+ output_lang=None,
87
123
  )
88
- end = datetime.now()
89
- output.execution_time = (end - start).total_seconds()
90
- return output
91
-
92
- # Extract category names and descriptions
93
- category_list = [
94
- f"Category Name: {node.name}, Description: {node.description}"
95
- for node in children
96
- ]
97
- category_names = [node.name for node in children]
98
-
99
- # Run categorization for this level
100
- level_output = self._operator.run(
124
+
125
+ # Check for errors from operator
126
+ if level_output.errors:
127
+ output.errors.extend(level_output.errors)
128
+ end = datetime.now()
129
+ output.execution_time = (end - start).total_seconds()
130
+ return output
131
+
132
+ # Get the chosen category
133
+ chosen_category = level_output.result
134
+
135
+ # Find the corresponding node
136
+ parent_node = categories.get_node(chosen_category)
137
+ if parent_node is None:
138
+ output.errors.append(
139
+ f"Category '{chosen_category}' not found in tree after selection"
140
+ )
141
+ end = datetime.now()
142
+ output.execution_time = (end - start).total_seconds()
143
+ return output
144
+
145
+ parent_id = parent_node.node_id
146
+ final_output.append(parent_node.name)
147
+
148
+ # Copy analysis/logprobs/process from the last level's output
149
+ output.analysis = level_output.analysis
150
+ output.logprobs = level_output.logprobs
151
+ output.process = level_output.process
152
+
153
+ output.result = final_output
154
+ end = datetime.now()
155
+ output.execution_time = (end - start).total_seconds()
156
+ return output
157
+
158
+ else:
159
+ output = self._operator.run(
101
160
  # User parameters
102
161
  text=text,
103
- category_list=category_list,
162
+ category_list=categories,
104
163
  with_analysis=with_analysis,
105
164
  user_prompt=user_prompt,
106
165
  temperature=temperature,
@@ -112,65 +171,25 @@ class TheTool:
112
171
  priority=priority,
113
172
  # Internal parameters
114
173
  prompt_file="categorize.yaml",
115
- output_model=Models.create_dynamic_model(category_names),
174
+ output_model=Models.create_dynamic_model(categories),
116
175
  output_lang=None,
117
176
  )
177
+ end = datetime.now()
178
+ output.execution_time = (end - start).total_seconds()
179
+ return output
118
180
 
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
138
-
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
181
+ except PromptError as e:
182
+ output.errors.append(f"Prompt error: {e}")
183
+ except LLMError as e:
184
+ output.errors.append(f"LLM error: {e}")
185
+ except ValidationError as e:
186
+ output.errors.append(f"Validation error: {e}")
187
+ except TextToolsError as e:
188
+ output.errors.append(f"TextTools error: {e}")
189
+ except Exception as e:
190
+ output.errors.append(f"Unexpected error: {e}")
146
191
 
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 = 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
- priority=priority,
166
- # Internal parameters
167
- prompt_file="categorize.yaml",
168
- output_model=Models.create_dynamic_model(categories),
169
- output_lang=None,
170
- )
171
- end = datetime.now()
172
- output.execution_time = (end - start).total_seconds()
173
- return output
192
+ return output
174
193
 
175
194
  def extract_keywords(
176
195
  self,
@@ -212,27 +231,43 @@ class TheTool:
212
231
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
213
232
  - errors (list(str) | None): Errors occured during tool call
214
233
  """
215
- start = datetime.now()
216
- output = self._operator.run(
217
- # User parameters
218
- text=text,
219
- with_analysis=with_analysis,
220
- output_lang=output_lang,
221
- user_prompt=user_prompt,
222
- temperature=temperature,
223
- logprobs=logprobs,
224
- top_logprobs=top_logprobs,
225
- mode=mode,
226
- number_of_keywords=number_of_keywords,
227
- validator=validator,
228
- max_validation_retries=max_validation_retries,
229
- priority=priority,
230
- # Internal parameters
231
- prompt_file="extract_keywords.yaml",
232
- output_model=Models.ListStrOutput,
233
- )
234
- end = datetime.now()
235
- output.execution_time = (end - start).total_seconds()
234
+ output = Models.ToolOutput()
235
+
236
+ try:
237
+ start = datetime.now()
238
+ output = self._operator.run(
239
+ # User parameters
240
+ text=text,
241
+ with_analysis=with_analysis,
242
+ output_lang=output_lang,
243
+ user_prompt=user_prompt,
244
+ temperature=temperature,
245
+ logprobs=logprobs,
246
+ top_logprobs=top_logprobs,
247
+ mode=mode,
248
+ number_of_keywords=number_of_keywords,
249
+ validator=validator,
250
+ max_validation_retries=max_validation_retries,
251
+ priority=priority,
252
+ # Internal parameters
253
+ prompt_file="extract_keywords.yaml",
254
+ output_model=Models.ListStrOutput,
255
+ )
256
+ end = datetime.now()
257
+ output.execution_time = (end - start).total_seconds()
258
+ return output
259
+
260
+ except PromptError as e:
261
+ output.errors.append(f"Prompt error: {e}")
262
+ except LLMError as e:
263
+ output.errors.append(f"LLM error: {e}")
264
+ except ValidationError as e:
265
+ output.errors.append(f"Validation error: {e}")
266
+ except TextToolsError as e:
267
+ output.errors.append(f"TextTools error: {e}")
268
+ except Exception as e:
269
+ output.errors.append(f"Unexpected error: {e}")
270
+
236
271
  return output
237
272
 
238
273
  def extract_entities(
@@ -273,26 +308,42 @@ class TheTool:
273
308
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
274
309
  - errors (list(str) | None): Errors occured during tool call
275
310
  """
276
- start = datetime.now()
277
- output = self._operator.run(
278
- # User parameters
279
- text=text,
280
- with_analysis=with_analysis,
281
- output_lang=output_lang,
282
- user_prompt=user_prompt,
283
- temperature=temperature,
284
- logprobs=logprobs,
285
- top_logprobs=top_logprobs,
286
- validator=validator,
287
- max_validation_retries=max_validation_retries,
288
- priority=priority,
289
- # Internal parameters
290
- prompt_file="extract_entities.yaml",
291
- output_model=Models.ListDictStrStrOutput,
292
- mode=None,
293
- )
294
- end = datetime.now()
295
- output.execution_time = (end - start).total_seconds()
311
+ output = Models.ToolOutput()
312
+
313
+ try:
314
+ start = datetime.now()
315
+ output = self._operator.run(
316
+ # User parameters
317
+ text=text,
318
+ with_analysis=with_analysis,
319
+ output_lang=output_lang,
320
+ user_prompt=user_prompt,
321
+ temperature=temperature,
322
+ logprobs=logprobs,
323
+ top_logprobs=top_logprobs,
324
+ validator=validator,
325
+ max_validation_retries=max_validation_retries,
326
+ priority=priority,
327
+ # Internal parameters
328
+ prompt_file="extract_entities.yaml",
329
+ output_model=Models.ListDictStrStrOutput,
330
+ mode=None,
331
+ )
332
+ end = datetime.now()
333
+ output.execution_time = (end - start).total_seconds()
334
+ return output
335
+
336
+ except PromptError as e:
337
+ output.errors.append(f"Prompt error: {e}")
338
+ except LLMError as e:
339
+ output.errors.append(f"LLM error: {e}")
340
+ except ValidationError as e:
341
+ output.errors.append(f"Validation error: {e}")
342
+ except TextToolsError as e:
343
+ output.errors.append(f"TextTools error: {e}")
344
+ except Exception as e:
345
+ output.errors.append(f"Unexpected error: {e}")
346
+
296
347
  return output
297
348
 
298
349
  def is_question(
@@ -331,26 +382,42 @@ class TheTool:
331
382
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
332
383
  - errors (list(str) | None): Errors occured during tool call
333
384
  """
334
- start = datetime.now()
335
- output = self._operator.run(
336
- # User parameters
337
- text=text,
338
- with_analysis=with_analysis,
339
- user_prompt=user_prompt,
340
- temperature=temperature,
341
- logprobs=logprobs,
342
- top_logprobs=top_logprobs,
343
- validator=validator,
344
- max_validation_retries=max_validation_retries,
345
- priority=priority,
346
- # Internal parameters
347
- prompt_file="is_question.yaml",
348
- output_model=Models.BoolOutput,
349
- mode=None,
350
- output_lang=None,
351
- )
352
- end = datetime.now()
353
- output.execution_time = (end - start).total_seconds()
385
+ output = Models.ToolOutput()
386
+
387
+ try:
388
+ start = datetime.now()
389
+ output = self._operator.run(
390
+ # User parameters
391
+ text=text,
392
+ with_analysis=with_analysis,
393
+ user_prompt=user_prompt,
394
+ temperature=temperature,
395
+ logprobs=logprobs,
396
+ top_logprobs=top_logprobs,
397
+ validator=validator,
398
+ max_validation_retries=max_validation_retries,
399
+ priority=priority,
400
+ # Internal parameters
401
+ prompt_file="is_question.yaml",
402
+ output_model=Models.BoolOutput,
403
+ mode=None,
404
+ output_lang=None,
405
+ )
406
+ end = datetime.now()
407
+ output.execution_time = (end - start).total_seconds()
408
+ return output
409
+
410
+ except PromptError as e:
411
+ output.errors.append(f"Prompt error: {e}")
412
+ except LLMError as e:
413
+ output.errors.append(f"LLM error: {e}")
414
+ except ValidationError as e:
415
+ output.errors.append(f"Validation error: {e}")
416
+ except TextToolsError as e:
417
+ output.errors.append(f"TextTools error: {e}")
418
+ except Exception as e:
419
+ output.errors.append(f"Unexpected error: {e}")
420
+
354
421
  return output
355
422
 
356
423
  def text_to_question(
@@ -391,26 +458,42 @@ class TheTool:
391
458
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
392
459
  - errors (list(str) | None): Errors occured during tool call
393
460
  """
394
- start = datetime.now()
395
- output = self._operator.run(
396
- # User parameters
397
- text=text,
398
- with_analysis=with_analysis,
399
- output_lang=output_lang,
400
- user_prompt=user_prompt,
401
- temperature=temperature,
402
- logprobs=logprobs,
403
- top_logprobs=top_logprobs,
404
- validator=validator,
405
- max_validation_retries=max_validation_retries,
406
- priority=priority,
407
- # Internal parameters
408
- prompt_file="text_to_question.yaml",
409
- output_model=Models.StrOutput,
410
- mode=None,
411
- )
412
- end = datetime.now()
413
- output.execution_time = (end - start).total_seconds()
461
+ output = Models.ToolOutput()
462
+
463
+ try:
464
+ start = datetime.now()
465
+ output = self._operator.run(
466
+ # User parameters
467
+ text=text,
468
+ with_analysis=with_analysis,
469
+ output_lang=output_lang,
470
+ user_prompt=user_prompt,
471
+ temperature=temperature,
472
+ logprobs=logprobs,
473
+ top_logprobs=top_logprobs,
474
+ validator=validator,
475
+ max_validation_retries=max_validation_retries,
476
+ priority=priority,
477
+ # Internal parameters
478
+ prompt_file="text_to_question.yaml",
479
+ output_model=Models.StrOutput,
480
+ mode=None,
481
+ )
482
+ end = datetime.now()
483
+ output.execution_time = (end - start).total_seconds()
484
+ return output
485
+
486
+ except PromptError as e:
487
+ output.errors.append(f"Prompt error: {e}")
488
+ except LLMError as e:
489
+ output.errors.append(f"LLM error: {e}")
490
+ except ValidationError as e:
491
+ output.errors.append(f"Validation error: {e}")
492
+ except TextToolsError as e:
493
+ output.errors.append(f"TextTools error: {e}")
494
+ except Exception as e:
495
+ output.errors.append(f"Unexpected error: {e}")
496
+
414
497
  return output
415
498
 
416
499
  def merge_questions(
@@ -453,27 +536,43 @@ class TheTool:
453
536
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
454
537
  - errors (list(str) | None): Errors occured during tool call
455
538
  """
456
- start = datetime.now()
457
- text = ", ".join(text)
458
- output = self._operator.run(
459
- # User parameters
460
- text=text,
461
- with_analysis=with_analysis,
462
- output_lang=output_lang,
463
- user_prompt=user_prompt,
464
- temperature=temperature,
465
- logprobs=logprobs,
466
- top_logprobs=top_logprobs,
467
- validator=validator,
468
- max_validation_retries=max_validation_retries,
469
- priority=priority,
470
- # Internal parameters
471
- prompt_file="merge_questions.yaml",
472
- output_model=Models.StrOutput,
473
- mode=mode,
474
- )
475
- end = datetime.now()
476
- output.execution_time = (end - start).total_seconds()
539
+ output = Models.ToolOutput()
540
+
541
+ try:
542
+ start = datetime.now()
543
+ text = ", ".join(text)
544
+ output = self._operator.run(
545
+ # User parameters
546
+ text=text,
547
+ with_analysis=with_analysis,
548
+ output_lang=output_lang,
549
+ user_prompt=user_prompt,
550
+ temperature=temperature,
551
+ logprobs=logprobs,
552
+ top_logprobs=top_logprobs,
553
+ validator=validator,
554
+ max_validation_retries=max_validation_retries,
555
+ priority=priority,
556
+ # Internal parameters
557
+ prompt_file="merge_questions.yaml",
558
+ output_model=Models.StrOutput,
559
+ mode=mode,
560
+ )
561
+ end = datetime.now()
562
+ output.execution_time = (end - start).total_seconds()
563
+ return output
564
+
565
+ except PromptError as e:
566
+ output.errors.append(f"Prompt error: {e}")
567
+ except LLMError as e:
568
+ output.errors.append(f"LLM error: {e}")
569
+ except ValidationError as e:
570
+ output.errors.append(f"Validation error: {e}")
571
+ except TextToolsError as e:
572
+ output.errors.append(f"TextTools error: {e}")
573
+ except Exception as e:
574
+ output.errors.append(f"Unexpected error: {e}")
575
+
477
576
  return output
478
577
 
479
578
  def rewrite(
@@ -516,26 +615,42 @@ class TheTool:
516
615
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
517
616
  - errors (list(str) | None): Errors occured during tool call
518
617
  """
519
- start = datetime.now()
520
- output = self._operator.run(
521
- # User parameters
522
- text=text,
523
- with_analysis=with_analysis,
524
- output_lang=output_lang,
525
- user_prompt=user_prompt,
526
- temperature=temperature,
527
- logprobs=logprobs,
528
- top_logprobs=top_logprobs,
529
- validator=validator,
530
- max_validation_retries=max_validation_retries,
531
- priority=priority,
532
- # Internal parameters
533
- prompt_file="rewrite.yaml",
534
- output_model=Models.StrOutput,
535
- mode=mode,
536
- )
537
- end = datetime.now()
538
- output.execution_time = (end - start).total_seconds()
618
+ output = Models.ToolOutput()
619
+
620
+ try:
621
+ start = datetime.now()
622
+ output = self._operator.run(
623
+ # User parameters
624
+ text=text,
625
+ with_analysis=with_analysis,
626
+ output_lang=output_lang,
627
+ user_prompt=user_prompt,
628
+ temperature=temperature,
629
+ logprobs=logprobs,
630
+ top_logprobs=top_logprobs,
631
+ validator=validator,
632
+ max_validation_retries=max_validation_retries,
633
+ priority=priority,
634
+ # Internal parameters
635
+ prompt_file="rewrite.yaml",
636
+ output_model=Models.StrOutput,
637
+ mode=mode,
638
+ )
639
+ end = datetime.now()
640
+ output.execution_time = (end - start).total_seconds()
641
+ return output
642
+
643
+ except PromptError as e:
644
+ output.errors.append(f"Prompt error: {e}")
645
+ except LLMError as e:
646
+ output.errors.append(f"LLM error: {e}")
647
+ except ValidationError as e:
648
+ output.errors.append(f"Validation error: {e}")
649
+ except TextToolsError as e:
650
+ output.errors.append(f"TextTools error: {e}")
651
+ except Exception as e:
652
+ output.errors.append(f"Unexpected error: {e}")
653
+
539
654
  return output
540
655
 
541
656
  def subject_to_question(
@@ -578,27 +693,43 @@ class TheTool:
578
693
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
579
694
  - errors (list(str) | None): Errors occured during tool call
580
695
  """
581
- start = datetime.now()
582
- output = self._operator.run(
583
- # User parameters
584
- text=text,
585
- number_of_questions=number_of_questions,
586
- with_analysis=with_analysis,
587
- output_lang=output_lang,
588
- user_prompt=user_prompt,
589
- temperature=temperature,
590
- logprobs=logprobs,
591
- top_logprobs=top_logprobs,
592
- validator=validator,
593
- max_validation_retries=max_validation_retries,
594
- priority=priority,
595
- # Internal parameters
596
- prompt_file="subject_to_question.yaml",
597
- output_model=Models.ReasonListStrOutput,
598
- mode=None,
599
- )
600
- end = datetime.now()
601
- output.execution_time = (end - start).total_seconds()
696
+ output = Models.ToolOutput()
697
+
698
+ try:
699
+ start = datetime.now()
700
+ output = self._operator.run(
701
+ # User parameters
702
+ text=text,
703
+ number_of_questions=number_of_questions,
704
+ with_analysis=with_analysis,
705
+ output_lang=output_lang,
706
+ user_prompt=user_prompt,
707
+ temperature=temperature,
708
+ logprobs=logprobs,
709
+ top_logprobs=top_logprobs,
710
+ validator=validator,
711
+ max_validation_retries=max_validation_retries,
712
+ priority=priority,
713
+ # Internal parameters
714
+ prompt_file="subject_to_question.yaml",
715
+ output_model=Models.ReasonListStrOutput,
716
+ mode=None,
717
+ )
718
+ end = datetime.now()
719
+ output.execution_time = (end - start).total_seconds()
720
+ return output
721
+
722
+ except PromptError as e:
723
+ output.errors.append(f"Prompt error: {e}")
724
+ except LLMError as e:
725
+ output.errors.append(f"LLM error: {e}")
726
+ except ValidationError as e:
727
+ output.errors.append(f"Validation error: {e}")
728
+ except TextToolsError as e:
729
+ output.errors.append(f"TextTools error: {e}")
730
+ except Exception as e:
731
+ output.errors.append(f"Unexpected error: {e}")
732
+
602
733
  return output
603
734
 
604
735
  def summarize(
@@ -639,26 +770,42 @@ class TheTool:
639
770
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
640
771
  - errors (list(str) | None): Errors occured during tool call
641
772
  """
642
- start = datetime.now()
643
- output = self._operator.run(
644
- # User parameters
645
- text=text,
646
- with_analysis=with_analysis,
647
- output_lang=output_lang,
648
- user_prompt=user_prompt,
649
- temperature=temperature,
650
- logprobs=logprobs,
651
- top_logprobs=top_logprobs,
652
- validator=validator,
653
- max_validation_retries=max_validation_retries,
654
- priority=priority,
655
- # Internal parameters
656
- prompt_file="summarize.yaml",
657
- output_model=Models.StrOutput,
658
- mode=None,
659
- )
660
- end = datetime.now()
661
- output.execution_time = (end - start).total_seconds()
773
+ output = Models.ToolOutput()
774
+
775
+ try:
776
+ start = datetime.now()
777
+ output = self._operator.run(
778
+ # User parameters
779
+ text=text,
780
+ with_analysis=with_analysis,
781
+ output_lang=output_lang,
782
+ user_prompt=user_prompt,
783
+ temperature=temperature,
784
+ logprobs=logprobs,
785
+ top_logprobs=top_logprobs,
786
+ validator=validator,
787
+ max_validation_retries=max_validation_retries,
788
+ priority=priority,
789
+ # Internal parameters
790
+ prompt_file="summarize.yaml",
791
+ output_model=Models.StrOutput,
792
+ mode=None,
793
+ )
794
+ end = datetime.now()
795
+ output.execution_time = (end - start).total_seconds()
796
+ return output
797
+
798
+ except PromptError as e:
799
+ output.errors.append(f"Prompt error: {e}")
800
+ except LLMError as e:
801
+ output.errors.append(f"LLM error: {e}")
802
+ except ValidationError as e:
803
+ output.errors.append(f"Validation error: {e}")
804
+ except TextToolsError as e:
805
+ output.errors.append(f"TextTools error: {e}")
806
+ except Exception as e:
807
+ output.errors.append(f"Unexpected error: {e}")
808
+
662
809
  return output
663
810
 
664
811
  def translate(
@@ -677,6 +824,8 @@ class TheTool:
677
824
  """
678
825
  Translate text between languages.
679
826
 
827
+ Important Note: This tool is EXPERIMENTAL, you can use it but it isn't reliable.
828
+
680
829
  Arguments:
681
830
  text: The input text to translate
682
831
  target_language: The target language for translation
@@ -699,30 +848,46 @@ class TheTool:
699
848
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
700
849
  - errors (list(str) | None): Errors occured during tool call
701
850
  """
702
- start = datetime.now()
703
- output = self._operator.run(
704
- # User parameters
705
- text=text,
706
- target_language=target_language,
707
- with_analysis=with_analysis,
708
- user_prompt=user_prompt,
709
- temperature=temperature,
710
- logprobs=logprobs,
711
- top_logprobs=top_logprobs,
712
- validator=validator,
713
- max_validation_retries=max_validation_retries,
714
- priority=priority,
715
- # Internal parameters
716
- prompt_file="translate.yaml",
717
- output_model=Models.StrOutput,
718
- mode=None,
719
- output_lang=None,
720
- )
721
- end = datetime.now()
722
- output.execution_time = (end - start).total_seconds()
851
+ output = Models.ToolOutput()
852
+
853
+ try:
854
+ start = datetime.now()
855
+ output = self._operator.run(
856
+ # User parameters
857
+ text=text,
858
+ target_language=target_language,
859
+ with_analysis=with_analysis,
860
+ user_prompt=user_prompt,
861
+ temperature=temperature,
862
+ logprobs=logprobs,
863
+ top_logprobs=top_logprobs,
864
+ validator=validator,
865
+ max_validation_retries=max_validation_retries,
866
+ priority=priority,
867
+ # Internal parameters
868
+ prompt_file="translate.yaml",
869
+ output_model=Models.StrOutput,
870
+ mode=None,
871
+ output_lang=None,
872
+ )
873
+ end = datetime.now()
874
+ output.execution_time = (end - start).total_seconds()
875
+ return output
876
+
877
+ except PromptError as e:
878
+ output.errors.append(f"Prompt error: {e}")
879
+ except LLMError as e:
880
+ output.errors.append(f"LLM error: {e}")
881
+ except ValidationError as e:
882
+ output.errors.append(f"Validation error: {e}")
883
+ except TextToolsError as e:
884
+ output.errors.append(f"TextTools error: {e}")
885
+ except Exception as e:
886
+ output.errors.append(f"Unexpected error: {e}")
887
+
723
888
  return output
724
889
 
725
- def detect_entity(
890
+ def propositionize(
726
891
  self,
727
892
  text: str,
728
893
  with_analysis: bool = False,
@@ -736,7 +901,9 @@ class TheTool:
736
901
  priority: int | None = 0,
737
902
  ) -> Models.ToolOutput:
738
903
  """
739
- Detects entities in a given text based on the entity_detector.yaml prompt.
904
+ Proposition input text to meaningful sentences.
905
+
906
+ Important Note: This tool is EXPERIMENTAL, you can use it but it isn't reliable.
740
907
 
741
908
  Arguments:
742
909
  text: The input text
@@ -752,7 +919,7 @@ class TheTool:
752
919
 
753
920
  Returns:
754
921
  ToolOutput: Object containing:
755
- - result (list[Entity]): The entities
922
+ - result (list[str]): The propositions
756
923
  - logprobs (list | None): Probability data if logprobs enabled
757
924
  - analysis (str | None): Detailed reasoning if with_analysis enabled
758
925
  - process (str | None): Description of the process used
@@ -760,31 +927,48 @@ class TheTool:
760
927
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
761
928
  - errors (list(str) | None): Errors occured during tool call
762
929
  """
763
- start = datetime.now()
764
- output = self._operator.run(
765
- # User parameters
766
- text=text,
767
- with_analysis=with_analysis,
768
- output_lang=output_lang,
769
- user_prompt=user_prompt,
770
- temperature=temperature,
771
- logprobs=logprobs,
772
- top_logprobs=top_logprobs,
773
- validator=validator,
774
- max_validation_retries=max_validation_retries,
775
- priority=priority,
776
- # Internal parameters
777
- prompt_file="detect_entity.yaml",
778
- output_model=Models.EntityDetectorOutput,
779
- mode=None,
780
- )
781
- end = datetime.now()
782
- output.execution_time = (end - start).total_seconds()
930
+ output = Models.ToolOutput()
931
+
932
+ try:
933
+ start = datetime.now()
934
+ output = self._operator.run(
935
+ # User parameters
936
+ text=text,
937
+ with_analysis=with_analysis,
938
+ output_lang=output_lang,
939
+ user_prompt=user_prompt,
940
+ temperature=temperature,
941
+ logprobs=logprobs,
942
+ top_logprobs=top_logprobs,
943
+ validator=validator,
944
+ max_validation_retries=max_validation_retries,
945
+ priority=priority,
946
+ # Internal parameters
947
+ prompt_file="propositionize.yaml",
948
+ output_model=Models.ListStrOutput,
949
+ mode=None,
950
+ )
951
+ end = datetime.now()
952
+ output.execution_time = (end - start).total_seconds()
953
+ return output
954
+
955
+ except PromptError as e:
956
+ output.errors.append(f"Prompt error: {e}")
957
+ except LLMError as e:
958
+ output.errors.append(f"LLM error: {e}")
959
+ except ValidationError as e:
960
+ output.errors.append(f"Validation error: {e}")
961
+ except TextToolsError as e:
962
+ output.errors.append(f"TextTools error: {e}")
963
+ except Exception as e:
964
+ output.errors.append(f"Unexpected error: {e}")
965
+
783
966
  return output
784
967
 
785
- def propositionize(
968
+ def check_fact(
786
969
  self,
787
970
  text: str,
971
+ source_text: str,
788
972
  with_analysis: bool = False,
789
973
  output_lang: str | None = None,
790
974
  user_prompt: str | None = None,
@@ -796,10 +980,13 @@ class TheTool:
796
980
  priority: int | None = 0,
797
981
  ) -> Models.ToolOutput:
798
982
  """
799
- Proposition input text to meaningful sentences.
983
+ Checks wheather a statement is relevant to the source text or not.
984
+
985
+ Important Note: This tool is EXPERIMENTAL, you can use it but it isn't reliable.
800
986
 
801
987
  Arguments:
802
988
  text: The input text
989
+ source_text: the source text that we want to check relation of text to it
803
990
  with_analysis: Whether to include detailed reasoning analysis
804
991
  output_lang: Language for the output summary
805
992
  user_prompt: Additional instructions for summarization
@@ -812,7 +999,7 @@ class TheTool:
812
999
 
813
1000
  Returns:
814
1001
  ToolOutput: Object containing:
815
- - result (list[str]): The propositions
1002
+ - result (bool): statement is relevant to source text or not
816
1003
  - logprobs (list | None): Probability data if logprobs enabled
817
1004
  - analysis (str | None): Detailed reasoning if with_analysis enabled
818
1005
  - process (str | None): Description of the process used
@@ -820,32 +1007,50 @@ class TheTool:
820
1007
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
821
1008
  - errors (list(str) | None): Errors occured during tool call
822
1009
  """
823
- start = datetime.now()
824
- output = self._operator.run(
825
- # User parameters
826
- text=text,
827
- with_analysis=with_analysis,
828
- output_lang=output_lang,
829
- user_prompt=user_prompt,
830
- temperature=temperature,
831
- logprobs=logprobs,
832
- top_logprobs=top_logprobs,
833
- validator=validator,
834
- max_validation_retries=max_validation_retries,
835
- priority=priority,
836
- # Internal parameters
837
- prompt_file="propositionize.yaml",
838
- output_model=Models.ListStrOutput,
839
- mode=None,
840
- )
841
- end = datetime.now()
842
- output.execution_time = (end - start).total_seconds()
1010
+ output = Models.ToolOutput()
1011
+ try:
1012
+ start = datetime.now()
1013
+ output = self._operator.run(
1014
+ # User parameters
1015
+ text=text,
1016
+ with_analysis=with_analysis,
1017
+ output_lang=output_lang,
1018
+ user_prompt=user_prompt,
1019
+ temperature=temperature,
1020
+ logprobs=logprobs,
1021
+ top_logprobs=top_logprobs,
1022
+ validator=validator,
1023
+ max_validation_retries=max_validation_retries,
1024
+ priority=priority,
1025
+ # Internal parameters
1026
+ prompt_file="check_fact.yaml",
1027
+ output_model=Models.BoolOutput,
1028
+ mode=None,
1029
+ source_text=source_text,
1030
+ )
1031
+ end = datetime.now()
1032
+ output.execution_time = (end - start).total_seconds()
1033
+ return output
1034
+
1035
+ except PromptError as e:
1036
+ output.errors.append(f"Prompt error: {e}")
1037
+ except LLMError as e:
1038
+ output.errors.append(f"LLM error: {e}")
1039
+ except ValidationError as e:
1040
+ output.errors.append(f"Validation error: {e}")
1041
+ except TextToolsError as e:
1042
+ output.errors.append(f"TextTools error: {e}")
1043
+ except Exception as e:
1044
+ output.errors.append(f"Unexpected error: {e}")
1045
+
843
1046
  return output
844
1047
 
845
1048
  def run_custom(
846
1049
  self,
847
1050
  prompt: str,
848
1051
  output_model: Any,
1052
+ with_analysis: bool = False,
1053
+ analyze_template: str | None = None,
849
1054
  output_lang: str | None = None,
850
1055
  temperature: float | None = None,
851
1056
  logprobs: bool | None = None,
@@ -857,8 +1062,13 @@ class TheTool:
857
1062
  """
858
1063
  Custom tool that can do almost anything!
859
1064
 
1065
+ Important Note: This tool is EXPERIMENTAL, you can use it but it isn't reliable.
1066
+
860
1067
  Arguments:
861
- text: The user prompt
1068
+ prompt: The user prompt
1069
+ output_model: Pydantic BaseModel used for structured output
1070
+ with_analysis: Whether to include detailed reasoning analysis
1071
+ analyze_template: The analyze template used for reasoning analysis
862
1072
  output_lang: Language for the output summary
863
1073
  temperature: Controls randomness (0.0 = deterministic, 1.0 = creative)
864
1074
  logprobs: Whether to return token probability information
@@ -877,25 +1087,42 @@ class TheTool:
877
1087
  - execution_time (float): Time taken for execution in seconds (-1.0 if not measured)
878
1088
  - errors (list(str) | None): Errors occured during tool call
879
1089
  """
880
- start = datetime.now()
881
- output = self._operator.run(
882
- # User paramaeters
883
- text=prompt,
884
- output_model=output_model,
885
- output_model_str=output_model.model_json_schema(),
886
- output_lang=output_lang,
887
- temperature=temperature,
888
- logprobs=logprobs,
889
- top_logprobs=top_logprobs,
890
- validator=validator,
891
- max_validation_retries=max_validation_retries,
892
- priority=priority,
893
- # Internal parameters
894
- prompt_file="run_custom.yaml",
895
- user_prompt=None,
896
- with_analysis=False,
897
- mode=None,
898
- )
899
- end = datetime.now()
900
- output.execution_time = (end - start).total_seconds()
1090
+ output = Models.ToolOutput()
1091
+
1092
+ try:
1093
+ start = datetime.now()
1094
+ output = self._operator.run(
1095
+ # User paramaeters
1096
+ text=prompt,
1097
+ output_model=output_model,
1098
+ with_analysis=with_analysis,
1099
+ analyze_template=analyze_template,
1100
+ output_model_str=output_model.model_json_schema(),
1101
+ output_lang=output_lang,
1102
+ temperature=temperature,
1103
+ logprobs=logprobs,
1104
+ top_logprobs=top_logprobs,
1105
+ validator=validator,
1106
+ max_validation_retries=max_validation_retries,
1107
+ priority=priority,
1108
+ # Internal parameters
1109
+ prompt_file="run_custom.yaml",
1110
+ user_prompt=None,
1111
+ mode=None,
1112
+ )
1113
+ end = datetime.now()
1114
+ output.execution_time = (end - start).total_seconds()
1115
+ return output
1116
+
1117
+ except PromptError as e:
1118
+ output.errors.append(f"Prompt error: {e}")
1119
+ except LLMError as e:
1120
+ output.errors.append(f"LLM error: {e}")
1121
+ except ValidationError as e:
1122
+ output.errors.append(f"Validation error: {e}")
1123
+ except TextToolsError as e:
1124
+ output.errors.append(f"TextTools error: {e}")
1125
+ except Exception as e:
1126
+ output.errors.append(f"Unexpected error: {e}")
1127
+
901
1128
  return output