hamtaa-texttools 1.1.16__py3-none-any.whl → 1.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hamtaa_texttools-1.2.0.dist-info/METADATA +212 -0
- hamtaa_texttools-1.2.0.dist-info/RECORD +34 -0
- texttools/__init__.py +5 -5
- texttools/batch/__init__.py +0 -0
- texttools/batch/{batch_config.py → config.py} +16 -2
- texttools/batch/{internals/batch_manager.py → manager.py} +2 -2
- texttools/batch/{batch_runner.py → runner.py} +80 -69
- texttools/core/__init__.py +0 -0
- texttools/core/engine.py +254 -0
- texttools/core/exceptions.py +22 -0
- texttools/core/internal_models.py +58 -0
- texttools/core/operators/async_operator.py +194 -0
- texttools/core/operators/sync_operator.py +192 -0
- texttools/models.py +88 -0
- texttools/prompts/categorize.yaml +36 -77
- texttools/prompts/check_fact.yaml +24 -0
- texttools/prompts/extract_entities.yaml +7 -3
- texttools/prompts/extract_keywords.yaml +21 -9
- texttools/prompts/is_question.yaml +6 -2
- texttools/prompts/merge_questions.yaml +12 -5
- texttools/prompts/propositionize.yaml +24 -0
- texttools/prompts/rewrite.yaml +9 -10
- texttools/prompts/run_custom.yaml +2 -2
- texttools/prompts/subject_to_question.yaml +7 -3
- texttools/prompts/summarize.yaml +6 -2
- texttools/prompts/text_to_question.yaml +12 -6
- texttools/prompts/translate.yaml +7 -2
- texttools/py.typed +0 -0
- texttools/tools/__init__.py +0 -0
- texttools/tools/async_tools.py +778 -489
- texttools/tools/sync_tools.py +775 -487
- hamtaa_texttools-1.1.16.dist-info/METADATA +0 -255
- hamtaa_texttools-1.1.16.dist-info/RECORD +0 -31
- texttools/batch/internals/utils.py +0 -16
- texttools/prompts/README.md +0 -35
- texttools/prompts/detect_entity.yaml +0 -22
- texttools/tools/internals/async_operator.py +0 -200
- texttools/tools/internals/formatters.py +0 -24
- texttools/tools/internals/models.py +0 -183
- texttools/tools/internals/operator_utils.py +0 -54
- texttools/tools/internals/prompt_loader.py +0 -56
- texttools/tools/internals/sync_operator.py +0 -201
- {hamtaa_texttools-1.1.16.dist-info → hamtaa_texttools-1.2.0.dist-info}/WHEEL +0 -0
- {hamtaa_texttools-1.1.16.dist-info → hamtaa_texttools-1.2.0.dist-info}/licenses/LICENSE +0 -0
- {hamtaa_texttools-1.1.16.dist-info → hamtaa_texttools-1.2.0.dist-info}/top_level.txt +0 -0
texttools/tools/sync_tools.py
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
from typing import Literal, Any
|
|
1
|
+
import sys
|
|
3
2
|
from collections.abc import Callable
|
|
3
|
+
from time import perf_counter
|
|
4
|
+
from typing import Any, Literal
|
|
4
5
|
|
|
5
6
|
from openai import OpenAI
|
|
6
7
|
|
|
7
|
-
from
|
|
8
|
-
|
|
8
|
+
from ..core.engine import text_to_chunks
|
|
9
|
+
from ..core.exceptions import LLMError, PromptError, TextToolsError, ValidationError
|
|
10
|
+
from ..core.internal_models import (
|
|
11
|
+
Bool,
|
|
12
|
+
ListDictStrStr,
|
|
13
|
+
ListStr,
|
|
14
|
+
ReasonListStr,
|
|
15
|
+
Str,
|
|
16
|
+
create_dynamic_model,
|
|
17
|
+
)
|
|
18
|
+
from ..core.operators.sync_operator import Operator
|
|
19
|
+
from ..models import CategoryTree, ToolOutput, ToolOutputMetadata
|
|
9
20
|
|
|
10
21
|
|
|
11
22
|
class TheTool:
|
|
12
23
|
"""
|
|
13
24
|
Each method configures the operator with a specific YAML prompt,
|
|
14
25
|
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
26
|
"""
|
|
21
27
|
|
|
22
28
|
def __init__(
|
|
@@ -29,144 +35,135 @@ class TheTool:
|
|
|
29
35
|
def categorize(
|
|
30
36
|
self,
|
|
31
37
|
text: str,
|
|
32
|
-
categories: list[str] |
|
|
38
|
+
categories: list[str] | CategoryTree,
|
|
33
39
|
with_analysis: bool = False,
|
|
34
40
|
user_prompt: str | None = None,
|
|
35
41
|
temperature: float | None = 0.0,
|
|
36
42
|
logprobs: bool = False,
|
|
37
|
-
top_logprobs: int
|
|
38
|
-
mode: Literal["category_list", "category_tree"] = "category_list",
|
|
43
|
+
top_logprobs: int = 3,
|
|
39
44
|
validator: Callable[[Any], bool] | None = None,
|
|
40
45
|
max_validation_retries: int | None = None,
|
|
41
|
-
priority: int | None =
|
|
42
|
-
) ->
|
|
46
|
+
priority: int | None = None,
|
|
47
|
+
) -> ToolOutput:
|
|
43
48
|
"""
|
|
44
49
|
Categorize a text into a category / category tree.
|
|
45
50
|
|
|
51
|
+
Important Note: category_tree mode is EXPERIMENTAL, you can use it but it isn't reliable.
|
|
52
|
+
|
|
46
53
|
Arguments:
|
|
47
|
-
text: The input text
|
|
48
|
-
categories: The category /
|
|
54
|
+
text: The input text
|
|
55
|
+
categories: The category list / category tree
|
|
49
56
|
with_analysis: Whether to include detailed reasoning analysis
|
|
50
|
-
user_prompt: Additional instructions
|
|
51
|
-
temperature: Controls randomness (0.0
|
|
57
|
+
user_prompt: Additional instructions
|
|
58
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
52
59
|
logprobs: Whether to return token probability information
|
|
53
60
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
54
61
|
validator: Custom validation function to validate the output
|
|
55
62
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
56
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
63
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
57
64
|
|
|
58
65
|
Returns:
|
|
59
|
-
ToolOutput
|
|
60
|
-
|
|
61
|
-
- logprobs (list | None): Probability data if logprobs enabled
|
|
62
|
-
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
63
|
-
- errors (list(str) | None): Errors occured during tool call
|
|
66
|
+
ToolOutput
|
|
67
|
+
|
|
64
68
|
"""
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
parent_id = 0
|
|
72
|
-
final_output = []
|
|
73
|
-
|
|
74
|
-
for _ in range(levels):
|
|
75
|
-
# Get child nodes for current parent
|
|
76
|
-
parent_node = categories.find_node(parent_id)
|
|
77
|
-
children = categories.find_children(parent_node)
|
|
78
|
-
|
|
79
|
-
# Check if child nodes exist
|
|
80
|
-
if not children:
|
|
81
|
-
output.errors.append(
|
|
82
|
-
f"No categories found for parent_id {parent_id} in the tree"
|
|
83
|
-
)
|
|
84
|
-
end = datetime.now()
|
|
85
|
-
output.execution_time = (end - start).total_seconds()
|
|
86
|
-
return output
|
|
87
|
-
|
|
88
|
-
# Extract category names and descriptions
|
|
89
|
-
category_list = [
|
|
90
|
-
f"Category Name: {node.name}, Description: {node.description}"
|
|
91
|
-
for node in children
|
|
92
|
-
]
|
|
93
|
-
category_names = [node.name for node in children]
|
|
94
|
-
|
|
95
|
-
# Run categorization for this level
|
|
96
|
-
level_output = self._operator.run(
|
|
69
|
+
tool_name = sys._getframe().f_code.co_name
|
|
70
|
+
start = perf_counter()
|
|
71
|
+
|
|
72
|
+
try:
|
|
73
|
+
if isinstance(categories, list):
|
|
74
|
+
operator_output = self._operator.run(
|
|
97
75
|
# User parameters
|
|
98
76
|
text=text,
|
|
99
|
-
category_list=
|
|
77
|
+
category_list=categories,
|
|
100
78
|
with_analysis=with_analysis,
|
|
101
79
|
user_prompt=user_prompt,
|
|
102
80
|
temperature=temperature,
|
|
103
81
|
logprobs=logprobs,
|
|
104
82
|
top_logprobs=top_logprobs,
|
|
105
|
-
mode=mode,
|
|
106
83
|
validator=validator,
|
|
107
84
|
max_validation_retries=max_validation_retries,
|
|
108
85
|
priority=priority,
|
|
109
86
|
# Internal parameters
|
|
110
|
-
|
|
111
|
-
output_model=
|
|
87
|
+
tool_name=tool_name,
|
|
88
|
+
output_model=create_dynamic_model(categories),
|
|
89
|
+
mode=None,
|
|
112
90
|
output_lang=None,
|
|
113
91
|
)
|
|
114
92
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
93
|
+
metadata = ToolOutputMetadata(
|
|
94
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
95
|
+
)
|
|
96
|
+
tool_output = ToolOutput(
|
|
97
|
+
result=operator_output.result,
|
|
98
|
+
analysis=operator_output.analysis,
|
|
99
|
+
logprobs=operator_output.logprobs,
|
|
100
|
+
metadata=metadata,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
else:
|
|
104
|
+
levels = categories.get_level_count()
|
|
105
|
+
parent_node = categories.get_node("root")
|
|
106
|
+
final_categories = []
|
|
107
|
+
analysis = ""
|
|
108
|
+
logprobs_list = []
|
|
109
|
+
|
|
110
|
+
for _ in range(levels):
|
|
111
|
+
if not parent_node.children:
|
|
112
|
+
break
|
|
113
|
+
|
|
114
|
+
category_list = [
|
|
115
|
+
f"Category Name: {name}, Description: {node.description}"
|
|
116
|
+
for name, node in parent_node.children.items()
|
|
117
|
+
]
|
|
118
|
+
category_names = list(parent_node.children.keys())
|
|
119
|
+
|
|
120
|
+
level_operator_output = self._operator.run(
|
|
121
|
+
# User parameters
|
|
122
|
+
text=text,
|
|
123
|
+
category_list=category_list,
|
|
124
|
+
with_analysis=with_analysis,
|
|
125
|
+
user_prompt=user_prompt,
|
|
126
|
+
temperature=temperature,
|
|
127
|
+
logprobs=logprobs,
|
|
128
|
+
top_logprobs=top_logprobs,
|
|
129
|
+
validator=validator,
|
|
130
|
+
max_validation_retries=max_validation_retries,
|
|
131
|
+
priority=priority,
|
|
132
|
+
# Internal parameters
|
|
133
|
+
tool_name=tool_name,
|
|
134
|
+
output_model=create_dynamic_model(category_names),
|
|
135
|
+
mode=None,
|
|
136
|
+
output_lang=None,
|
|
130
137
|
)
|
|
131
|
-
end = datetime.now()
|
|
132
|
-
output.execution_time = (end - start).total_seconds()
|
|
133
|
-
return output
|
|
134
138
|
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
chosen_category = level_operator_output.result
|
|
140
|
+
parent_node = categories.get_node(chosen_category)
|
|
141
|
+
if not parent_node:
|
|
142
|
+
break
|
|
143
|
+
final_categories.append(chosen_category)
|
|
137
144
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
145
|
+
if with_analysis:
|
|
146
|
+
analysis += level_operator_output.analysis
|
|
147
|
+
if logprobs:
|
|
148
|
+
logprobs_list.extend(level_operator_output.logprobs)
|
|
142
149
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
150
|
+
metadata = ToolOutputMetadata(
|
|
151
|
+
tool_name=tool_name, execution_time=(perf_counter() - start)
|
|
152
|
+
)
|
|
153
|
+
tool_output = ToolOutput(
|
|
154
|
+
result=final_categories,
|
|
155
|
+
analysis=analysis,
|
|
156
|
+
logprobs=logprobs_list,
|
|
157
|
+
metadata=metadata,
|
|
158
|
+
)
|
|
147
159
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
category_list=categories,
|
|
153
|
-
with_analysis=with_analysis,
|
|
154
|
-
user_prompt=user_prompt,
|
|
155
|
-
temperature=temperature,
|
|
156
|
-
logprobs=logprobs,
|
|
157
|
-
top_logprobs=top_logprobs,
|
|
158
|
-
mode=mode,
|
|
159
|
-
validator=validator,
|
|
160
|
-
max_validation_retries=max_validation_retries,
|
|
161
|
-
priority=priority,
|
|
162
|
-
# Internal parameters
|
|
163
|
-
prompt_file="categorize.yaml",
|
|
164
|
-
output_model=Models.create_dynamic_model(categories),
|
|
165
|
-
output_lang=None,
|
|
160
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
161
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
162
|
+
tool_output = ToolOutput(
|
|
163
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
166
164
|
)
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return output
|
|
165
|
+
|
|
166
|
+
return tool_output
|
|
170
167
|
|
|
171
168
|
def extract_keywords(
|
|
172
169
|
self,
|
|
@@ -176,114 +173,146 @@ class TheTool:
|
|
|
176
173
|
user_prompt: str | None = None,
|
|
177
174
|
temperature: float | None = 0.0,
|
|
178
175
|
logprobs: bool = False,
|
|
179
|
-
top_logprobs: int
|
|
176
|
+
top_logprobs: int = 3,
|
|
180
177
|
mode: Literal["auto", "threshold", "count"] = "auto",
|
|
181
178
|
number_of_keywords: int | None = None,
|
|
182
179
|
validator: Callable[[Any], bool] | None = None,
|
|
183
180
|
max_validation_retries: int | None = None,
|
|
184
|
-
priority: int | None =
|
|
185
|
-
) ->
|
|
181
|
+
priority: int | None = None,
|
|
182
|
+
) -> ToolOutput:
|
|
186
183
|
"""
|
|
187
184
|
Extract salient keywords from text.
|
|
188
185
|
|
|
189
186
|
Arguments:
|
|
190
|
-
text: The input text
|
|
187
|
+
text: The input text
|
|
191
188
|
with_analysis: Whether to include detailed reasoning analysis
|
|
192
|
-
output_lang: Language for the output
|
|
193
|
-
user_prompt: Additional instructions
|
|
194
|
-
temperature: Controls randomness (0.0
|
|
189
|
+
output_lang: Language for the output
|
|
190
|
+
user_prompt: Additional instructions
|
|
191
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
195
192
|
logprobs: Whether to return token probability information
|
|
196
193
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
197
194
|
validator: Custom validation function to validate the output
|
|
198
195
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
199
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
196
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
200
197
|
|
|
201
198
|
Returns:
|
|
202
|
-
ToolOutput
|
|
203
|
-
- result (list[str]): List of extracted keywords
|
|
204
|
-
- logprobs (list | None): Probability data if logprobs enabled
|
|
205
|
-
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
206
|
-
- errors (list(str) | None): Errors occured during tool call
|
|
199
|
+
ToolOutput
|
|
207
200
|
"""
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
201
|
+
tool_name = sys._getframe().f_code.co_name
|
|
202
|
+
start = perf_counter()
|
|
203
|
+
|
|
204
|
+
try:
|
|
205
|
+
operator_output = self._operator.run(
|
|
206
|
+
# User parameters
|
|
207
|
+
text=text,
|
|
208
|
+
with_analysis=with_analysis,
|
|
209
|
+
output_lang=output_lang,
|
|
210
|
+
user_prompt=user_prompt,
|
|
211
|
+
temperature=temperature,
|
|
212
|
+
logprobs=logprobs,
|
|
213
|
+
top_logprobs=top_logprobs,
|
|
214
|
+
mode=mode,
|
|
215
|
+
number_of_keywords=number_of_keywords,
|
|
216
|
+
validator=validator,
|
|
217
|
+
max_validation_retries=max_validation_retries,
|
|
218
|
+
priority=priority,
|
|
219
|
+
# Internal parameters
|
|
220
|
+
tool_name=tool_name,
|
|
221
|
+
output_model=ListStr,
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
metadata = ToolOutputMetadata(
|
|
225
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
226
|
+
)
|
|
227
|
+
tool_output = ToolOutput(
|
|
228
|
+
result=operator_output.result,
|
|
229
|
+
logprobs=operator_output.logprobs,
|
|
230
|
+
analysis=operator_output.analysis,
|
|
231
|
+
metadata=metadata,
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
235
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
236
|
+
tool_output = ToolOutput(
|
|
237
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
return tool_output
|
|
230
241
|
|
|
231
242
|
def extract_entities(
|
|
232
243
|
self,
|
|
233
244
|
text: str,
|
|
245
|
+
entities: list[str] | None = None,
|
|
234
246
|
with_analysis: bool = False,
|
|
235
247
|
output_lang: str | None = None,
|
|
236
248
|
user_prompt: str | None = None,
|
|
237
249
|
temperature: float | None = 0.0,
|
|
238
250
|
logprobs: bool = False,
|
|
239
|
-
top_logprobs: int
|
|
251
|
+
top_logprobs: int = 3,
|
|
240
252
|
validator: Callable[[Any], bool] | None = None,
|
|
241
253
|
max_validation_retries: int | None = None,
|
|
242
|
-
priority: int | None =
|
|
243
|
-
) ->
|
|
254
|
+
priority: int | None = None,
|
|
255
|
+
) -> ToolOutput:
|
|
244
256
|
"""
|
|
245
257
|
Perform Named Entity Recognition (NER) over the input text.
|
|
246
258
|
|
|
247
259
|
Arguments:
|
|
248
|
-
text: The input text
|
|
260
|
+
text: The input text
|
|
261
|
+
entities: List of entities provided by user
|
|
249
262
|
with_analysis: Whether to include detailed reasoning analysis
|
|
250
|
-
output_lang: Language for the output
|
|
251
|
-
user_prompt: Additional instructions
|
|
252
|
-
temperature: Controls randomness (0.0
|
|
263
|
+
output_lang: Language for the output
|
|
264
|
+
user_prompt: Additional instructions
|
|
265
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
253
266
|
logprobs: Whether to return token probability information
|
|
254
267
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
255
268
|
validator: Custom validation function to validate the output
|
|
256
269
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
257
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
270
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
258
271
|
|
|
259
272
|
Returns:
|
|
260
|
-
ToolOutput
|
|
261
|
-
- result (list[dict]): List of entities with 'text' and 'type' keys
|
|
262
|
-
- logprobs (list | None): Probability data if logprobs enabled
|
|
263
|
-
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
264
|
-
- errors (list(str) | None): Errors occured during tool call
|
|
273
|
+
ToolOutput
|
|
265
274
|
"""
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
275
|
+
tool_name = sys._getframe().f_code.co_name
|
|
276
|
+
start = perf_counter()
|
|
277
|
+
|
|
278
|
+
try:
|
|
279
|
+
operator_output = self._operator.run(
|
|
280
|
+
# User parameters
|
|
281
|
+
text=text,
|
|
282
|
+
entities=entities
|
|
283
|
+
or "all named entities (e.g., PER, ORG, LOC, DAT, etc.)",
|
|
284
|
+
with_analysis=with_analysis,
|
|
285
|
+
output_lang=output_lang,
|
|
286
|
+
user_prompt=user_prompt,
|
|
287
|
+
temperature=temperature,
|
|
288
|
+
logprobs=logprobs,
|
|
289
|
+
top_logprobs=top_logprobs,
|
|
290
|
+
validator=validator,
|
|
291
|
+
max_validation_retries=max_validation_retries,
|
|
292
|
+
priority=priority,
|
|
293
|
+
# Internal parameters
|
|
294
|
+
tool_name=tool_name,
|
|
295
|
+
output_model=ListDictStrStr,
|
|
296
|
+
mode=None,
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
metadata = ToolOutputMetadata(
|
|
300
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
301
|
+
)
|
|
302
|
+
tool_output = ToolOutput(
|
|
303
|
+
result=operator_output.result,
|
|
304
|
+
logprobs=operator_output.logprobs,
|
|
305
|
+
analysis=operator_output.analysis,
|
|
306
|
+
metadata=metadata,
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
310
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
311
|
+
tool_output = ToolOutput(
|
|
312
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
return tool_output
|
|
287
316
|
|
|
288
317
|
def is_question(
|
|
289
318
|
self,
|
|
@@ -292,110 +321,141 @@ class TheTool:
|
|
|
292
321
|
user_prompt: str | None = None,
|
|
293
322
|
temperature: float | None = 0.0,
|
|
294
323
|
logprobs: bool = False,
|
|
295
|
-
top_logprobs: int
|
|
324
|
+
top_logprobs: int = 3,
|
|
296
325
|
validator: Callable[[Any], bool] | None = None,
|
|
297
326
|
max_validation_retries: int | None = None,
|
|
298
|
-
priority: int | None =
|
|
299
|
-
) ->
|
|
327
|
+
priority: int | None = None,
|
|
328
|
+
) -> ToolOutput:
|
|
300
329
|
"""
|
|
301
330
|
Detect if the input is phrased as a question.
|
|
302
331
|
|
|
303
332
|
Arguments:
|
|
304
|
-
text: The input text
|
|
333
|
+
text: The input text
|
|
305
334
|
with_analysis: Whether to include detailed reasoning analysis
|
|
306
|
-
user_prompt: Additional instructions
|
|
307
|
-
temperature: Controls randomness (0.0
|
|
335
|
+
user_prompt: Additional instructions
|
|
336
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
308
337
|
logprobs: Whether to return token probability information
|
|
309
338
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
310
339
|
validator: Custom validation function to validate the output
|
|
311
340
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
312
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
341
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
313
342
|
|
|
314
343
|
Returns:
|
|
315
|
-
ToolOutput
|
|
316
|
-
- result (bool): True if text is a question, False otherwise
|
|
317
|
-
- logprobs (list | None): Probability data if logprobs enabled
|
|
318
|
-
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
319
|
-
- errors (list(str) | None): Errors occured during tool call
|
|
344
|
+
ToolOutput
|
|
320
345
|
"""
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
346
|
+
tool_name = sys._getframe().f_code.co_name
|
|
347
|
+
start = perf_counter()
|
|
348
|
+
|
|
349
|
+
try:
|
|
350
|
+
operator_output = self._operator.run(
|
|
351
|
+
# User parameters
|
|
352
|
+
text=text,
|
|
353
|
+
with_analysis=with_analysis,
|
|
354
|
+
user_prompt=user_prompt,
|
|
355
|
+
temperature=temperature,
|
|
356
|
+
logprobs=logprobs,
|
|
357
|
+
top_logprobs=top_logprobs,
|
|
358
|
+
validator=validator,
|
|
359
|
+
max_validation_retries=max_validation_retries,
|
|
360
|
+
priority=priority,
|
|
361
|
+
# Internal parameters
|
|
362
|
+
tool_name=tool_name,
|
|
363
|
+
output_model=Bool,
|
|
364
|
+
mode=None,
|
|
365
|
+
output_lang=None,
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
metadata = ToolOutputMetadata(
|
|
369
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
370
|
+
)
|
|
371
|
+
tool_output = ToolOutput(
|
|
372
|
+
result=operator_output.result,
|
|
373
|
+
logprobs=operator_output.logprobs,
|
|
374
|
+
analysis=operator_output.analysis,
|
|
375
|
+
metadata=metadata,
|
|
376
|
+
)
|
|
377
|
+
|
|
378
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
379
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
380
|
+
tool_output = ToolOutput(
|
|
381
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
382
|
+
)
|
|
383
|
+
|
|
384
|
+
return tool_output
|
|
342
385
|
|
|
343
386
|
def text_to_question(
|
|
344
387
|
self,
|
|
345
388
|
text: str,
|
|
389
|
+
number_of_questions: int,
|
|
346
390
|
with_analysis: bool = False,
|
|
347
391
|
output_lang: str | None = None,
|
|
348
392
|
user_prompt: str | None = None,
|
|
349
393
|
temperature: float | None = 0.0,
|
|
350
394
|
logprobs: bool = False,
|
|
351
|
-
top_logprobs: int
|
|
395
|
+
top_logprobs: int = 3,
|
|
352
396
|
validator: Callable[[Any], bool] | None = None,
|
|
353
397
|
max_validation_retries: int | None = None,
|
|
354
|
-
priority: int | None =
|
|
355
|
-
) ->
|
|
398
|
+
priority: int | None = None,
|
|
399
|
+
) -> ToolOutput:
|
|
356
400
|
"""
|
|
357
401
|
Generate a single question from the given text.
|
|
358
402
|
|
|
359
403
|
Arguments:
|
|
360
|
-
text: The input text
|
|
404
|
+
text: The input text
|
|
405
|
+
number_of_questions: Number of questions to generate
|
|
361
406
|
with_analysis: Whether to include detailed reasoning analysis
|
|
362
|
-
output_lang: Language for the output
|
|
363
|
-
user_prompt: Additional instructions
|
|
364
|
-
temperature: Controls randomness (0.0
|
|
407
|
+
output_lang: Language for the output
|
|
408
|
+
user_prompt: Additional instructions
|
|
409
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
365
410
|
logprobs: Whether to return token probability information
|
|
366
411
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
367
412
|
validator: Custom validation function to validate the output
|
|
368
413
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
369
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
414
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
370
415
|
|
|
371
416
|
Returns:
|
|
372
|
-
ToolOutput
|
|
373
|
-
- result (str): The generated question
|
|
374
|
-
- logprobs (list | None): Probability data if logprobs enabled
|
|
375
|
-
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
376
|
-
- errors (list(str) | None): Errors occured during tool call
|
|
417
|
+
ToolOutput
|
|
377
418
|
"""
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
419
|
+
tool_name = sys._getframe().f_code.co_name
|
|
420
|
+
start = perf_counter()
|
|
421
|
+
|
|
422
|
+
try:
|
|
423
|
+
operator_output = self._operator.run(
|
|
424
|
+
# User parameters
|
|
425
|
+
text=text,
|
|
426
|
+
number_of_questions=number_of_questions,
|
|
427
|
+
with_analysis=with_analysis,
|
|
428
|
+
output_lang=output_lang,
|
|
429
|
+
user_prompt=user_prompt,
|
|
430
|
+
temperature=temperature,
|
|
431
|
+
logprobs=logprobs,
|
|
432
|
+
top_logprobs=top_logprobs,
|
|
433
|
+
validator=validator,
|
|
434
|
+
max_validation_retries=max_validation_retries,
|
|
435
|
+
priority=priority,
|
|
436
|
+
# Internal parameters
|
|
437
|
+
tool_name=tool_name,
|
|
438
|
+
output_model=ReasonListStr,
|
|
439
|
+
mode=None,
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
metadata = ToolOutputMetadata(
|
|
443
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
444
|
+
)
|
|
445
|
+
tool_output = ToolOutput(
|
|
446
|
+
result=operator_output.result,
|
|
447
|
+
logprobs=operator_output.logprobs,
|
|
448
|
+
analysis=operator_output.analysis,
|
|
449
|
+
metadata=metadata,
|
|
450
|
+
)
|
|
451
|
+
|
|
452
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
453
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
454
|
+
tool_output = ToolOutput(
|
|
455
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
456
|
+
)
|
|
457
|
+
|
|
458
|
+
return tool_output
|
|
399
459
|
|
|
400
460
|
def merge_questions(
|
|
401
461
|
self,
|
|
@@ -405,57 +465,70 @@ class TheTool:
|
|
|
405
465
|
user_prompt: str | None = None,
|
|
406
466
|
temperature: float | None = 0.0,
|
|
407
467
|
logprobs: bool = False,
|
|
408
|
-
top_logprobs: int
|
|
468
|
+
top_logprobs: int = 3,
|
|
409
469
|
mode: Literal["default", "reason"] = "default",
|
|
410
470
|
validator: Callable[[Any], bool] | None = None,
|
|
411
471
|
max_validation_retries: int | None = None,
|
|
412
|
-
priority: int | None =
|
|
413
|
-
) ->
|
|
472
|
+
priority: int | None = None,
|
|
473
|
+
) -> ToolOutput:
|
|
414
474
|
"""
|
|
415
475
|
Merge multiple questions into a single unified question.
|
|
416
476
|
|
|
417
477
|
Arguments:
|
|
418
478
|
text: List of questions to merge
|
|
419
479
|
with_analysis: Whether to include detailed reasoning analysis
|
|
420
|
-
output_lang: Language for the output
|
|
421
|
-
user_prompt: Additional instructions
|
|
422
|
-
temperature: Controls randomness (0.0
|
|
480
|
+
output_lang: Language for the output
|
|
481
|
+
user_prompt: Additional instructions
|
|
482
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
423
483
|
logprobs: Whether to return token probability information
|
|
424
484
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
425
|
-
mode: Merging strategy - 'default' for direct merge, 'reason' for reasoned merge
|
|
426
485
|
validator: Custom validation function to validate the output
|
|
427
486
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
428
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
487
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
429
488
|
|
|
430
489
|
Returns:
|
|
431
|
-
ToolOutput
|
|
432
|
-
- result (str): The merged question
|
|
433
|
-
- logprobs (list | None): Probability data if logprobs enabled
|
|
434
|
-
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
435
|
-
- errors (list(str) | None): Errors occured during tool call
|
|
490
|
+
ToolOutput
|
|
436
491
|
"""
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
text=text
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
492
|
+
tool_name = sys._getframe().f_code.co_name
|
|
493
|
+
start = perf_counter()
|
|
494
|
+
|
|
495
|
+
try:
|
|
496
|
+
text = ", ".join(text)
|
|
497
|
+
operator_output = self._operator.run(
|
|
498
|
+
# User parameters
|
|
499
|
+
text=text,
|
|
500
|
+
with_analysis=with_analysis,
|
|
501
|
+
output_lang=output_lang,
|
|
502
|
+
user_prompt=user_prompt,
|
|
503
|
+
temperature=temperature,
|
|
504
|
+
logprobs=logprobs,
|
|
505
|
+
top_logprobs=top_logprobs,
|
|
506
|
+
validator=validator,
|
|
507
|
+
max_validation_retries=max_validation_retries,
|
|
508
|
+
priority=priority,
|
|
509
|
+
# Internal parameters
|
|
510
|
+
tool_name=tool_name,
|
|
511
|
+
output_model=Str,
|
|
512
|
+
mode=mode,
|
|
513
|
+
)
|
|
514
|
+
|
|
515
|
+
metadata = ToolOutputMetadata(
|
|
516
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
517
|
+
)
|
|
518
|
+
tool_output = ToolOutput(
|
|
519
|
+
result=operator_output.result,
|
|
520
|
+
logprobs=operator_output.logprobs,
|
|
521
|
+
analysis=operator_output.analysis,
|
|
522
|
+
metadata=metadata,
|
|
523
|
+
)
|
|
524
|
+
|
|
525
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
526
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
527
|
+
tool_output = ToolOutput(
|
|
528
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
529
|
+
)
|
|
530
|
+
|
|
531
|
+
return tool_output
|
|
459
532
|
|
|
460
533
|
def rewrite(
|
|
461
534
|
self,
|
|
@@ -465,56 +538,69 @@ class TheTool:
|
|
|
465
538
|
user_prompt: str | None = None,
|
|
466
539
|
temperature: float | None = 0.0,
|
|
467
540
|
logprobs: bool = False,
|
|
468
|
-
top_logprobs: int
|
|
541
|
+
top_logprobs: int = 3,
|
|
469
542
|
mode: Literal["positive", "negative", "hard_negative"] = "positive",
|
|
470
543
|
validator: Callable[[Any], bool] | None = None,
|
|
471
544
|
max_validation_retries: int | None = None,
|
|
472
|
-
priority: int | None =
|
|
473
|
-
) ->
|
|
545
|
+
priority: int | None = None,
|
|
546
|
+
) -> ToolOutput:
|
|
474
547
|
"""
|
|
475
548
|
Rewrite a text with different modes.
|
|
476
549
|
|
|
477
550
|
Arguments:
|
|
478
|
-
text: The input text
|
|
551
|
+
text: The input text
|
|
479
552
|
with_analysis: Whether to include detailed reasoning analysis
|
|
480
|
-
output_lang: Language for the output
|
|
481
|
-
user_prompt: Additional instructions
|
|
482
|
-
temperature: Controls randomness (0.0
|
|
553
|
+
output_lang: Language for the output
|
|
554
|
+
user_prompt: Additional instructions
|
|
555
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
483
556
|
logprobs: Whether to return token probability information
|
|
484
557
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
485
|
-
mode: Rewriting mode - 'positive', 'negative', or 'hard_negative'
|
|
486
558
|
validator: Custom validation function to validate the output
|
|
487
559
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
488
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
560
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
489
561
|
|
|
490
562
|
Returns:
|
|
491
|
-
ToolOutput
|
|
492
|
-
- result (str): The rewritten text
|
|
493
|
-
- logprobs (list | None): Probability data if logprobs enabled
|
|
494
|
-
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
495
|
-
- errors (list(str) | None): Errors occured during tool call
|
|
563
|
+
ToolOutput
|
|
496
564
|
"""
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
565
|
+
tool_name = sys._getframe().f_code.co_name
|
|
566
|
+
start = perf_counter()
|
|
567
|
+
|
|
568
|
+
try:
|
|
569
|
+
operator_output = self._operator.run(
|
|
570
|
+
# User parameters
|
|
571
|
+
text=text,
|
|
572
|
+
with_analysis=with_analysis,
|
|
573
|
+
output_lang=output_lang,
|
|
574
|
+
user_prompt=user_prompt,
|
|
575
|
+
temperature=temperature,
|
|
576
|
+
logprobs=logprobs,
|
|
577
|
+
top_logprobs=top_logprobs,
|
|
578
|
+
validator=validator,
|
|
579
|
+
max_validation_retries=max_validation_retries,
|
|
580
|
+
priority=priority,
|
|
581
|
+
# Internal parameters
|
|
582
|
+
tool_name=tool_name,
|
|
583
|
+
output_model=Str,
|
|
584
|
+
mode=mode,
|
|
585
|
+
)
|
|
586
|
+
|
|
587
|
+
metadata = ToolOutputMetadata(
|
|
588
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
589
|
+
)
|
|
590
|
+
tool_output = ToolOutput(
|
|
591
|
+
result=operator_output.result,
|
|
592
|
+
logprobs=operator_output.logprobs,
|
|
593
|
+
analysis=operator_output.analysis,
|
|
594
|
+
metadata=metadata,
|
|
595
|
+
)
|
|
596
|
+
|
|
597
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
598
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
599
|
+
tool_output = ToolOutput(
|
|
600
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
601
|
+
)
|
|
602
|
+
|
|
603
|
+
return tool_output
|
|
518
604
|
|
|
519
605
|
def subject_to_question(
|
|
520
606
|
self,
|
|
@@ -525,11 +611,11 @@ class TheTool:
|
|
|
525
611
|
user_prompt: str | None = None,
|
|
526
612
|
temperature: float | None = 0.0,
|
|
527
613
|
logprobs: bool = False,
|
|
528
|
-
top_logprobs: int
|
|
614
|
+
top_logprobs: int = 3,
|
|
529
615
|
validator: Callable[[Any], bool] | None = None,
|
|
530
616
|
max_validation_retries: int | None = None,
|
|
531
|
-
priority: int | None =
|
|
532
|
-
) ->
|
|
617
|
+
priority: int | None = None,
|
|
618
|
+
) -> ToolOutput:
|
|
533
619
|
"""
|
|
534
620
|
Generate a list of questions about a subject.
|
|
535
621
|
|
|
@@ -537,44 +623,58 @@ class TheTool:
|
|
|
537
623
|
text: The subject text to generate questions about
|
|
538
624
|
number_of_questions: Number of questions to generate
|
|
539
625
|
with_analysis: Whether to include detailed reasoning analysis
|
|
540
|
-
output_lang: Language for the output
|
|
541
|
-
user_prompt: Additional instructions
|
|
542
|
-
temperature: Controls randomness (0.0
|
|
626
|
+
output_lang: Language for the output
|
|
627
|
+
user_prompt: Additional instructions
|
|
628
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
543
629
|
logprobs: Whether to return token probability information
|
|
544
630
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
545
631
|
validator: Custom validation function to validate the output
|
|
546
632
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
547
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
633
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
548
634
|
|
|
549
635
|
Returns:
|
|
550
|
-
ToolOutput
|
|
551
|
-
- result (list[str]): List of generated questions
|
|
552
|
-
- logprobs (list | None): Probability data if logprobs enabled
|
|
553
|
-
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
554
|
-
- errors (list(str) | None): Errors occured during tool call
|
|
636
|
+
ToolOutput
|
|
555
637
|
"""
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
638
|
+
tool_name = sys._getframe().f_code.co_name
|
|
639
|
+
start = perf_counter()
|
|
640
|
+
|
|
641
|
+
try:
|
|
642
|
+
operator_output = self._operator.run(
|
|
643
|
+
# User parameters
|
|
644
|
+
text=text,
|
|
645
|
+
number_of_questions=number_of_questions,
|
|
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
|
+
tool_name=tool_name,
|
|
657
|
+
output_model=ReasonListStr,
|
|
658
|
+
mode=None,
|
|
659
|
+
)
|
|
660
|
+
|
|
661
|
+
metadata = ToolOutputMetadata(
|
|
662
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
663
|
+
)
|
|
664
|
+
tool_output = ToolOutput(
|
|
665
|
+
result=operator_output.result,
|
|
666
|
+
logprobs=operator_output.logprobs,
|
|
667
|
+
analysis=operator_output.analysis,
|
|
668
|
+
metadata=metadata,
|
|
669
|
+
)
|
|
670
|
+
|
|
671
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
672
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
673
|
+
tool_output = ToolOutput(
|
|
674
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
675
|
+
)
|
|
676
|
+
|
|
677
|
+
return tool_output
|
|
578
678
|
|
|
579
679
|
def summarize(
|
|
580
680
|
self,
|
|
@@ -584,114 +684,190 @@ class TheTool:
|
|
|
584
684
|
user_prompt: str | None = None,
|
|
585
685
|
temperature: float | None = 0.0,
|
|
586
686
|
logprobs: bool = False,
|
|
587
|
-
top_logprobs: int
|
|
687
|
+
top_logprobs: int = 3,
|
|
588
688
|
validator: Callable[[Any], bool] | None = None,
|
|
589
689
|
max_validation_retries: int | None = None,
|
|
590
|
-
priority: int | None =
|
|
591
|
-
) ->
|
|
690
|
+
priority: int | None = None,
|
|
691
|
+
) -> ToolOutput:
|
|
592
692
|
"""
|
|
593
693
|
Summarize the given subject text.
|
|
594
694
|
|
|
595
695
|
Arguments:
|
|
596
|
-
text: The input text
|
|
696
|
+
text: The input text
|
|
597
697
|
with_analysis: Whether to include detailed reasoning analysis
|
|
598
|
-
output_lang: Language for the output
|
|
599
|
-
user_prompt: Additional instructions
|
|
600
|
-
temperature: Controls randomness (0.0
|
|
698
|
+
output_lang: Language for the output
|
|
699
|
+
user_prompt: Additional instructions
|
|
700
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
601
701
|
logprobs: Whether to return token probability information
|
|
602
702
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
603
703
|
validator: Custom validation function to validate the output
|
|
604
704
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
605
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
705
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
606
706
|
|
|
607
707
|
Returns:
|
|
608
|
-
ToolOutput
|
|
609
|
-
- result (str): The summary text
|
|
610
|
-
- logprobs (list | None): Probability data if logprobs enabled
|
|
611
|
-
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
612
|
-
- errors (list(str) | None): Errors occured during tool call
|
|
708
|
+
ToolOutput
|
|
613
709
|
"""
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
710
|
+
tool_name = sys._getframe().f_code.co_name
|
|
711
|
+
start = perf_counter()
|
|
712
|
+
|
|
713
|
+
try:
|
|
714
|
+
operator_output = self._operator.run(
|
|
715
|
+
# User parameters
|
|
716
|
+
text=text,
|
|
717
|
+
with_analysis=with_analysis,
|
|
718
|
+
output_lang=output_lang,
|
|
719
|
+
user_prompt=user_prompt,
|
|
720
|
+
temperature=temperature,
|
|
721
|
+
logprobs=logprobs,
|
|
722
|
+
top_logprobs=top_logprobs,
|
|
723
|
+
validator=validator,
|
|
724
|
+
max_validation_retries=max_validation_retries,
|
|
725
|
+
priority=priority,
|
|
726
|
+
# Internal parameters
|
|
727
|
+
tool_name=tool_name,
|
|
728
|
+
output_model=Str,
|
|
729
|
+
mode=None,
|
|
730
|
+
)
|
|
731
|
+
|
|
732
|
+
metadata = ToolOutputMetadata(
|
|
733
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
734
|
+
)
|
|
735
|
+
tool_output = ToolOutput(
|
|
736
|
+
result=operator_output.result,
|
|
737
|
+
logprobs=operator_output.logprobs,
|
|
738
|
+
analysis=operator_output.analysis,
|
|
739
|
+
metadata=metadata,
|
|
740
|
+
)
|
|
741
|
+
|
|
742
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
743
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
744
|
+
tool_output = ToolOutput(
|
|
745
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
746
|
+
)
|
|
747
|
+
|
|
748
|
+
return tool_output
|
|
635
749
|
|
|
636
750
|
def translate(
|
|
637
751
|
self,
|
|
638
752
|
text: str,
|
|
639
753
|
target_language: str,
|
|
754
|
+
use_chunker: bool = True,
|
|
640
755
|
with_analysis: bool = False,
|
|
641
756
|
user_prompt: str | None = None,
|
|
642
757
|
temperature: float | None = 0.0,
|
|
643
758
|
logprobs: bool = False,
|
|
644
|
-
top_logprobs: int
|
|
759
|
+
top_logprobs: int = 3,
|
|
645
760
|
validator: Callable[[Any], bool] | None = None,
|
|
646
761
|
max_validation_retries: int | None = None,
|
|
647
|
-
priority: int | None =
|
|
648
|
-
) ->
|
|
762
|
+
priority: int | None = None,
|
|
763
|
+
) -> ToolOutput:
|
|
649
764
|
"""
|
|
650
765
|
Translate text between languages.
|
|
651
766
|
|
|
767
|
+
Important Note: This tool is EXPERIMENTAL, you can use it but it isn't reliable.
|
|
768
|
+
|
|
652
769
|
Arguments:
|
|
653
|
-
text: The input text
|
|
770
|
+
text: The input text
|
|
654
771
|
target_language: The target language for translation
|
|
772
|
+
use_chunker: Whether to use text chunker for text length bigger than 1500
|
|
655
773
|
with_analysis: Whether to include detailed reasoning analysis
|
|
656
|
-
user_prompt: Additional instructions
|
|
657
|
-
temperature: Controls randomness (0.0
|
|
774
|
+
user_prompt: Additional instructions
|
|
775
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
658
776
|
logprobs: Whether to return token probability information
|
|
659
777
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
660
778
|
validator: Custom validation function to validate the output
|
|
661
779
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
662
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
780
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
663
781
|
|
|
664
782
|
Returns:
|
|
665
|
-
ToolOutput
|
|
666
|
-
- result (str): The translated text
|
|
667
|
-
- logprobs (list | None): Probability data if logprobs enabled
|
|
668
|
-
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
669
|
-
- errors (list(str) | None): Errors occured during tool call
|
|
783
|
+
ToolOutput
|
|
670
784
|
"""
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
785
|
+
tool_name = sys._getframe().f_code.co_name
|
|
786
|
+
start = perf_counter()
|
|
787
|
+
|
|
788
|
+
try:
|
|
789
|
+
if len(text.split(" ")) > 1500 and use_chunker:
|
|
790
|
+
chunks = text_to_chunks(text, 1200, 0)
|
|
791
|
+
translation = ""
|
|
792
|
+
analysis = ""
|
|
793
|
+
logprobs_list = []
|
|
794
|
+
|
|
795
|
+
for chunk in chunks:
|
|
796
|
+
chunk_operator_output = self._operator.run(
|
|
797
|
+
# User parameters
|
|
798
|
+
text=chunk,
|
|
799
|
+
target_language=target_language,
|
|
800
|
+
with_analysis=with_analysis,
|
|
801
|
+
user_prompt=user_prompt,
|
|
802
|
+
temperature=temperature,
|
|
803
|
+
logprobs=logprobs,
|
|
804
|
+
top_logprobs=top_logprobs,
|
|
805
|
+
validator=validator,
|
|
806
|
+
max_validation_retries=max_validation_retries,
|
|
807
|
+
priority=priority,
|
|
808
|
+
# Internal parameters
|
|
809
|
+
tool_name=tool_name,
|
|
810
|
+
output_model=Str,
|
|
811
|
+
mode=None,
|
|
812
|
+
output_lang=None,
|
|
813
|
+
)
|
|
814
|
+
|
|
815
|
+
translation += chunk_operator_output.result + "\n"
|
|
816
|
+
|
|
817
|
+
if with_analysis:
|
|
818
|
+
analysis += chunk_operator_output.analysis
|
|
819
|
+
if logprobs:
|
|
820
|
+
logprobs_list.extend(chunk_operator_output.logprobs)
|
|
821
|
+
|
|
822
|
+
metadata = ToolOutputMetadata(
|
|
823
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
824
|
+
)
|
|
825
|
+
tool_output = ToolOutput(
|
|
826
|
+
result=translation,
|
|
827
|
+
logprobs=logprobs_list,
|
|
828
|
+
analysis=analysis,
|
|
829
|
+
metadata=metadata,
|
|
830
|
+
)
|
|
831
|
+
|
|
832
|
+
else:
|
|
833
|
+
operator_output = self._operator.run(
|
|
834
|
+
# User parameters
|
|
835
|
+
text=text,
|
|
836
|
+
target_language=target_language,
|
|
837
|
+
with_analysis=with_analysis,
|
|
838
|
+
user_prompt=user_prompt,
|
|
839
|
+
temperature=temperature,
|
|
840
|
+
logprobs=logprobs,
|
|
841
|
+
top_logprobs=top_logprobs,
|
|
842
|
+
validator=validator,
|
|
843
|
+
max_validation_retries=max_validation_retries,
|
|
844
|
+
priority=priority,
|
|
845
|
+
# Internal parameters
|
|
846
|
+
tool_name=tool_name,
|
|
847
|
+
output_model=Str,
|
|
848
|
+
mode=None,
|
|
849
|
+
output_lang=None,
|
|
850
|
+
)
|
|
851
|
+
|
|
852
|
+
metadata = ToolOutputMetadata(
|
|
853
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
854
|
+
)
|
|
855
|
+
tool_output = ToolOutput(
|
|
856
|
+
result=operator_output.result,
|
|
857
|
+
logprobs=operator_output.logprobs,
|
|
858
|
+
analysis=operator_output.analysis,
|
|
859
|
+
metadata=metadata,
|
|
860
|
+
)
|
|
861
|
+
|
|
862
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
863
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
864
|
+
tool_output = ToolOutput(
|
|
865
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
866
|
+
)
|
|
867
|
+
|
|
868
|
+
return tool_output
|
|
869
|
+
|
|
870
|
+
def propositionize(
|
|
695
871
|
self,
|
|
696
872
|
text: str,
|
|
697
873
|
with_analysis: bool = False,
|
|
@@ -699,106 +875,218 @@ class TheTool:
|
|
|
699
875
|
user_prompt: str | None = None,
|
|
700
876
|
temperature: float | None = 0.0,
|
|
701
877
|
logprobs: bool = False,
|
|
702
|
-
top_logprobs: int
|
|
878
|
+
top_logprobs: int = 3,
|
|
703
879
|
validator: Callable[[Any], bool] | None = None,
|
|
704
880
|
max_validation_retries: int | None = None,
|
|
705
|
-
priority: int | None =
|
|
706
|
-
) ->
|
|
881
|
+
priority: int | None = None,
|
|
882
|
+
) -> ToolOutput:
|
|
707
883
|
"""
|
|
708
|
-
|
|
884
|
+
Proposition input text to meaningful sentences.
|
|
885
|
+
|
|
886
|
+
Important Note: This tool is EXPERIMENTAL, you can use it but it isn't reliable.
|
|
709
887
|
|
|
710
888
|
Arguments:
|
|
711
889
|
text: The input text
|
|
712
890
|
with_analysis: Whether to include detailed reasoning analysis
|
|
713
|
-
output_lang: Language for the output
|
|
714
|
-
user_prompt: Additional instructions
|
|
715
|
-
temperature: Controls randomness (0.0
|
|
891
|
+
output_lang: Language for the output
|
|
892
|
+
user_prompt: Additional instructions
|
|
893
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
716
894
|
logprobs: Whether to return token probability information
|
|
717
895
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
718
896
|
validator: Custom validation function to validate the output
|
|
719
897
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
720
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
898
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
721
899
|
|
|
722
900
|
Returns:
|
|
723
|
-
ToolOutput
|
|
724
|
-
- result (list[Entity]): The entities
|
|
725
|
-
- logprobs (list | None): Probability data if logprobs enabled
|
|
726
|
-
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
727
|
-
- errors (list(str) | None): Errors occured during tool call
|
|
901
|
+
ToolOutput
|
|
728
902
|
"""
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
903
|
+
tool_name = sys._getframe().f_code.co_name
|
|
904
|
+
start = perf_counter()
|
|
905
|
+
|
|
906
|
+
try:
|
|
907
|
+
operator_output = self._operator.run(
|
|
908
|
+
# User parameters
|
|
909
|
+
text=text,
|
|
910
|
+
with_analysis=with_analysis,
|
|
911
|
+
output_lang=output_lang,
|
|
912
|
+
user_prompt=user_prompt,
|
|
913
|
+
temperature=temperature,
|
|
914
|
+
logprobs=logprobs,
|
|
915
|
+
top_logprobs=top_logprobs,
|
|
916
|
+
validator=validator,
|
|
917
|
+
max_validation_retries=max_validation_retries,
|
|
918
|
+
priority=priority,
|
|
919
|
+
# Internal parameters
|
|
920
|
+
tool_name=tool_name,
|
|
921
|
+
output_model=ListStr,
|
|
922
|
+
mode=None,
|
|
923
|
+
)
|
|
924
|
+
|
|
925
|
+
metadata = ToolOutputMetadata(
|
|
926
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
927
|
+
)
|
|
928
|
+
tool_output = ToolOutput(
|
|
929
|
+
result=operator_output.result,
|
|
930
|
+
logprobs=operator_output.logprobs,
|
|
931
|
+
analysis=operator_output.analysis,
|
|
932
|
+
metadata=metadata,
|
|
933
|
+
)
|
|
934
|
+
|
|
935
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
936
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
937
|
+
tool_output = ToolOutput(
|
|
938
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
939
|
+
)
|
|
940
|
+
|
|
941
|
+
return tool_output
|
|
942
|
+
|
|
943
|
+
def check_fact(
|
|
944
|
+
self,
|
|
945
|
+
text: str,
|
|
946
|
+
source_text: str,
|
|
947
|
+
with_analysis: bool = False,
|
|
948
|
+
output_lang: str | None = None,
|
|
949
|
+
user_prompt: str | None = None,
|
|
950
|
+
temperature: float | None = 0.0,
|
|
951
|
+
logprobs: bool = False,
|
|
952
|
+
top_logprobs: int = 3,
|
|
953
|
+
validator: Callable[[Any], bool] | None = None,
|
|
954
|
+
max_validation_retries: int | None = None,
|
|
955
|
+
priority: int | None = None,
|
|
956
|
+
) -> ToolOutput:
|
|
957
|
+
"""
|
|
958
|
+
Checks wheather a statement is relevant to the source text or not.
|
|
959
|
+
|
|
960
|
+
Important Note: This tool is EXPERIMENTAL, you can use it but it isn't reliable.
|
|
961
|
+
|
|
962
|
+
Arguments:
|
|
963
|
+
text: The input text
|
|
964
|
+
source_text: the source text that we want to check relation of text to it
|
|
965
|
+
with_analysis: Whether to include detailed reasoning analysis
|
|
966
|
+
output_lang: Language for the output
|
|
967
|
+
user_prompt: Additional instructions
|
|
968
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
969
|
+
logprobs: Whether to return token probability information
|
|
970
|
+
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
971
|
+
validator: Custom validation function to validate the output
|
|
972
|
+
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
973
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
974
|
+
|
|
975
|
+
Returns:
|
|
976
|
+
ToolOutput
|
|
977
|
+
"""
|
|
978
|
+
tool_name = sys._getframe().f_code.co_name
|
|
979
|
+
start = perf_counter()
|
|
980
|
+
|
|
981
|
+
try:
|
|
982
|
+
operator_output = self._operator.run(
|
|
983
|
+
# User parameters
|
|
984
|
+
text=text,
|
|
985
|
+
with_analysis=with_analysis,
|
|
986
|
+
output_lang=output_lang,
|
|
987
|
+
user_prompt=user_prompt,
|
|
988
|
+
temperature=temperature,
|
|
989
|
+
logprobs=logprobs,
|
|
990
|
+
top_logprobs=top_logprobs,
|
|
991
|
+
validator=validator,
|
|
992
|
+
max_validation_retries=max_validation_retries,
|
|
993
|
+
priority=priority,
|
|
994
|
+
# Internal parameters
|
|
995
|
+
tool_name=tool_name,
|
|
996
|
+
output_model=Bool,
|
|
997
|
+
mode=None,
|
|
998
|
+
source_text=source_text,
|
|
999
|
+
)
|
|
1000
|
+
|
|
1001
|
+
metadata = ToolOutputMetadata(
|
|
1002
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
1003
|
+
)
|
|
1004
|
+
tool_output = ToolOutput(
|
|
1005
|
+
result=operator_output.result,
|
|
1006
|
+
logprobs=operator_output.logprobs,
|
|
1007
|
+
analysis=operator_output.analysis,
|
|
1008
|
+
metadata=metadata,
|
|
1009
|
+
)
|
|
1010
|
+
|
|
1011
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
1012
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
1013
|
+
tool_output = ToolOutput(
|
|
1014
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
1015
|
+
)
|
|
1016
|
+
|
|
1017
|
+
return tool_output
|
|
750
1018
|
|
|
751
1019
|
def run_custom(
|
|
752
1020
|
self,
|
|
753
1021
|
prompt: str,
|
|
754
1022
|
output_model: Any,
|
|
1023
|
+
with_analysis: bool = False,
|
|
1024
|
+
analyze_template: str | None = None,
|
|
755
1025
|
output_lang: str | None = None,
|
|
756
1026
|
temperature: float | None = None,
|
|
757
1027
|
logprobs: bool | None = None,
|
|
758
|
-
top_logprobs: int
|
|
1028
|
+
top_logprobs: int = 3,
|
|
759
1029
|
validator: Callable[[Any], bool] | None = None,
|
|
760
1030
|
max_validation_retries: int | None = None,
|
|
761
|
-
priority: int | None =
|
|
762
|
-
) ->
|
|
1031
|
+
priority: int | None = None,
|
|
1032
|
+
) -> ToolOutput:
|
|
763
1033
|
"""
|
|
764
1034
|
Custom tool that can do almost anything!
|
|
765
1035
|
|
|
766
1036
|
Arguments:
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
1037
|
+
prompt: The user prompt
|
|
1038
|
+
output_model: Pydantic BaseModel used for structured output
|
|
1039
|
+
with_analysis: Whether to include detailed reasoning analysis
|
|
1040
|
+
analyze_template: The analyze template used for reasoning analysis
|
|
1041
|
+
output_lang: Language for the output
|
|
1042
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
770
1043
|
logprobs: Whether to return token probability information
|
|
771
1044
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
772
1045
|
validator: Custom validation function to validate the output
|
|
773
1046
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
774
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
1047
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
775
1048
|
|
|
776
1049
|
Returns:
|
|
777
|
-
ToolOutput
|
|
778
|
-
- result (str): The translated text
|
|
779
|
-
- logprobs (list | None): Probability data if logprobs enabled
|
|
780
|
-
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
781
|
-
- errors (list(str) | None): Errors occured during tool call
|
|
1050
|
+
ToolOutput
|
|
782
1051
|
"""
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
1052
|
+
tool_name = sys._getframe().f_code.co_name
|
|
1053
|
+
start = perf_counter()
|
|
1054
|
+
|
|
1055
|
+
try:
|
|
1056
|
+
operator_output = self._operator.run(
|
|
1057
|
+
# User paramaeters
|
|
1058
|
+
text=prompt,
|
|
1059
|
+
output_model=output_model,
|
|
1060
|
+
with_analysis=with_analysis,
|
|
1061
|
+
analyze_template=analyze_template,
|
|
1062
|
+
output_model_str=output_model.model_json_schema(),
|
|
1063
|
+
output_lang=output_lang,
|
|
1064
|
+
temperature=temperature,
|
|
1065
|
+
logprobs=logprobs,
|
|
1066
|
+
top_logprobs=top_logprobs,
|
|
1067
|
+
validator=validator,
|
|
1068
|
+
max_validation_retries=max_validation_retries,
|
|
1069
|
+
priority=priority,
|
|
1070
|
+
# Internal parameters
|
|
1071
|
+
tool_name=tool_name,
|
|
1072
|
+
user_prompt=None,
|
|
1073
|
+
mode=None,
|
|
1074
|
+
)
|
|
1075
|
+
|
|
1076
|
+
metadata = ToolOutputMetadata(
|
|
1077
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
1078
|
+
)
|
|
1079
|
+
tool_output = ToolOutput(
|
|
1080
|
+
result=operator_output.result,
|
|
1081
|
+
logprobs=operator_output.logprobs,
|
|
1082
|
+
analysis=operator_output.analysis,
|
|
1083
|
+
metadata=metadata,
|
|
1084
|
+
)
|
|
1085
|
+
|
|
1086
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
1087
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
1088
|
+
tool_output = ToolOutput(
|
|
1089
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
1090
|
+
)
|
|
1091
|
+
|
|
1092
|
+
return tool_output
|