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.
- {hamtaa_texttools-1.1.17.dist-info → hamtaa_texttools-1.1.19.dist-info}/METADATA +31 -1
- hamtaa_texttools-1.1.19.dist-info/RECORD +33 -0
- texttools/__init__.py +1 -1
- texttools/batch/batch_runner.py +75 -64
- texttools/{tools/internals → internals}/async_operator.py +96 -48
- texttools/internals/exceptions.py +28 -0
- texttools/{tools/internals → internals}/models.py +2 -2
- texttools/internals/prompt_loader.py +108 -0
- texttools/{tools/internals → internals}/sync_operator.py +92 -47
- texttools/prompts/check_fact.yaml +19 -0
- texttools/prompts/propositionize.yaml +13 -6
- texttools/prompts/run_custom.yaml +1 -1
- texttools/tools/async_tools.py +576 -348
- texttools/tools/sync_tools.py +573 -346
- hamtaa_texttools-1.1.17.dist-info/RECORD +0 -32
- texttools/prompts/detect_entity.yaml +0 -22
- texttools/tools/internals/prompt_loader.py +0 -56
- {hamtaa_texttools-1.1.17.dist-info → hamtaa_texttools-1.1.19.dist-info}/WHEEL +0 -0
- {hamtaa_texttools-1.1.17.dist-info → hamtaa_texttools-1.1.19.dist-info}/licenses/LICENSE +0 -0
- {hamtaa_texttools-1.1.17.dist-info → hamtaa_texttools-1.1.19.dist-info}/top_level.txt +0 -0
- /texttools/{tools/internals → internals}/formatters.py +0 -0
- /texttools/{tools/internals → internals}/operator_utils.py +0 -0
texttools/tools/sync_tools.py
CHANGED
|
@@ -4,19 +4,20 @@ from collections.abc import Callable
|
|
|
4
4
|
|
|
5
5
|
from openai import OpenAI
|
|
6
6
|
|
|
7
|
-
from texttools.
|
|
8
|
-
import texttools.
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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=
|
|
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(
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
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
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
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
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
text=text
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
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
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
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
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
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
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
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
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
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
|
|
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
|
-
|
|
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[
|
|
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
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
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
|
|
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
|
-
|
|
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 (
|
|
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
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
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
|
-
|
|
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
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
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
|