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/async_tools.py
CHANGED
|
@@ -1,24 +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 AsyncOpenAI
|
|
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.async_operator import AsyncOperator
|
|
19
|
+
from ..models import CategoryTree, ToolOutput, ToolOutputMetadata
|
|
9
20
|
|
|
10
21
|
|
|
11
22
|
class AsyncTheTool:
|
|
12
23
|
"""
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Each method configures the async operator with a specific YAML prompt,
|
|
24
|
+
Each method configures the operator with a specific YAML prompt,
|
|
16
25
|
output schema, and flags, then delegates execution to `operator.run()`.
|
|
17
|
-
|
|
18
|
-
Usage:
|
|
19
|
-
async_client = AsyncOpenAI(...)
|
|
20
|
-
tool = TheToolAsync(async_client, model="model-name")
|
|
21
|
-
result = await tool.categorize("text ...", with_analysis=True)
|
|
22
26
|
"""
|
|
23
27
|
|
|
24
28
|
def __init__(
|
|
@@ -31,142 +35,135 @@ class AsyncTheTool:
|
|
|
31
35
|
async def categorize(
|
|
32
36
|
self,
|
|
33
37
|
text: str,
|
|
34
|
-
categories: list[str] |
|
|
38
|
+
categories: list[str] | CategoryTree,
|
|
35
39
|
with_analysis: bool = False,
|
|
36
40
|
user_prompt: str | None = None,
|
|
37
41
|
temperature: float | None = 0.0,
|
|
38
42
|
logprobs: bool = False,
|
|
39
|
-
top_logprobs: int
|
|
40
|
-
mode: Literal["category_list", "category_tree"] = "category_list",
|
|
43
|
+
top_logprobs: int = 3,
|
|
41
44
|
validator: Callable[[Any], bool] | None = None,
|
|
42
45
|
max_validation_retries: int | None = None,
|
|
43
|
-
priority: int | None =
|
|
44
|
-
) ->
|
|
46
|
+
priority: int | None = None,
|
|
47
|
+
) -> ToolOutput:
|
|
45
48
|
"""
|
|
46
49
|
Categorize a text into a category / category tree.
|
|
47
50
|
|
|
51
|
+
Important Note: category_tree mode is EXPERIMENTAL, you can use it but it isn't reliable.
|
|
52
|
+
|
|
48
53
|
Arguments:
|
|
49
|
-
text: The input text
|
|
50
|
-
categories: The category /
|
|
54
|
+
text: The input text
|
|
55
|
+
categories: The category list / category tree
|
|
51
56
|
with_analysis: Whether to include detailed reasoning analysis
|
|
52
|
-
user_prompt: Additional instructions
|
|
53
|
-
temperature: Controls randomness (0.0
|
|
57
|
+
user_prompt: Additional instructions
|
|
58
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
54
59
|
logprobs: Whether to return token probability information
|
|
55
60
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
56
61
|
validator: Custom validation function to validate the output
|
|
57
62
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
58
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
63
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
59
64
|
|
|
60
65
|
Returns:
|
|
61
|
-
ToolOutput
|
|
62
|
-
|
|
63
|
-
- logprobs (list | None): Probability data if logprobs enabled
|
|
64
|
-
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
65
|
-
- errors (list(str) | None): Errors occured during tool call
|
|
66
|
+
ToolOutput
|
|
67
|
+
|
|
66
68
|
"""
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
parent_id = 0
|
|
74
|
-
final_output = []
|
|
75
|
-
|
|
76
|
-
for _ in range(levels):
|
|
77
|
-
# Get child nodes for current parent
|
|
78
|
-
parent_node = categories.find_node(parent_id)
|
|
79
|
-
children = categories.find_children(parent_node)
|
|
80
|
-
|
|
81
|
-
# Check if child nodes exist
|
|
82
|
-
if not children:
|
|
83
|
-
output.errors.append(
|
|
84
|
-
f"No categories found for parent_id {parent_id} in the tree"
|
|
85
|
-
)
|
|
86
|
-
end = datetime.now()
|
|
87
|
-
output.execution_time = (end - start).total_seconds()
|
|
88
|
-
return output
|
|
89
|
-
|
|
90
|
-
# Extract category names and descriptions
|
|
91
|
-
category_list = [
|
|
92
|
-
f"Category Name: {node.name}, Description: {node.description}"
|
|
93
|
-
for node in children
|
|
94
|
-
]
|
|
95
|
-
category_names = [node.name for node in children]
|
|
96
|
-
|
|
97
|
-
# Run categorization for this level
|
|
98
|
-
level_output = await 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 = await self._operator.run(
|
|
99
75
|
# User parameters
|
|
100
76
|
text=text,
|
|
101
|
-
category_list=
|
|
77
|
+
category_list=categories,
|
|
102
78
|
with_analysis=with_analysis,
|
|
103
79
|
user_prompt=user_prompt,
|
|
104
80
|
temperature=temperature,
|
|
105
81
|
logprobs=logprobs,
|
|
106
82
|
top_logprobs=top_logprobs,
|
|
107
|
-
mode=mode,
|
|
108
83
|
validator=validator,
|
|
109
84
|
max_validation_retries=max_validation_retries,
|
|
85
|
+
priority=priority,
|
|
110
86
|
# Internal parameters
|
|
111
|
-
|
|
112
|
-
output_model=
|
|
87
|
+
tool_name=tool_name,
|
|
88
|
+
output_model=create_dynamic_model(categories),
|
|
89
|
+
mode=None,
|
|
113
90
|
output_lang=None,
|
|
114
91
|
)
|
|
115
92
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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 = await 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,
|
|
131
137
|
)
|
|
132
|
-
end = datetime.now()
|
|
133
|
-
output.execution_time = (end - start).total_seconds()
|
|
134
|
-
return output
|
|
135
138
|
|
|
136
|
-
|
|
137
|
-
|
|
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)
|
|
138
144
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
145
|
+
if with_analysis:
|
|
146
|
+
analysis += level_operator_output.analysis
|
|
147
|
+
if logprobs:
|
|
148
|
+
logprobs_list.extend(level_operator_output.logprobs)
|
|
143
149
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
+
)
|
|
148
159
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
category_list=categories,
|
|
154
|
-
with_analysis=with_analysis,
|
|
155
|
-
user_prompt=user_prompt,
|
|
156
|
-
temperature=temperature,
|
|
157
|
-
logprobs=logprobs,
|
|
158
|
-
top_logprobs=top_logprobs,
|
|
159
|
-
mode=mode,
|
|
160
|
-
validator=validator,
|
|
161
|
-
max_validation_retries=max_validation_retries,
|
|
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
|
async def extract_keywords(
|
|
172
169
|
self,
|
|
@@ -176,114 +173,146 @@ class AsyncTheTool:
|
|
|
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 = await 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
|
async 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 (Optional)
|
|
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 = await 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
|
async def is_question(
|
|
289
318
|
self,
|
|
@@ -292,110 +321,142 @@ class AsyncTheTool:
|
|
|
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
|
+
|
|
348
|
+
start = perf_counter()
|
|
349
|
+
|
|
350
|
+
try:
|
|
351
|
+
operator_output = await self._operator.run(
|
|
352
|
+
# User parameters
|
|
353
|
+
text=text,
|
|
354
|
+
with_analysis=with_analysis,
|
|
355
|
+
user_prompt=user_prompt,
|
|
356
|
+
temperature=temperature,
|
|
357
|
+
logprobs=logprobs,
|
|
358
|
+
top_logprobs=top_logprobs,
|
|
359
|
+
validator=validator,
|
|
360
|
+
max_validation_retries=max_validation_retries,
|
|
361
|
+
priority=priority,
|
|
362
|
+
# Internal parameters
|
|
363
|
+
tool_name=tool_name,
|
|
364
|
+
output_model=Bool,
|
|
365
|
+
mode=None,
|
|
366
|
+
output_lang=None,
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
metadata = ToolOutputMetadata(
|
|
370
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
371
|
+
)
|
|
372
|
+
tool_output = ToolOutput(
|
|
373
|
+
result=operator_output.result,
|
|
374
|
+
logprobs=operator_output.logprobs,
|
|
375
|
+
analysis=operator_output.analysis,
|
|
376
|
+
metadata=metadata,
|
|
377
|
+
)
|
|
378
|
+
|
|
379
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
380
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
381
|
+
tool_output = ToolOutput(
|
|
382
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
return tool_output
|
|
342
386
|
|
|
343
387
|
async def text_to_question(
|
|
344
388
|
self,
|
|
345
389
|
text: str,
|
|
390
|
+
number_of_questions: int,
|
|
346
391
|
with_analysis: bool = False,
|
|
347
392
|
output_lang: str | None = None,
|
|
348
393
|
user_prompt: str | None = None,
|
|
349
394
|
temperature: float | None = 0.0,
|
|
350
395
|
logprobs: bool = False,
|
|
351
|
-
top_logprobs: int
|
|
396
|
+
top_logprobs: int = 3,
|
|
352
397
|
validator: Callable[[Any], bool] | None = None,
|
|
353
398
|
max_validation_retries: int | None = None,
|
|
354
|
-
priority: int | None =
|
|
355
|
-
) ->
|
|
399
|
+
priority: int | None = None,
|
|
400
|
+
) -> ToolOutput:
|
|
356
401
|
"""
|
|
357
402
|
Generate a single question from the given text.
|
|
358
403
|
|
|
359
404
|
Arguments:
|
|
360
|
-
text: The input text
|
|
405
|
+
text: The input text
|
|
406
|
+
number_of_questions: Number of questions to generate
|
|
361
407
|
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
|
|
408
|
+
output_lang: Language for the output
|
|
409
|
+
user_prompt: Additional instructions
|
|
410
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
365
411
|
logprobs: Whether to return token probability information
|
|
366
412
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
367
413
|
validator: Custom validation function to validate the output
|
|
368
414
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
369
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
415
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
370
416
|
|
|
371
417
|
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
|
|
418
|
+
ToolOutput
|
|
377
419
|
"""
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
420
|
+
tool_name = sys._getframe().f_code.co_name
|
|
421
|
+
start = perf_counter()
|
|
422
|
+
|
|
423
|
+
try:
|
|
424
|
+
operator_output = await self._operator.run(
|
|
425
|
+
# User parameters
|
|
426
|
+
text=text,
|
|
427
|
+
number_of_questions=number_of_questions,
|
|
428
|
+
with_analysis=with_analysis,
|
|
429
|
+
output_lang=output_lang,
|
|
430
|
+
user_prompt=user_prompt,
|
|
431
|
+
temperature=temperature,
|
|
432
|
+
logprobs=logprobs,
|
|
433
|
+
top_logprobs=top_logprobs,
|
|
434
|
+
validator=validator,
|
|
435
|
+
max_validation_retries=max_validation_retries,
|
|
436
|
+
priority=priority,
|
|
437
|
+
# Internal parameters
|
|
438
|
+
tool_name=tool_name,
|
|
439
|
+
output_model=ReasonListStr,
|
|
440
|
+
mode=None,
|
|
441
|
+
)
|
|
442
|
+
|
|
443
|
+
metadata = ToolOutputMetadata(
|
|
444
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
445
|
+
)
|
|
446
|
+
tool_output = ToolOutput(
|
|
447
|
+
result=operator_output.result,
|
|
448
|
+
logprobs=operator_output.logprobs,
|
|
449
|
+
analysis=operator_output.analysis,
|
|
450
|
+
metadata=metadata,
|
|
451
|
+
)
|
|
452
|
+
|
|
453
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
454
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
455
|
+
tool_output = ToolOutput(
|
|
456
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
457
|
+
)
|
|
458
|
+
|
|
459
|
+
return tool_output
|
|
399
460
|
|
|
400
461
|
async def merge_questions(
|
|
401
462
|
self,
|
|
@@ -405,57 +466,70 @@ class AsyncTheTool:
|
|
|
405
466
|
user_prompt: str | None = None,
|
|
406
467
|
temperature: float | None = 0.0,
|
|
407
468
|
logprobs: bool = False,
|
|
408
|
-
top_logprobs: int
|
|
469
|
+
top_logprobs: int = 3,
|
|
409
470
|
mode: Literal["default", "reason"] = "default",
|
|
410
471
|
validator: Callable[[Any], bool] | None = None,
|
|
411
472
|
max_validation_retries: int | None = None,
|
|
412
|
-
priority: int | None =
|
|
413
|
-
) ->
|
|
473
|
+
priority: int | None = None,
|
|
474
|
+
) -> ToolOutput:
|
|
414
475
|
"""
|
|
415
476
|
Merge multiple questions into a single unified question.
|
|
416
477
|
|
|
417
478
|
Arguments:
|
|
418
479
|
text: List of questions to merge
|
|
419
480
|
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
|
|
481
|
+
output_lang: Language for the output
|
|
482
|
+
user_prompt: Additional instructions
|
|
483
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
423
484
|
logprobs: Whether to return token probability information
|
|
424
485
|
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
486
|
validator: Custom validation function to validate the output
|
|
427
487
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
428
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
488
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
429
489
|
|
|
430
490
|
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
|
|
491
|
+
ToolOutput
|
|
436
492
|
"""
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
text=
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
493
|
+
tool_name = sys._getframe().f_code.co_name
|
|
494
|
+
start = perf_counter()
|
|
495
|
+
|
|
496
|
+
try:
|
|
497
|
+
text = ", ".join(text)
|
|
498
|
+
operator_output = await self._operator.run(
|
|
499
|
+
# User parameters
|
|
500
|
+
text=text,
|
|
501
|
+
with_analysis=with_analysis,
|
|
502
|
+
output_lang=output_lang,
|
|
503
|
+
user_prompt=user_prompt,
|
|
504
|
+
temperature=temperature,
|
|
505
|
+
logprobs=logprobs,
|
|
506
|
+
top_logprobs=top_logprobs,
|
|
507
|
+
validator=validator,
|
|
508
|
+
max_validation_retries=max_validation_retries,
|
|
509
|
+
priority=priority,
|
|
510
|
+
# Internal parameters
|
|
511
|
+
tool_name=tool_name,
|
|
512
|
+
output_model=Str,
|
|
513
|
+
mode=mode,
|
|
514
|
+
)
|
|
515
|
+
|
|
516
|
+
metadata = ToolOutputMetadata(
|
|
517
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
518
|
+
)
|
|
519
|
+
tool_output = ToolOutput(
|
|
520
|
+
result=operator_output.result,
|
|
521
|
+
logprobs=operator_output.logprobs,
|
|
522
|
+
analysis=operator_output.analysis,
|
|
523
|
+
metadata=metadata,
|
|
524
|
+
)
|
|
525
|
+
|
|
526
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
527
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
528
|
+
tool_output = ToolOutput(
|
|
529
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
530
|
+
)
|
|
531
|
+
|
|
532
|
+
return tool_output
|
|
459
533
|
|
|
460
534
|
async def rewrite(
|
|
461
535
|
self,
|
|
@@ -465,56 +539,69 @@ class AsyncTheTool:
|
|
|
465
539
|
user_prompt: str | None = None,
|
|
466
540
|
temperature: float | None = 0.0,
|
|
467
541
|
logprobs: bool = False,
|
|
468
|
-
top_logprobs: int
|
|
542
|
+
top_logprobs: int = 3,
|
|
469
543
|
mode: Literal["positive", "negative", "hard_negative"] = "positive",
|
|
470
544
|
validator: Callable[[Any], bool] | None = None,
|
|
471
545
|
max_validation_retries: int | None = None,
|
|
472
|
-
priority: int | None =
|
|
473
|
-
) ->
|
|
546
|
+
priority: int | None = None,
|
|
547
|
+
) -> ToolOutput:
|
|
474
548
|
"""
|
|
475
549
|
Rewrite a text with different modes.
|
|
476
550
|
|
|
477
551
|
Arguments:
|
|
478
|
-
text: The input text
|
|
552
|
+
text: The input text
|
|
479
553
|
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
|
|
554
|
+
output_lang: Language for the output
|
|
555
|
+
user_prompt: Additional instructions
|
|
556
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
483
557
|
logprobs: Whether to return token probability information
|
|
484
558
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
485
|
-
mode: Rewriting mode - 'positive', 'negative', or 'hard_negative'
|
|
486
559
|
validator: Custom validation function to validate the output
|
|
487
560
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
488
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
561
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
489
562
|
|
|
490
563
|
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
|
|
564
|
+
ToolOutput
|
|
496
565
|
"""
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
566
|
+
tool_name = sys._getframe().f_code.co_name
|
|
567
|
+
start = perf_counter()
|
|
568
|
+
|
|
569
|
+
try:
|
|
570
|
+
operator_output = await self._operator.run(
|
|
571
|
+
# User parameters
|
|
572
|
+
text=text,
|
|
573
|
+
with_analysis=with_analysis,
|
|
574
|
+
output_lang=output_lang,
|
|
575
|
+
user_prompt=user_prompt,
|
|
576
|
+
temperature=temperature,
|
|
577
|
+
logprobs=logprobs,
|
|
578
|
+
top_logprobs=top_logprobs,
|
|
579
|
+
validator=validator,
|
|
580
|
+
max_validation_retries=max_validation_retries,
|
|
581
|
+
priority=priority,
|
|
582
|
+
# Internal parameters
|
|
583
|
+
tool_name=tool_name,
|
|
584
|
+
output_model=Str,
|
|
585
|
+
mode=mode,
|
|
586
|
+
)
|
|
587
|
+
|
|
588
|
+
metadata = ToolOutputMetadata(
|
|
589
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
590
|
+
)
|
|
591
|
+
tool_output = ToolOutput(
|
|
592
|
+
result=operator_output.result,
|
|
593
|
+
logprobs=operator_output.logprobs,
|
|
594
|
+
analysis=operator_output.analysis,
|
|
595
|
+
metadata=metadata,
|
|
596
|
+
)
|
|
597
|
+
|
|
598
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
599
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
600
|
+
tool_output = ToolOutput(
|
|
601
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
602
|
+
)
|
|
603
|
+
|
|
604
|
+
return tool_output
|
|
518
605
|
|
|
519
606
|
async def subject_to_question(
|
|
520
607
|
self,
|
|
@@ -525,11 +612,11 @@ class AsyncTheTool:
|
|
|
525
612
|
user_prompt: str | None = None,
|
|
526
613
|
temperature: float | None = 0.0,
|
|
527
614
|
logprobs: bool = False,
|
|
528
|
-
top_logprobs: int
|
|
615
|
+
top_logprobs: int = 3,
|
|
529
616
|
validator: Callable[[Any], bool] | None = None,
|
|
530
617
|
max_validation_retries: int | None = None,
|
|
531
|
-
priority: int | None =
|
|
532
|
-
) ->
|
|
618
|
+
priority: int | None = None,
|
|
619
|
+
) -> ToolOutput:
|
|
533
620
|
"""
|
|
534
621
|
Generate a list of questions about a subject.
|
|
535
622
|
|
|
@@ -537,44 +624,58 @@ class AsyncTheTool:
|
|
|
537
624
|
text: The subject text to generate questions about
|
|
538
625
|
number_of_questions: Number of questions to generate
|
|
539
626
|
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
|
|
627
|
+
output_lang: Language for the output
|
|
628
|
+
user_prompt: Additional instructions
|
|
629
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
543
630
|
logprobs: Whether to return token probability information
|
|
544
631
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
545
632
|
validator: Custom validation function to validate the output
|
|
546
633
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
547
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
634
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
548
635
|
|
|
549
636
|
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
|
|
637
|
+
ToolOutput
|
|
555
638
|
"""
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
639
|
+
tool_name = sys._getframe().f_code.co_name
|
|
640
|
+
start = perf_counter()
|
|
641
|
+
|
|
642
|
+
try:
|
|
643
|
+
operator_output = await self._operator.run(
|
|
644
|
+
# User parameters
|
|
645
|
+
text=text,
|
|
646
|
+
number_of_questions=number_of_questions,
|
|
647
|
+
with_analysis=with_analysis,
|
|
648
|
+
output_lang=output_lang,
|
|
649
|
+
user_prompt=user_prompt,
|
|
650
|
+
temperature=temperature,
|
|
651
|
+
logprobs=logprobs,
|
|
652
|
+
top_logprobs=top_logprobs,
|
|
653
|
+
validator=validator,
|
|
654
|
+
max_validation_retries=max_validation_retries,
|
|
655
|
+
priority=priority,
|
|
656
|
+
# Internal parameters
|
|
657
|
+
tool_name=tool_name,
|
|
658
|
+
output_model=ReasonListStr,
|
|
659
|
+
mode=None,
|
|
660
|
+
)
|
|
661
|
+
|
|
662
|
+
metadata = ToolOutputMetadata(
|
|
663
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
664
|
+
)
|
|
665
|
+
tool_output = ToolOutput(
|
|
666
|
+
result=operator_output.result,
|
|
667
|
+
logprobs=operator_output.logprobs,
|
|
668
|
+
analysis=operator_output.analysis,
|
|
669
|
+
metadata=metadata,
|
|
670
|
+
)
|
|
671
|
+
|
|
672
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
673
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
674
|
+
tool_output = ToolOutput(
|
|
675
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
676
|
+
)
|
|
677
|
+
|
|
678
|
+
return tool_output
|
|
578
679
|
|
|
579
680
|
async def summarize(
|
|
580
681
|
self,
|
|
@@ -584,221 +685,409 @@ class AsyncTheTool:
|
|
|
584
685
|
user_prompt: str | None = None,
|
|
585
686
|
temperature: float | None = 0.0,
|
|
586
687
|
logprobs: bool = False,
|
|
587
|
-
top_logprobs: int
|
|
688
|
+
top_logprobs: int = 3,
|
|
588
689
|
validator: Callable[[Any], bool] | None = None,
|
|
589
690
|
max_validation_retries: int | None = None,
|
|
590
|
-
priority: int | None =
|
|
591
|
-
) ->
|
|
691
|
+
priority: int | None = None,
|
|
692
|
+
) -> ToolOutput:
|
|
592
693
|
"""
|
|
593
694
|
Summarize the given subject text.
|
|
594
695
|
|
|
595
696
|
Arguments:
|
|
596
|
-
text: The input text
|
|
697
|
+
text: The input text
|
|
597
698
|
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
|
|
699
|
+
output_lang: Language for the output
|
|
700
|
+
user_prompt: Additional instructions
|
|
701
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
601
702
|
logprobs: Whether to return token probability information
|
|
602
703
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
603
704
|
validator: Custom validation function to validate the output
|
|
604
705
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
605
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
706
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
606
707
|
|
|
607
708
|
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
|
|
709
|
+
ToolOutput
|
|
613
710
|
"""
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
711
|
+
tool_name = sys._getframe().f_code.co_name
|
|
712
|
+
start = perf_counter()
|
|
713
|
+
|
|
714
|
+
try:
|
|
715
|
+
operator_output = await self._operator.run(
|
|
716
|
+
# User parameters
|
|
717
|
+
text=text,
|
|
718
|
+
with_analysis=with_analysis,
|
|
719
|
+
output_lang=output_lang,
|
|
720
|
+
user_prompt=user_prompt,
|
|
721
|
+
temperature=temperature,
|
|
722
|
+
logprobs=logprobs,
|
|
723
|
+
top_logprobs=top_logprobs,
|
|
724
|
+
validator=validator,
|
|
725
|
+
max_validation_retries=max_validation_retries,
|
|
726
|
+
priority=priority,
|
|
727
|
+
# Internal parameters
|
|
728
|
+
tool_name=tool_name,
|
|
729
|
+
output_model=Str,
|
|
730
|
+
mode=None,
|
|
731
|
+
)
|
|
732
|
+
|
|
733
|
+
metadata = ToolOutputMetadata(
|
|
734
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
735
|
+
)
|
|
736
|
+
tool_output = ToolOutput(
|
|
737
|
+
result=operator_output.result,
|
|
738
|
+
logprobs=operator_output.logprobs,
|
|
739
|
+
analysis=operator_output.analysis,
|
|
740
|
+
metadata=metadata,
|
|
741
|
+
)
|
|
742
|
+
|
|
743
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
744
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
745
|
+
tool_output = ToolOutput(
|
|
746
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
747
|
+
)
|
|
748
|
+
|
|
749
|
+
return tool_output
|
|
635
750
|
|
|
636
751
|
async def translate(
|
|
637
752
|
self,
|
|
638
753
|
text: str,
|
|
639
754
|
target_language: str,
|
|
755
|
+
use_chunker: bool = True,
|
|
640
756
|
with_analysis: bool = False,
|
|
641
757
|
user_prompt: str | None = None,
|
|
642
758
|
temperature: float | None = 0.0,
|
|
643
759
|
logprobs: bool = False,
|
|
644
|
-
top_logprobs: int
|
|
760
|
+
top_logprobs: int = 3,
|
|
645
761
|
validator: Callable[[Any], bool] | None = None,
|
|
646
762
|
max_validation_retries: int | None = None,
|
|
647
|
-
priority: int | None =
|
|
648
|
-
) ->
|
|
763
|
+
priority: int | None = None,
|
|
764
|
+
) -> ToolOutput:
|
|
649
765
|
"""
|
|
650
766
|
Translate text between languages.
|
|
651
767
|
|
|
768
|
+
Important Note: This tool is EXPERIMENTAL, you can use it but it isn't reliable.
|
|
769
|
+
|
|
652
770
|
Arguments:
|
|
653
|
-
text: The input text
|
|
771
|
+
text: The input text
|
|
654
772
|
target_language: The target language for translation
|
|
773
|
+
use_chunker: Whether to use text chunker for text length bigger than 1500
|
|
774
|
+
with_analysis: Whether to include detailed reasoning analysis
|
|
775
|
+
user_prompt: Additional instructions
|
|
776
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
777
|
+
logprobs: Whether to return token probability information
|
|
778
|
+
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
779
|
+
validator: Custom validation function to validate the output
|
|
780
|
+
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
781
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
782
|
+
|
|
783
|
+
Returns:
|
|
784
|
+
ToolOutput
|
|
785
|
+
"""
|
|
786
|
+
tool_name = sys._getframe().f_code.co_name
|
|
787
|
+
start = perf_counter()
|
|
788
|
+
|
|
789
|
+
try:
|
|
790
|
+
if len(text.split(" ")) > 1500 and use_chunker:
|
|
791
|
+
chunks = text_to_chunks(text, 1200, 0)
|
|
792
|
+
translation = ""
|
|
793
|
+
analysis = ""
|
|
794
|
+
logprobs_list = []
|
|
795
|
+
|
|
796
|
+
for chunk in chunks:
|
|
797
|
+
chunk_operator_output = await self._operator.run(
|
|
798
|
+
# User parameters
|
|
799
|
+
text=chunk,
|
|
800
|
+
target_language=target_language,
|
|
801
|
+
with_analysis=with_analysis,
|
|
802
|
+
user_prompt=user_prompt,
|
|
803
|
+
temperature=temperature,
|
|
804
|
+
logprobs=logprobs,
|
|
805
|
+
top_logprobs=top_logprobs,
|
|
806
|
+
validator=validator,
|
|
807
|
+
max_validation_retries=max_validation_retries,
|
|
808
|
+
priority=priority,
|
|
809
|
+
# Internal parameters
|
|
810
|
+
tool_name=tool_name,
|
|
811
|
+
output_model=Str,
|
|
812
|
+
mode=None,
|
|
813
|
+
output_lang=None,
|
|
814
|
+
)
|
|
815
|
+
|
|
816
|
+
translation += chunk_operator_output.result + "\n"
|
|
817
|
+
|
|
818
|
+
if with_analysis:
|
|
819
|
+
analysis += chunk_operator_output.analysis
|
|
820
|
+
if logprobs:
|
|
821
|
+
logprobs_list.extend(chunk_operator_output.logprobs)
|
|
822
|
+
|
|
823
|
+
metadata = ToolOutputMetadata(
|
|
824
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
825
|
+
)
|
|
826
|
+
tool_output = ToolOutput(
|
|
827
|
+
result=translation,
|
|
828
|
+
logprobs=logprobs_list,
|
|
829
|
+
analysis=analysis,
|
|
830
|
+
metadata=metadata,
|
|
831
|
+
)
|
|
832
|
+
|
|
833
|
+
else:
|
|
834
|
+
operator_output = await self._operator.run(
|
|
835
|
+
# User parameters
|
|
836
|
+
text=text,
|
|
837
|
+
target_language=target_language,
|
|
838
|
+
with_analysis=with_analysis,
|
|
839
|
+
user_prompt=user_prompt,
|
|
840
|
+
temperature=temperature,
|
|
841
|
+
logprobs=logprobs,
|
|
842
|
+
top_logprobs=top_logprobs,
|
|
843
|
+
validator=validator,
|
|
844
|
+
max_validation_retries=max_validation_retries,
|
|
845
|
+
priority=priority,
|
|
846
|
+
# Internal parameters
|
|
847
|
+
tool_name=tool_name,
|
|
848
|
+
output_model=Str,
|
|
849
|
+
mode=None,
|
|
850
|
+
output_lang=None,
|
|
851
|
+
)
|
|
852
|
+
|
|
853
|
+
metadata = ToolOutputMetadata(
|
|
854
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
855
|
+
)
|
|
856
|
+
tool_output = ToolOutput(
|
|
857
|
+
result=operator_output.result,
|
|
858
|
+
logprobs=operator_output.logprobs,
|
|
859
|
+
analysis=operator_output.analysis,
|
|
860
|
+
metadata=metadata,
|
|
861
|
+
)
|
|
862
|
+
|
|
863
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
864
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
865
|
+
tool_output = ToolOutput(
|
|
866
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
867
|
+
)
|
|
868
|
+
|
|
869
|
+
return tool_output
|
|
870
|
+
|
|
871
|
+
async def propositionize(
|
|
872
|
+
self,
|
|
873
|
+
text: str,
|
|
874
|
+
with_analysis: bool = False,
|
|
875
|
+
output_lang: str | None = None,
|
|
876
|
+
user_prompt: str | None = None,
|
|
877
|
+
temperature: float | None = 0.0,
|
|
878
|
+
logprobs: bool = False,
|
|
879
|
+
top_logprobs: int = 3,
|
|
880
|
+
validator: Callable[[Any], bool] | None = None,
|
|
881
|
+
max_validation_retries: int | None = None,
|
|
882
|
+
priority: int | None = None,
|
|
883
|
+
) -> ToolOutput:
|
|
884
|
+
"""
|
|
885
|
+
Proposition input text to meaningful sentences.
|
|
886
|
+
|
|
887
|
+
Important Note: This tool is EXPERIMENTAL, you can use it but it isn't reliable.
|
|
888
|
+
|
|
889
|
+
Arguments:
|
|
890
|
+
text: The input text
|
|
655
891
|
with_analysis: Whether to include detailed reasoning analysis
|
|
656
|
-
|
|
657
|
-
|
|
892
|
+
output_lang: Language for the output
|
|
893
|
+
user_prompt: Additional instructions
|
|
894
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
658
895
|
logprobs: Whether to return token probability information
|
|
659
896
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
660
897
|
validator: Custom validation function to validate the output
|
|
661
898
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
662
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
899
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
663
900
|
|
|
664
901
|
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
|
|
902
|
+
ToolOutput
|
|
670
903
|
"""
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
904
|
+
tool_name = sys._getframe().f_code.co_name
|
|
905
|
+
start = perf_counter()
|
|
906
|
+
|
|
907
|
+
try:
|
|
908
|
+
operator_output = await self._operator.run(
|
|
909
|
+
# User parameters
|
|
910
|
+
text=text,
|
|
911
|
+
with_analysis=with_analysis,
|
|
912
|
+
output_lang=output_lang,
|
|
913
|
+
user_prompt=user_prompt,
|
|
914
|
+
temperature=temperature,
|
|
915
|
+
logprobs=logprobs,
|
|
916
|
+
top_logprobs=top_logprobs,
|
|
917
|
+
validator=validator,
|
|
918
|
+
max_validation_retries=max_validation_retries,
|
|
919
|
+
priority=priority,
|
|
920
|
+
# Internal parameters
|
|
921
|
+
tool_name=tool_name,
|
|
922
|
+
output_model=ListStr,
|
|
923
|
+
mode=None,
|
|
924
|
+
)
|
|
925
|
+
|
|
926
|
+
metadata = ToolOutputMetadata(
|
|
927
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
928
|
+
)
|
|
929
|
+
tool_output = ToolOutput(
|
|
930
|
+
result=operator_output.result,
|
|
931
|
+
logprobs=operator_output.logprobs,
|
|
932
|
+
analysis=operator_output.analysis,
|
|
933
|
+
metadata=metadata,
|
|
934
|
+
)
|
|
935
|
+
|
|
936
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
937
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
938
|
+
tool_output = ToolOutput(
|
|
939
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
940
|
+
)
|
|
941
|
+
|
|
942
|
+
return tool_output
|
|
943
|
+
|
|
944
|
+
async def check_fact(
|
|
695
945
|
self,
|
|
696
946
|
text: str,
|
|
947
|
+
source_text: str,
|
|
697
948
|
with_analysis: bool = False,
|
|
698
949
|
output_lang: str | None = None,
|
|
699
950
|
user_prompt: str | None = None,
|
|
700
951
|
temperature: float | None = 0.0,
|
|
701
952
|
logprobs: bool = False,
|
|
702
|
-
top_logprobs: int
|
|
953
|
+
top_logprobs: int = 3,
|
|
703
954
|
validator: Callable[[Any], bool] | None = None,
|
|
704
955
|
max_validation_retries: int | None = None,
|
|
705
|
-
priority: int | None =
|
|
706
|
-
) ->
|
|
956
|
+
priority: int | None = None,
|
|
957
|
+
) -> ToolOutput:
|
|
707
958
|
"""
|
|
708
|
-
|
|
959
|
+
Checks wheather a statement is relevant to the source text or not.
|
|
960
|
+
|
|
961
|
+
Important Note: This tool is EXPERIMENTAL, you can use it but it isn't reliable.
|
|
709
962
|
|
|
710
963
|
Arguments:
|
|
711
964
|
text: The input text
|
|
965
|
+
source_text: the source text that we want to check relation of text to it
|
|
712
966
|
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
|
|
967
|
+
output_lang: Language for the output
|
|
968
|
+
user_prompt: Additional instructions
|
|
969
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
716
970
|
logprobs: Whether to return token probability information
|
|
717
971
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
718
972
|
validator: Custom validation function to validate the output
|
|
719
973
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
720
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
974
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
721
975
|
|
|
722
976
|
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
|
|
977
|
+
ToolOutput
|
|
728
978
|
"""
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
979
|
+
tool_name = sys._getframe().f_code.co_name
|
|
980
|
+
start = perf_counter()
|
|
981
|
+
|
|
982
|
+
try:
|
|
983
|
+
operator_output = await self._operator.run(
|
|
984
|
+
# User parameters
|
|
985
|
+
text=text,
|
|
986
|
+
with_analysis=with_analysis,
|
|
987
|
+
output_lang=output_lang,
|
|
988
|
+
user_prompt=user_prompt,
|
|
989
|
+
temperature=temperature,
|
|
990
|
+
logprobs=logprobs,
|
|
991
|
+
top_logprobs=top_logprobs,
|
|
992
|
+
validator=validator,
|
|
993
|
+
max_validation_retries=max_validation_retries,
|
|
994
|
+
priority=priority,
|
|
995
|
+
# Internal parameters
|
|
996
|
+
tool_name=tool_name,
|
|
997
|
+
output_model=Bool,
|
|
998
|
+
mode=None,
|
|
999
|
+
source_text=source_text,
|
|
1000
|
+
)
|
|
1001
|
+
|
|
1002
|
+
metadata = ToolOutputMetadata(
|
|
1003
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
1004
|
+
)
|
|
1005
|
+
tool_output = ToolOutput(
|
|
1006
|
+
result=operator_output.result,
|
|
1007
|
+
logprobs=operator_output.logprobs,
|
|
1008
|
+
analysis=operator_output.analysis,
|
|
1009
|
+
metadata=metadata,
|
|
1010
|
+
)
|
|
1011
|
+
|
|
1012
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
1013
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
1014
|
+
tool_output = ToolOutput(
|
|
1015
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
1016
|
+
)
|
|
1017
|
+
|
|
1018
|
+
return tool_output
|
|
750
1019
|
|
|
751
1020
|
async def run_custom(
|
|
752
1021
|
self,
|
|
753
1022
|
prompt: str,
|
|
754
1023
|
output_model: Any,
|
|
1024
|
+
with_analysis: bool = False,
|
|
1025
|
+
analyze_template: str | None = None,
|
|
755
1026
|
output_lang: str | None = None,
|
|
756
1027
|
temperature: float | None = None,
|
|
757
1028
|
logprobs: bool | None = None,
|
|
758
|
-
top_logprobs: int
|
|
1029
|
+
top_logprobs: int = 3,
|
|
759
1030
|
validator: Callable[[Any], bool] | None = None,
|
|
760
1031
|
max_validation_retries: int | None = None,
|
|
761
|
-
priority: int | None =
|
|
762
|
-
) ->
|
|
1032
|
+
priority: int | None = None,
|
|
1033
|
+
) -> ToolOutput:
|
|
763
1034
|
"""
|
|
764
1035
|
Custom tool that can do almost anything!
|
|
765
1036
|
|
|
766
1037
|
Arguments:
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
1038
|
+
prompt: The user prompt
|
|
1039
|
+
output_model: Pydantic BaseModel used for structured output
|
|
1040
|
+
with_analysis: Whether to include detailed reasoning analysis
|
|
1041
|
+
analyze_template: The analyze template used for reasoning analysis
|
|
1042
|
+
output_lang: Language for the output
|
|
1043
|
+
temperature: Controls randomness (0.0 - 2.0)
|
|
770
1044
|
logprobs: Whether to return token probability information
|
|
771
1045
|
top_logprobs: Number of top token alternatives to return if logprobs enabled
|
|
772
1046
|
validator: Custom validation function to validate the output
|
|
773
1047
|
max_validation_retries: Maximum number of retry attempts if validation fails
|
|
774
|
-
priority: Task execution priority (if enabled by vLLM and model)
|
|
1048
|
+
priority: Task execution priority (if enabled by vLLM and the model)
|
|
775
1049
|
|
|
776
1050
|
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
|
|
1051
|
+
ToolOutput
|
|
782
1052
|
"""
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
1053
|
+
tool_name = sys._getframe().f_code.co_name
|
|
1054
|
+
start = perf_counter()
|
|
1055
|
+
|
|
1056
|
+
try:
|
|
1057
|
+
operator_output = await self._operator.run(
|
|
1058
|
+
# User paramaeters
|
|
1059
|
+
text=prompt,
|
|
1060
|
+
output_model=output_model,
|
|
1061
|
+
with_analysis=with_analysis,
|
|
1062
|
+
analyze_template=analyze_template,
|
|
1063
|
+
output_model_str=output_model.model_json_schema(),
|
|
1064
|
+
output_lang=output_lang,
|
|
1065
|
+
temperature=temperature,
|
|
1066
|
+
logprobs=logprobs,
|
|
1067
|
+
top_logprobs=top_logprobs,
|
|
1068
|
+
validator=validator,
|
|
1069
|
+
max_validation_retries=max_validation_retries,
|
|
1070
|
+
priority=priority,
|
|
1071
|
+
# Internal parameters
|
|
1072
|
+
tool_name=tool_name,
|
|
1073
|
+
user_prompt=None,
|
|
1074
|
+
mode=None,
|
|
1075
|
+
)
|
|
1076
|
+
|
|
1077
|
+
metadata = ToolOutputMetadata(
|
|
1078
|
+
tool_name=tool_name, execution_time=perf_counter() - start
|
|
1079
|
+
)
|
|
1080
|
+
tool_output = ToolOutput(
|
|
1081
|
+
result=operator_output.result,
|
|
1082
|
+
logprobs=operator_output.logprobs,
|
|
1083
|
+
analysis=operator_output.analysis,
|
|
1084
|
+
metadata=metadata,
|
|
1085
|
+
)
|
|
1086
|
+
|
|
1087
|
+
except (PromptError, LLMError, ValidationError, TextToolsError, Exception) as e:
|
|
1088
|
+
metadata = ToolOutputMetadata(tool_name=tool_name)
|
|
1089
|
+
tool_output = ToolOutput(
|
|
1090
|
+
errors=[f"{type(e).__name__}: {e}"], metadata=metadata
|
|
1091
|
+
)
|
|
1092
|
+
|
|
1093
|
+
return tool_output
|