hamtaa-texttools 1.1.14__tar.gz → 1.1.16__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hamtaa_texttools-1.1.14/hamtaa_texttools.egg-info → hamtaa_texttools-1.1.16}/PKG-INFO +10 -7
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/README.md +9 -6
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16/hamtaa_texttools.egg-info}/PKG-INFO +10 -7
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/hamtaa_texttools.egg-info/SOURCES.txt +0 -3
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/pyproject.toml +1 -1
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/tests/test_all_tools.py +22 -4
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/tools/async_tools.py +86 -27
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/tools/internals/async_operator.py +2 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/tools/internals/models.py +18 -16
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/tools/internals/sync_operator.py +2 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/tools/sync_tools.py +86 -25
- hamtaa_texttools-1.1.14/tests/test_category_tree.py +0 -47
- hamtaa_texttools-1.1.14/tests/test_keyword_extractor_modes.py +0 -43
- hamtaa_texttools-1.1.14/tests/test_logprobs.py +0 -38
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/LICENSE +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/MANIFEST.in +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/hamtaa_texttools.egg-info/dependency_links.txt +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/hamtaa_texttools.egg-info/requires.txt +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/hamtaa_texttools.egg-info/top_level.txt +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/setup.cfg +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/tests/test_all_async_tools.py +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/tests/test_output_validation.py +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/__init__.py +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/batch/batch_config.py +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/batch/batch_runner.py +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/batch/internals/batch_manager.py +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/batch/internals/utils.py +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/prompts/README.md +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/prompts/categorize.yaml +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/prompts/detect_entity.yaml +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/prompts/extract_entities.yaml +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/prompts/extract_keywords.yaml +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/prompts/is_question.yaml +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/prompts/merge_questions.yaml +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/prompts/rewrite.yaml +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/prompts/run_custom.yaml +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/prompts/subject_to_question.yaml +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/prompts/summarize.yaml +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/prompts/text_to_question.yaml +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/prompts/translate.yaml +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/tools/internals/formatters.py +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/tools/internals/operator_utils.py +0 -0
- {hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/tools/internals/prompt_loader.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hamtaa-texttools
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.16
|
|
4
4
|
Summary: A high-level NLP toolkit built on top of modern LLMs.
|
|
5
5
|
Author-email: Tohidi <the.mohammad.tohidi@gmail.com>, Montazer <montazerh82@gmail.com>, Givechi <mohamad.m.givechi@gmail.com>, MoosaviNejad <erfanmoosavi84@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -92,12 +92,15 @@ TextTools provides several optional flags to customize LLM behavior:
|
|
|
92
92
|
## 🧩 ToolOutput
|
|
93
93
|
|
|
94
94
|
Every tool of `TextTools` returns a `ToolOutput` object which is a BaseModel with attributes:
|
|
95
|
-
- **`result
|
|
96
|
-
- **`analysis
|
|
97
|
-
- **`logprobs
|
|
98
|
-
- **`
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
- **`result: Any`** → The output of LLM
|
|
96
|
+
- **`analysis: str`** → The reasoning step before generating the final output
|
|
97
|
+
- **`logprobs: list`** → Token-level probabilities for the generated output
|
|
98
|
+
- **`process: str`** → The tool name which processed the input
|
|
99
|
+
- **`processed_at: datetime`** → The process time
|
|
100
|
+
- **`execution_time: float`** → The execution time (seconds)
|
|
101
|
+
- **`errors: list[str]`** → Any error that have occured during calling LLM
|
|
102
|
+
|
|
103
|
+
**Note:** You can use `repr(ToolOutput)` to see details of your ToolOutput.
|
|
101
104
|
|
|
102
105
|
---
|
|
103
106
|
|
|
@@ -57,12 +57,15 @@ TextTools provides several optional flags to customize LLM behavior:
|
|
|
57
57
|
## 🧩 ToolOutput
|
|
58
58
|
|
|
59
59
|
Every tool of `TextTools` returns a `ToolOutput` object which is a BaseModel with attributes:
|
|
60
|
-
- **`result
|
|
61
|
-
- **`analysis
|
|
62
|
-
- **`logprobs
|
|
63
|
-
- **`
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
- **`result: Any`** → The output of LLM
|
|
61
|
+
- **`analysis: str`** → The reasoning step before generating the final output
|
|
62
|
+
- **`logprobs: list`** → Token-level probabilities for the generated output
|
|
63
|
+
- **`process: str`** → The tool name which processed the input
|
|
64
|
+
- **`processed_at: datetime`** → The process time
|
|
65
|
+
- **`execution_time: float`** → The execution time (seconds)
|
|
66
|
+
- **`errors: list[str]`** → Any error that have occured during calling LLM
|
|
67
|
+
|
|
68
|
+
**Note:** You can use `repr(ToolOutput)` to see details of your ToolOutput.
|
|
66
69
|
|
|
67
70
|
---
|
|
68
71
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hamtaa-texttools
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.16
|
|
4
4
|
Summary: A high-level NLP toolkit built on top of modern LLMs.
|
|
5
5
|
Author-email: Tohidi <the.mohammad.tohidi@gmail.com>, Montazer <montazerh82@gmail.com>, Givechi <mohamad.m.givechi@gmail.com>, MoosaviNejad <erfanmoosavi84@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -92,12 +92,15 @@ TextTools provides several optional flags to customize LLM behavior:
|
|
|
92
92
|
## 🧩 ToolOutput
|
|
93
93
|
|
|
94
94
|
Every tool of `TextTools` returns a `ToolOutput` object which is a BaseModel with attributes:
|
|
95
|
-
- **`result
|
|
96
|
-
- **`analysis
|
|
97
|
-
- **`logprobs
|
|
98
|
-
- **`
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
- **`result: Any`** → The output of LLM
|
|
96
|
+
- **`analysis: str`** → The reasoning step before generating the final output
|
|
97
|
+
- **`logprobs: list`** → Token-level probabilities for the generated output
|
|
98
|
+
- **`process: str`** → The tool name which processed the input
|
|
99
|
+
- **`processed_at: datetime`** → The process time
|
|
100
|
+
- **`execution_time: float`** → The execution time (seconds)
|
|
101
|
+
- **`errors: list[str]`** → Any error that have occured during calling LLM
|
|
102
|
+
|
|
103
|
+
**Note:** You can use `repr(ToolOutput)` to see details of your ToolOutput.
|
|
101
104
|
|
|
102
105
|
---
|
|
103
106
|
|
|
@@ -9,9 +9,6 @@ hamtaa_texttools.egg-info/requires.txt
|
|
|
9
9
|
hamtaa_texttools.egg-info/top_level.txt
|
|
10
10
|
tests/test_all_async_tools.py
|
|
11
11
|
tests/test_all_tools.py
|
|
12
|
-
tests/test_category_tree.py
|
|
13
|
-
tests/test_keyword_extractor_modes.py
|
|
14
|
-
tests/test_logprobs.py
|
|
15
12
|
tests/test_output_validation.py
|
|
16
13
|
texttools/__init__.py
|
|
17
14
|
texttools/batch/batch_config.py
|
|
@@ -4,7 +4,7 @@ from dotenv import load_dotenv
|
|
|
4
4
|
from openai import OpenAI
|
|
5
5
|
from pydantic import BaseModel
|
|
6
6
|
|
|
7
|
-
from texttools import TheTool
|
|
7
|
+
from texttools import TheTool, CategoryTree
|
|
8
8
|
|
|
9
9
|
# Load environment variables from .env
|
|
10
10
|
load_dotenv()
|
|
@@ -18,12 +18,31 @@ client = OpenAI(base_url=BASE_URL, api_key=API_KEY)
|
|
|
18
18
|
# Create an instance of TheTool
|
|
19
19
|
t = TheTool(client=client, model=MODEL)
|
|
20
20
|
|
|
21
|
-
# Categorizer
|
|
21
|
+
# Categorizer: list mode
|
|
22
22
|
category = t.categorize("سلام حالت چطوره؟", categories=["هیچکدام", "دینی", "فلسفه"])
|
|
23
23
|
print(repr(category))
|
|
24
24
|
|
|
25
|
+
# Categorizer: tree mode
|
|
26
|
+
tree = CategoryTree("category_test_tree")
|
|
27
|
+
tree.add_node("اخلاق")
|
|
28
|
+
tree.add_node("معرفت شناسی")
|
|
29
|
+
tree.add_node("متافیزیک", description="اراده قدرت در حیطه متافیزیک است")
|
|
30
|
+
tree.add_node("فلسفه ذهن", description="فلسفه ذهن به چگونگی درک ما از جهان می پردازد")
|
|
31
|
+
tree.add_node("آگاهی", "فلسفه ذهن", description="آگاهی خیلی مهم است")
|
|
32
|
+
tree.add_node("ذهن و بدن", "فلسفه ذهن")
|
|
33
|
+
tree.add_node("امکان و ضرورت", "متافیزیک")
|
|
34
|
+
|
|
35
|
+
categories = t.categorize(
|
|
36
|
+
"اراده قدرت مفهومی مهم در مابعد الطبیعه است که توسط نیچه مطرح شده",
|
|
37
|
+
tree,
|
|
38
|
+
mode="category_tree",
|
|
39
|
+
)
|
|
40
|
+
print(repr(categories))
|
|
41
|
+
|
|
25
42
|
# Keyword Extractor
|
|
26
|
-
keywords = t.extract_keywords(
|
|
43
|
+
keywords = t.extract_keywords(
|
|
44
|
+
"Tomorrow, we will be dead by the car crash", mode="count", number_of_keywords=3
|
|
45
|
+
)
|
|
27
46
|
print(repr(keywords))
|
|
28
47
|
|
|
29
48
|
# NER Extractor
|
|
@@ -50,7 +69,6 @@ print(repr(merged))
|
|
|
50
69
|
rewritten = t.rewrite(
|
|
51
70
|
"چرا ما انسان ها، موجوداتی اجتماعی هستیم؟",
|
|
52
71
|
mode="positive",
|
|
53
|
-
with_analysis=True,
|
|
54
72
|
)
|
|
55
73
|
print(repr(rewritten))
|
|
56
74
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from datetime import datetime
|
|
1
2
|
from typing import Literal, Any
|
|
2
3
|
from collections.abc import Callable
|
|
3
4
|
|
|
@@ -63,10 +64,12 @@ class AsyncTheTool:
|
|
|
63
64
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
64
65
|
- errors (list(str) | None): Errors occured during tool call
|
|
65
66
|
"""
|
|
67
|
+
start = datetime.now()
|
|
68
|
+
|
|
66
69
|
if mode == "category_tree":
|
|
67
70
|
# Initializations
|
|
68
71
|
output = Models.ToolOutput()
|
|
69
|
-
levels = categories.
|
|
72
|
+
levels = categories.get_level_count()
|
|
70
73
|
parent_id = 0
|
|
71
74
|
final_output = []
|
|
72
75
|
|
|
@@ -80,6 +83,8 @@ class AsyncTheTool:
|
|
|
80
83
|
output.errors.append(
|
|
81
84
|
f"No categories found for parent_id {parent_id} in the tree"
|
|
82
85
|
)
|
|
86
|
+
end = datetime.now()
|
|
87
|
+
output.execution_time = (end - start).total_seconds()
|
|
83
88
|
return output
|
|
84
89
|
|
|
85
90
|
# Extract category names and descriptions
|
|
@@ -111,6 +116,8 @@ class AsyncTheTool:
|
|
|
111
116
|
# Check for errors from operator
|
|
112
117
|
if level_output.errors:
|
|
113
118
|
output.errors.extend(level_output.errors)
|
|
119
|
+
end = datetime.now()
|
|
120
|
+
output.execution_time = (end - start).total_seconds()
|
|
114
121
|
return output
|
|
115
122
|
|
|
116
123
|
# Get the chosen category
|
|
@@ -122,20 +129,25 @@ class AsyncTheTool:
|
|
|
122
129
|
output.errors.append(
|
|
123
130
|
f"Category '{chosen_category}' not found in tree after selection"
|
|
124
131
|
)
|
|
132
|
+
end = datetime.now()
|
|
133
|
+
output.execution_time = (end - start).total_seconds()
|
|
125
134
|
return output
|
|
126
135
|
|
|
127
136
|
parent_id = parent_node.node_id
|
|
128
137
|
final_output.append(parent_node.name)
|
|
129
138
|
|
|
130
|
-
# Copy analysis/logprobs from the last level's output
|
|
139
|
+
# Copy analysis/logprobs/process from the last level's output
|
|
131
140
|
output.analysis = level_output.analysis
|
|
132
141
|
output.logprobs = level_output.logprobs
|
|
142
|
+
output.process = level_output.process
|
|
133
143
|
|
|
134
144
|
output.result = final_output
|
|
145
|
+
end = datetime.now()
|
|
146
|
+
output.execution_time = (end - start).total_seconds()
|
|
135
147
|
return output
|
|
136
148
|
|
|
137
149
|
else:
|
|
138
|
-
|
|
150
|
+
output = await self._operator.run(
|
|
139
151
|
# User parameters
|
|
140
152
|
text=text,
|
|
141
153
|
category_list=categories,
|
|
@@ -152,6 +164,9 @@ class AsyncTheTool:
|
|
|
152
164
|
output_model=Models.create_dynamic_model(categories),
|
|
153
165
|
output_lang=None,
|
|
154
166
|
)
|
|
167
|
+
end = datetime.now()
|
|
168
|
+
output.execution_time = (end - start).total_seconds()
|
|
169
|
+
return output
|
|
155
170
|
|
|
156
171
|
async def extract_keywords(
|
|
157
172
|
self,
|
|
@@ -190,7 +205,8 @@ class AsyncTheTool:
|
|
|
190
205
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
191
206
|
- errors (list(str) | None): Errors occured during tool call
|
|
192
207
|
"""
|
|
193
|
-
|
|
208
|
+
start = datetime.now()
|
|
209
|
+
output = await self._operator.run(
|
|
194
210
|
# User parameters
|
|
195
211
|
text=text,
|
|
196
212
|
with_analysis=with_analysis,
|
|
@@ -203,11 +219,14 @@ class AsyncTheTool:
|
|
|
203
219
|
number_of_keywords=number_of_keywords,
|
|
204
220
|
validator=validator,
|
|
205
221
|
max_validation_retries=max_validation_retries,
|
|
222
|
+
priority=priority,
|
|
206
223
|
# Internal parameters
|
|
207
224
|
prompt_file="extract_keywords.yaml",
|
|
208
225
|
output_model=Models.ListStrOutput,
|
|
209
|
-
priority=priority,
|
|
210
226
|
)
|
|
227
|
+
end = datetime.now()
|
|
228
|
+
output.execution_time = (end - start).total_seconds()
|
|
229
|
+
return output
|
|
211
230
|
|
|
212
231
|
async def extract_entities(
|
|
213
232
|
self,
|
|
@@ -244,7 +263,8 @@ class AsyncTheTool:
|
|
|
244
263
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
245
264
|
- errors (list(str) | None): Errors occured during tool call
|
|
246
265
|
"""
|
|
247
|
-
|
|
266
|
+
start = datetime.now()
|
|
267
|
+
output = await self._operator.run(
|
|
248
268
|
# User parameters
|
|
249
269
|
text=text,
|
|
250
270
|
with_analysis=with_analysis,
|
|
@@ -255,12 +275,15 @@ class AsyncTheTool:
|
|
|
255
275
|
top_logprobs=top_logprobs,
|
|
256
276
|
validator=validator,
|
|
257
277
|
max_validation_retries=max_validation_retries,
|
|
278
|
+
priority=priority,
|
|
258
279
|
# Internal parameters
|
|
259
280
|
prompt_file="extract_entities.yaml",
|
|
260
281
|
output_model=Models.ListDictStrStrOutput,
|
|
261
282
|
mode=None,
|
|
262
|
-
priority=priority,
|
|
263
283
|
)
|
|
284
|
+
end = datetime.now()
|
|
285
|
+
output.execution_time = (end - start).total_seconds()
|
|
286
|
+
return output
|
|
264
287
|
|
|
265
288
|
async def is_question(
|
|
266
289
|
self,
|
|
@@ -295,7 +318,8 @@ class AsyncTheTool:
|
|
|
295
318
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
296
319
|
- errors (list(str) | None): Errors occured during tool call
|
|
297
320
|
"""
|
|
298
|
-
|
|
321
|
+
start = datetime.now()
|
|
322
|
+
output = await self._operator.run(
|
|
299
323
|
# User parameters
|
|
300
324
|
text=text,
|
|
301
325
|
with_analysis=with_analysis,
|
|
@@ -305,13 +329,16 @@ class AsyncTheTool:
|
|
|
305
329
|
top_logprobs=top_logprobs,
|
|
306
330
|
validator=validator,
|
|
307
331
|
max_validation_retries=max_validation_retries,
|
|
332
|
+
priority=priority,
|
|
308
333
|
# Internal parameters
|
|
309
334
|
prompt_file="is_question.yaml",
|
|
310
335
|
output_model=Models.BoolOutput,
|
|
311
336
|
mode=None,
|
|
312
337
|
output_lang=None,
|
|
313
|
-
priority=priority,
|
|
314
338
|
)
|
|
339
|
+
end = datetime.now()
|
|
340
|
+
output.execution_time = (end - start).total_seconds()
|
|
341
|
+
return output
|
|
315
342
|
|
|
316
343
|
async def text_to_question(
|
|
317
344
|
self,
|
|
@@ -348,7 +375,8 @@ class AsyncTheTool:
|
|
|
348
375
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
349
376
|
- errors (list(str) | None): Errors occured during tool call
|
|
350
377
|
"""
|
|
351
|
-
|
|
378
|
+
start = datetime.now()
|
|
379
|
+
output = await self._operator.run(
|
|
352
380
|
# User parameters
|
|
353
381
|
text=text,
|
|
354
382
|
with_analysis=with_analysis,
|
|
@@ -359,12 +387,15 @@ class AsyncTheTool:
|
|
|
359
387
|
top_logprobs=top_logprobs,
|
|
360
388
|
validator=validator,
|
|
361
389
|
max_validation_retries=max_validation_retries,
|
|
390
|
+
priority=priority,
|
|
362
391
|
# Internal parameters
|
|
363
392
|
prompt_file="text_to_question.yaml",
|
|
364
393
|
output_model=Models.StrOutput,
|
|
365
394
|
mode=None,
|
|
366
|
-
priority=priority,
|
|
367
395
|
)
|
|
396
|
+
end = datetime.now()
|
|
397
|
+
output.execution_time = (end - start).total_seconds()
|
|
398
|
+
return output
|
|
368
399
|
|
|
369
400
|
async def merge_questions(
|
|
370
401
|
self,
|
|
@@ -403,10 +434,11 @@ class AsyncTheTool:
|
|
|
403
434
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
404
435
|
- errors (list(str) | None): Errors occured during tool call
|
|
405
436
|
"""
|
|
406
|
-
|
|
407
|
-
|
|
437
|
+
start = datetime.now()
|
|
438
|
+
text_combined = ", ".join(text)
|
|
439
|
+
output = await self._operator.run(
|
|
408
440
|
# User parameters
|
|
409
|
-
text=
|
|
441
|
+
text=text_combined,
|
|
410
442
|
with_analysis=with_analysis,
|
|
411
443
|
output_lang=output_lang,
|
|
412
444
|
user_prompt=user_prompt,
|
|
@@ -415,12 +447,15 @@ class AsyncTheTool:
|
|
|
415
447
|
top_logprobs=top_logprobs,
|
|
416
448
|
validator=validator,
|
|
417
449
|
max_validation_retries=max_validation_retries,
|
|
450
|
+
priority=priority,
|
|
418
451
|
# Internal parameters
|
|
419
452
|
prompt_file="merge_questions.yaml",
|
|
420
453
|
output_model=Models.StrOutput,
|
|
421
454
|
mode=mode,
|
|
422
|
-
priority=priority,
|
|
423
455
|
)
|
|
456
|
+
end = datetime.now()
|
|
457
|
+
output.execution_time = (end - start).total_seconds()
|
|
458
|
+
return output
|
|
424
459
|
|
|
425
460
|
async def rewrite(
|
|
426
461
|
self,
|
|
@@ -459,7 +494,8 @@ class AsyncTheTool:
|
|
|
459
494
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
460
495
|
- errors (list(str) | None): Errors occured during tool call
|
|
461
496
|
"""
|
|
462
|
-
|
|
497
|
+
start = datetime.now()
|
|
498
|
+
output = await self._operator.run(
|
|
463
499
|
# User parameters
|
|
464
500
|
text=text,
|
|
465
501
|
with_analysis=with_analysis,
|
|
@@ -470,12 +506,15 @@ class AsyncTheTool:
|
|
|
470
506
|
top_logprobs=top_logprobs,
|
|
471
507
|
validator=validator,
|
|
472
508
|
max_validation_retries=max_validation_retries,
|
|
509
|
+
priority=priority,
|
|
473
510
|
# Internal parameters
|
|
474
511
|
prompt_file="rewrite.yaml",
|
|
475
512
|
output_model=Models.StrOutput,
|
|
476
513
|
mode=mode,
|
|
477
|
-
priority=priority,
|
|
478
514
|
)
|
|
515
|
+
end = datetime.now()
|
|
516
|
+
output.execution_time = (end - start).total_seconds()
|
|
517
|
+
return output
|
|
479
518
|
|
|
480
519
|
async def subject_to_question(
|
|
481
520
|
self,
|
|
@@ -514,7 +553,8 @@ class AsyncTheTool:
|
|
|
514
553
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
515
554
|
- errors (list(str) | None): Errors occured during tool call
|
|
516
555
|
"""
|
|
517
|
-
|
|
556
|
+
start = datetime.now()
|
|
557
|
+
output = await self._operator.run(
|
|
518
558
|
# User parameters
|
|
519
559
|
text=text,
|
|
520
560
|
number_of_questions=number_of_questions,
|
|
@@ -526,12 +566,15 @@ class AsyncTheTool:
|
|
|
526
566
|
top_logprobs=top_logprobs,
|
|
527
567
|
validator=validator,
|
|
528
568
|
max_validation_retries=max_validation_retries,
|
|
569
|
+
priority=priority,
|
|
529
570
|
# Internal parameters
|
|
530
571
|
prompt_file="subject_to_question.yaml",
|
|
531
572
|
output_model=Models.ReasonListStrOutput,
|
|
532
573
|
mode=None,
|
|
533
|
-
priority=priority,
|
|
534
574
|
)
|
|
575
|
+
end = datetime.now()
|
|
576
|
+
output.execution_time = (end - start).total_seconds()
|
|
577
|
+
return output
|
|
535
578
|
|
|
536
579
|
async def summarize(
|
|
537
580
|
self,
|
|
@@ -568,7 +611,8 @@ class AsyncTheTool:
|
|
|
568
611
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
569
612
|
- errors (list(str) | None): Errors occured during tool call
|
|
570
613
|
"""
|
|
571
|
-
|
|
614
|
+
start = datetime.now()
|
|
615
|
+
output = await self._operator.run(
|
|
572
616
|
# User parameters
|
|
573
617
|
text=text,
|
|
574
618
|
with_analysis=with_analysis,
|
|
@@ -579,12 +623,15 @@ class AsyncTheTool:
|
|
|
579
623
|
top_logprobs=top_logprobs,
|
|
580
624
|
validator=validator,
|
|
581
625
|
max_validation_retries=max_validation_retries,
|
|
626
|
+
priority=priority,
|
|
582
627
|
# Internal parameters
|
|
583
628
|
prompt_file="summarize.yaml",
|
|
584
629
|
output_model=Models.StrOutput,
|
|
585
630
|
mode=None,
|
|
586
|
-
priority=priority,
|
|
587
631
|
)
|
|
632
|
+
end = datetime.now()
|
|
633
|
+
output.execution_time = (end - start).total_seconds()
|
|
634
|
+
return output
|
|
588
635
|
|
|
589
636
|
async def translate(
|
|
590
637
|
self,
|
|
@@ -621,7 +668,8 @@ class AsyncTheTool:
|
|
|
621
668
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
622
669
|
- errors (list(str) | None): Errors occured during tool call
|
|
623
670
|
"""
|
|
624
|
-
|
|
671
|
+
start = datetime.now()
|
|
672
|
+
output = await self._operator.run(
|
|
625
673
|
# User parameters
|
|
626
674
|
text=text,
|
|
627
675
|
target_language=target_language,
|
|
@@ -632,13 +680,16 @@ class AsyncTheTool:
|
|
|
632
680
|
top_logprobs=top_logprobs,
|
|
633
681
|
validator=validator,
|
|
634
682
|
max_validation_retries=max_validation_retries,
|
|
683
|
+
priority=priority,
|
|
635
684
|
# Internal parameters
|
|
636
685
|
prompt_file="translate.yaml",
|
|
637
686
|
output_model=Models.StrOutput,
|
|
638
687
|
mode=None,
|
|
639
688
|
output_lang=None,
|
|
640
|
-
priority=priority,
|
|
641
689
|
)
|
|
690
|
+
end = datetime.now()
|
|
691
|
+
output.execution_time = (end - start).total_seconds()
|
|
692
|
+
return output
|
|
642
693
|
|
|
643
694
|
async def detect_entity(
|
|
644
695
|
self,
|
|
@@ -675,7 +726,8 @@ class AsyncTheTool:
|
|
|
675
726
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
676
727
|
- errors (list(str) | None): Errors occured during tool call
|
|
677
728
|
"""
|
|
678
|
-
|
|
729
|
+
start = datetime.now()
|
|
730
|
+
output = await self._operator.run(
|
|
679
731
|
# User parameters
|
|
680
732
|
text=text,
|
|
681
733
|
with_analysis=with_analysis,
|
|
@@ -686,12 +738,15 @@ class AsyncTheTool:
|
|
|
686
738
|
top_logprobs=top_logprobs,
|
|
687
739
|
validator=validator,
|
|
688
740
|
max_validation_retries=max_validation_retries,
|
|
741
|
+
priority=priority,
|
|
689
742
|
# Internal parameters
|
|
690
743
|
prompt_file="detect_entity.yaml",
|
|
691
744
|
output_model=Models.EntityDetectorOutput,
|
|
692
745
|
mode=None,
|
|
693
|
-
priority=priority,
|
|
694
746
|
)
|
|
747
|
+
end = datetime.now()
|
|
748
|
+
output.execution_time = (end - start).total_seconds()
|
|
749
|
+
return output
|
|
695
750
|
|
|
696
751
|
async def run_custom(
|
|
697
752
|
self,
|
|
@@ -725,7 +780,8 @@ class AsyncTheTool:
|
|
|
725
780
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
726
781
|
- errors (list(str) | None): Errors occured during tool call
|
|
727
782
|
"""
|
|
728
|
-
|
|
783
|
+
start = datetime.now()
|
|
784
|
+
output = await self._operator.run(
|
|
729
785
|
# User paramaeters
|
|
730
786
|
text=prompt,
|
|
731
787
|
output_model=output_model,
|
|
@@ -736,10 +792,13 @@ class AsyncTheTool:
|
|
|
736
792
|
top_logprobs=top_logprobs,
|
|
737
793
|
validator=validator,
|
|
738
794
|
max_validation_retries=max_validation_retries,
|
|
795
|
+
priority=priority,
|
|
739
796
|
# Internal parameters
|
|
740
797
|
prompt_file="run_custom.yaml",
|
|
741
798
|
user_prompt=None,
|
|
742
799
|
with_analysis=False,
|
|
743
800
|
mode=None,
|
|
744
|
-
priority=priority,
|
|
745
801
|
)
|
|
802
|
+
end = datetime.now()
|
|
803
|
+
output.execution_time = (end - start).total_seconds()
|
|
804
|
+
return output
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from datetime import datetime
|
|
1
2
|
from typing import Type, Any, Literal
|
|
2
3
|
|
|
3
4
|
from pydantic import BaseModel, Field, create_model
|
|
@@ -7,10 +8,13 @@ class ToolOutput(BaseModel):
|
|
|
7
8
|
result: Any = None
|
|
8
9
|
analysis: str = ""
|
|
9
10
|
logprobs: list[dict[str, Any]] = []
|
|
11
|
+
process: str = ""
|
|
12
|
+
processed_at: datetime = datetime.now()
|
|
13
|
+
execution_time: float = -1.0
|
|
10
14
|
errors: list[str] = []
|
|
11
15
|
|
|
12
16
|
def __repr__(self) -> str:
|
|
13
|
-
return f"ToolOutput(result_type='{type(self.result)}', result='{self.result}', analysis='{self.analysis}', logprobs='{self.logprobs}', errors='{self.errors}'"
|
|
17
|
+
return f"ToolOutput(process='{self.process}', result_type='{type(self.result)}', result='{self.result}', analysis='{self.analysis}', logprobs='{self.logprobs}', errors='{self.errors}', processed_at='{self.processed_at}', execution_time='{self.execution_time}'"
|
|
14
18
|
|
|
15
19
|
|
|
16
20
|
class StrOutput(BaseModel):
|
|
@@ -53,7 +57,7 @@ class Node(BaseModel):
|
|
|
53
57
|
class CategoryTree:
|
|
54
58
|
def __init__(self, tree_name):
|
|
55
59
|
self.root = Node(node_id=0, name=tree_name, level=0, parent_id=None)
|
|
56
|
-
self.
|
|
60
|
+
self.all_nodes: list[Node] = [self.root]
|
|
57
61
|
self.new_id = 1
|
|
58
62
|
|
|
59
63
|
def add_node(
|
|
@@ -85,11 +89,14 @@ class CategoryTree:
|
|
|
85
89
|
if description is not None:
|
|
86
90
|
node_data["description"] = description
|
|
87
91
|
|
|
88
|
-
self.
|
|
92
|
+
self.all_nodes.append(Node(**node_data))
|
|
89
93
|
self.new_id += 1
|
|
90
94
|
|
|
91
95
|
def get_nodes(self) -> list[Node]:
|
|
92
|
-
return self.
|
|
96
|
+
return self.all_nodes
|
|
97
|
+
|
|
98
|
+
def get_level_count(self) -> int:
|
|
99
|
+
return max([item.level for item in self.all_nodes])
|
|
93
100
|
|
|
94
101
|
def find_node(self, identifier: int | str) -> Node | None:
|
|
95
102
|
if isinstance(identifier, str):
|
|
@@ -106,11 +113,9 @@ class CategoryTree:
|
|
|
106
113
|
return None
|
|
107
114
|
|
|
108
115
|
def find_children(self, parent_node: Node) -> list[Node] | None:
|
|
109
|
-
children = [
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
children.append(node)
|
|
113
|
-
|
|
116
|
+
children = [
|
|
117
|
+
node for node in self.get_nodes() if parent_node.node_id == node.parent_id
|
|
118
|
+
]
|
|
114
119
|
return children if children else None
|
|
115
120
|
|
|
116
121
|
def remove_node(self, identifier: int | str) -> None:
|
|
@@ -122,14 +127,14 @@ class CategoryTree:
|
|
|
122
127
|
|
|
123
128
|
# Ending condition
|
|
124
129
|
if children is None:
|
|
125
|
-
self.
|
|
130
|
+
self.all_nodes.remove(node)
|
|
126
131
|
return
|
|
127
132
|
|
|
128
133
|
for child in children:
|
|
129
134
|
self.remove_node(child.name)
|
|
130
135
|
|
|
131
136
|
# Remove the node from tree
|
|
132
|
-
self.
|
|
137
|
+
self.all_nodes.remove(node)
|
|
133
138
|
else:
|
|
134
139
|
raise ValueError(f"Node with identifier: '{identifier}' not found.")
|
|
135
140
|
|
|
@@ -137,7 +142,7 @@ class CategoryTree:
|
|
|
137
142
|
def build_dict(node: Node) -> dict:
|
|
138
143
|
children = [
|
|
139
144
|
build_dict(child)
|
|
140
|
-
for child in self.
|
|
145
|
+
for child in self.all_nodes
|
|
141
146
|
if child.parent_id == node.node_id
|
|
142
147
|
]
|
|
143
148
|
return {
|
|
@@ -150,9 +155,6 @@ class CategoryTree:
|
|
|
150
155
|
|
|
151
156
|
return {"category_tree": build_dict(self.root)["children"]}
|
|
152
157
|
|
|
153
|
-
def level_count(self) -> int:
|
|
154
|
-
return max([item.level for item in self.node_list])
|
|
155
|
-
|
|
156
158
|
|
|
157
159
|
# This function is needed to create CategorizerOutput with dynamic categories
|
|
158
160
|
def create_dynamic_model(allowed_values: list[str]) -> Type[BaseModel]:
|
|
@@ -174,7 +176,7 @@ def create_dynamic_model(allowed_values: list[str]) -> Type[BaseModel]:
|
|
|
174
176
|
|
|
175
177
|
class Entity(BaseModel):
|
|
176
178
|
text: str = Field(description="The exact text of the entity")
|
|
177
|
-
|
|
179
|
+
entity_type: str = Field(description="The type of the entity")
|
|
178
180
|
|
|
179
181
|
|
|
180
182
|
class EntityDetectorOutput(BaseModel):
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from datetime import datetime
|
|
1
2
|
from typing import Literal, Any
|
|
2
3
|
from collections.abc import Callable
|
|
3
4
|
|
|
@@ -61,10 +62,12 @@ class TheTool:
|
|
|
61
62
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
62
63
|
- errors (list(str) | None): Errors occured during tool call
|
|
63
64
|
"""
|
|
65
|
+
start = datetime.now()
|
|
66
|
+
|
|
64
67
|
if mode == "category_tree":
|
|
65
68
|
# Initializations
|
|
66
69
|
output = Models.ToolOutput()
|
|
67
|
-
levels = categories.
|
|
70
|
+
levels = categories.get_level_count()
|
|
68
71
|
parent_id = 0
|
|
69
72
|
final_output = []
|
|
70
73
|
|
|
@@ -78,6 +81,8 @@ class TheTool:
|
|
|
78
81
|
output.errors.append(
|
|
79
82
|
f"No categories found for parent_id {parent_id} in the tree"
|
|
80
83
|
)
|
|
84
|
+
end = datetime.now()
|
|
85
|
+
output.execution_time = (end - start).total_seconds()
|
|
81
86
|
return output
|
|
82
87
|
|
|
83
88
|
# Extract category names and descriptions
|
|
@@ -100,6 +105,7 @@ class TheTool:
|
|
|
100
105
|
mode=mode,
|
|
101
106
|
validator=validator,
|
|
102
107
|
max_validation_retries=max_validation_retries,
|
|
108
|
+
priority=priority,
|
|
103
109
|
# Internal parameters
|
|
104
110
|
prompt_file="categorize.yaml",
|
|
105
111
|
output_model=Models.create_dynamic_model(category_names),
|
|
@@ -109,6 +115,8 @@ class TheTool:
|
|
|
109
115
|
# Check for errors from operator
|
|
110
116
|
if level_output.errors:
|
|
111
117
|
output.errors.extend(level_output.errors)
|
|
118
|
+
end = datetime.now()
|
|
119
|
+
output.execution_time = (end - start).total_seconds()
|
|
112
120
|
return output
|
|
113
121
|
|
|
114
122
|
# Get the chosen category
|
|
@@ -120,20 +128,25 @@ class TheTool:
|
|
|
120
128
|
output.errors.append(
|
|
121
129
|
f"Category '{chosen_category}' not found in tree after selection"
|
|
122
130
|
)
|
|
131
|
+
end = datetime.now()
|
|
132
|
+
output.execution_time = (end - start).total_seconds()
|
|
123
133
|
return output
|
|
124
134
|
|
|
125
135
|
parent_id = parent_node.node_id
|
|
126
136
|
final_output.append(parent_node.name)
|
|
127
137
|
|
|
128
|
-
# Copy analysis/logprobs from the last level's output
|
|
138
|
+
# Copy analysis/logprobs/process from the last level's output
|
|
129
139
|
output.analysis = level_output.analysis
|
|
130
140
|
output.logprobs = level_output.logprobs
|
|
141
|
+
output.process = level_output.process
|
|
131
142
|
|
|
132
143
|
output.result = final_output
|
|
144
|
+
end = datetime.now()
|
|
145
|
+
output.execution_time = (end - start).total_seconds()
|
|
133
146
|
return output
|
|
134
147
|
|
|
135
148
|
else:
|
|
136
|
-
|
|
149
|
+
output = self._operator.run(
|
|
137
150
|
# User parameters
|
|
138
151
|
text=text,
|
|
139
152
|
category_list=categories,
|
|
@@ -145,11 +158,15 @@ class TheTool:
|
|
|
145
158
|
mode=mode,
|
|
146
159
|
validator=validator,
|
|
147
160
|
max_validation_retries=max_validation_retries,
|
|
161
|
+
priority=priority,
|
|
148
162
|
# Internal parameters
|
|
149
163
|
prompt_file="categorize.yaml",
|
|
150
164
|
output_model=Models.create_dynamic_model(categories),
|
|
151
165
|
output_lang=None,
|
|
152
166
|
)
|
|
167
|
+
end = datetime.now()
|
|
168
|
+
output.execution_time = (end - start).total_seconds()
|
|
169
|
+
return output
|
|
153
170
|
|
|
154
171
|
def extract_keywords(
|
|
155
172
|
self,
|
|
@@ -188,7 +205,8 @@ class TheTool:
|
|
|
188
205
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
189
206
|
- errors (list(str) | None): Errors occured during tool call
|
|
190
207
|
"""
|
|
191
|
-
|
|
208
|
+
start = datetime.now()
|
|
209
|
+
output = self._operator.run(
|
|
192
210
|
# User parameters
|
|
193
211
|
text=text,
|
|
194
212
|
with_analysis=with_analysis,
|
|
@@ -201,11 +219,14 @@ class TheTool:
|
|
|
201
219
|
number_of_keywords=number_of_keywords,
|
|
202
220
|
validator=validator,
|
|
203
221
|
max_validation_retries=max_validation_retries,
|
|
222
|
+
priority=priority,
|
|
204
223
|
# Internal parameters
|
|
205
224
|
prompt_file="extract_keywords.yaml",
|
|
206
225
|
output_model=Models.ListStrOutput,
|
|
207
|
-
priority=priority,
|
|
208
226
|
)
|
|
227
|
+
end = datetime.now()
|
|
228
|
+
output.execution_time = (end - start).total_seconds()
|
|
229
|
+
return output
|
|
209
230
|
|
|
210
231
|
def extract_entities(
|
|
211
232
|
self,
|
|
@@ -242,7 +263,8 @@ class TheTool:
|
|
|
242
263
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
243
264
|
- errors (list(str) | None): Errors occured during tool call
|
|
244
265
|
"""
|
|
245
|
-
|
|
266
|
+
start = datetime.now()
|
|
267
|
+
output = self._operator.run(
|
|
246
268
|
# User parameters
|
|
247
269
|
text=text,
|
|
248
270
|
with_analysis=with_analysis,
|
|
@@ -253,12 +275,15 @@ class TheTool:
|
|
|
253
275
|
top_logprobs=top_logprobs,
|
|
254
276
|
validator=validator,
|
|
255
277
|
max_validation_retries=max_validation_retries,
|
|
278
|
+
priority=priority,
|
|
256
279
|
# Internal parameters
|
|
257
280
|
prompt_file="extract_entities.yaml",
|
|
258
281
|
output_model=Models.ListDictStrStrOutput,
|
|
259
282
|
mode=None,
|
|
260
|
-
priority=priority,
|
|
261
283
|
)
|
|
284
|
+
end = datetime.now()
|
|
285
|
+
output.execution_time = (end - start).total_seconds()
|
|
286
|
+
return output
|
|
262
287
|
|
|
263
288
|
def is_question(
|
|
264
289
|
self,
|
|
@@ -293,7 +318,8 @@ class TheTool:
|
|
|
293
318
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
294
319
|
- errors (list(str) | None): Errors occured during tool call
|
|
295
320
|
"""
|
|
296
|
-
|
|
321
|
+
start = datetime.now()
|
|
322
|
+
output = self._operator.run(
|
|
297
323
|
# User parameters
|
|
298
324
|
text=text,
|
|
299
325
|
with_analysis=with_analysis,
|
|
@@ -303,13 +329,16 @@ class TheTool:
|
|
|
303
329
|
top_logprobs=top_logprobs,
|
|
304
330
|
validator=validator,
|
|
305
331
|
max_validation_retries=max_validation_retries,
|
|
332
|
+
priority=priority,
|
|
306
333
|
# Internal parameters
|
|
307
334
|
prompt_file="is_question.yaml",
|
|
308
335
|
output_model=Models.BoolOutput,
|
|
309
336
|
mode=None,
|
|
310
337
|
output_lang=None,
|
|
311
|
-
priority=priority,
|
|
312
338
|
)
|
|
339
|
+
end = datetime.now()
|
|
340
|
+
output.execution_time = (end - start).total_seconds()
|
|
341
|
+
return output
|
|
313
342
|
|
|
314
343
|
def text_to_question(
|
|
315
344
|
self,
|
|
@@ -346,7 +375,8 @@ class TheTool:
|
|
|
346
375
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
347
376
|
- errors (list(str) | None): Errors occured during tool call
|
|
348
377
|
"""
|
|
349
|
-
|
|
378
|
+
start = datetime.now()
|
|
379
|
+
output = self._operator.run(
|
|
350
380
|
# User parameters
|
|
351
381
|
text=text,
|
|
352
382
|
with_analysis=with_analysis,
|
|
@@ -357,12 +387,15 @@ class TheTool:
|
|
|
357
387
|
top_logprobs=top_logprobs,
|
|
358
388
|
validator=validator,
|
|
359
389
|
max_validation_retries=max_validation_retries,
|
|
390
|
+
priority=priority,
|
|
360
391
|
# Internal parameters
|
|
361
392
|
prompt_file="text_to_question.yaml",
|
|
362
393
|
output_model=Models.StrOutput,
|
|
363
394
|
mode=None,
|
|
364
|
-
priority=priority,
|
|
365
395
|
)
|
|
396
|
+
end = datetime.now()
|
|
397
|
+
output.execution_time = (end - start).total_seconds()
|
|
398
|
+
return output
|
|
366
399
|
|
|
367
400
|
def merge_questions(
|
|
368
401
|
self,
|
|
@@ -401,8 +434,9 @@ class TheTool:
|
|
|
401
434
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
402
435
|
- errors (list(str) | None): Errors occured during tool call
|
|
403
436
|
"""
|
|
437
|
+
start = datetime.now()
|
|
404
438
|
text = ", ".join(text)
|
|
405
|
-
|
|
439
|
+
output = self._operator.run(
|
|
406
440
|
# User parameters
|
|
407
441
|
text=text,
|
|
408
442
|
with_analysis=with_analysis,
|
|
@@ -413,12 +447,15 @@ class TheTool:
|
|
|
413
447
|
top_logprobs=top_logprobs,
|
|
414
448
|
validator=validator,
|
|
415
449
|
max_validation_retries=max_validation_retries,
|
|
450
|
+
priority=priority,
|
|
416
451
|
# Internal parameters
|
|
417
452
|
prompt_file="merge_questions.yaml",
|
|
418
453
|
output_model=Models.StrOutput,
|
|
419
454
|
mode=mode,
|
|
420
|
-
priority=priority,
|
|
421
455
|
)
|
|
456
|
+
end = datetime.now()
|
|
457
|
+
output.execution_time = (end - start).total_seconds()
|
|
458
|
+
return output
|
|
422
459
|
|
|
423
460
|
def rewrite(
|
|
424
461
|
self,
|
|
@@ -457,7 +494,8 @@ class TheTool:
|
|
|
457
494
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
458
495
|
- errors (list(str) | None): Errors occured during tool call
|
|
459
496
|
"""
|
|
460
|
-
|
|
497
|
+
start = datetime.now()
|
|
498
|
+
output = self._operator.run(
|
|
461
499
|
# User parameters
|
|
462
500
|
text=text,
|
|
463
501
|
with_analysis=with_analysis,
|
|
@@ -468,12 +506,15 @@ class TheTool:
|
|
|
468
506
|
top_logprobs=top_logprobs,
|
|
469
507
|
validator=validator,
|
|
470
508
|
max_validation_retries=max_validation_retries,
|
|
509
|
+
priority=priority,
|
|
471
510
|
# Internal parameters
|
|
472
511
|
prompt_file="rewrite.yaml",
|
|
473
512
|
output_model=Models.StrOutput,
|
|
474
513
|
mode=mode,
|
|
475
|
-
priority=priority,
|
|
476
514
|
)
|
|
515
|
+
end = datetime.now()
|
|
516
|
+
output.execution_time = (end - start).total_seconds()
|
|
517
|
+
return output
|
|
477
518
|
|
|
478
519
|
def subject_to_question(
|
|
479
520
|
self,
|
|
@@ -512,7 +553,8 @@ class TheTool:
|
|
|
512
553
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
513
554
|
- errors (list(str) | None): Errors occured during tool call
|
|
514
555
|
"""
|
|
515
|
-
|
|
556
|
+
start = datetime.now()
|
|
557
|
+
output = self._operator.run(
|
|
516
558
|
# User parameters
|
|
517
559
|
text=text,
|
|
518
560
|
number_of_questions=number_of_questions,
|
|
@@ -524,12 +566,15 @@ class TheTool:
|
|
|
524
566
|
top_logprobs=top_logprobs,
|
|
525
567
|
validator=validator,
|
|
526
568
|
max_validation_retries=max_validation_retries,
|
|
569
|
+
priority=priority,
|
|
527
570
|
# Internal parameters
|
|
528
571
|
prompt_file="subject_to_question.yaml",
|
|
529
572
|
output_model=Models.ReasonListStrOutput,
|
|
530
573
|
mode=None,
|
|
531
|
-
priority=priority,
|
|
532
574
|
)
|
|
575
|
+
end = datetime.now()
|
|
576
|
+
output.execution_time = (end - start).total_seconds()
|
|
577
|
+
return output
|
|
533
578
|
|
|
534
579
|
def summarize(
|
|
535
580
|
self,
|
|
@@ -566,7 +611,8 @@ class TheTool:
|
|
|
566
611
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
567
612
|
- errors (list(str) | None): Errors occured during tool call
|
|
568
613
|
"""
|
|
569
|
-
|
|
614
|
+
start = datetime.now()
|
|
615
|
+
output = self._operator.run(
|
|
570
616
|
# User parameters
|
|
571
617
|
text=text,
|
|
572
618
|
with_analysis=with_analysis,
|
|
@@ -577,12 +623,15 @@ class TheTool:
|
|
|
577
623
|
top_logprobs=top_logprobs,
|
|
578
624
|
validator=validator,
|
|
579
625
|
max_validation_retries=max_validation_retries,
|
|
626
|
+
priority=priority,
|
|
580
627
|
# Internal parameters
|
|
581
628
|
prompt_file="summarize.yaml",
|
|
582
629
|
output_model=Models.StrOutput,
|
|
583
630
|
mode=None,
|
|
584
|
-
priority=priority,
|
|
585
631
|
)
|
|
632
|
+
end = datetime.now()
|
|
633
|
+
output.execution_time = (end - start).total_seconds()
|
|
634
|
+
return output
|
|
586
635
|
|
|
587
636
|
def translate(
|
|
588
637
|
self,
|
|
@@ -619,7 +668,8 @@ class TheTool:
|
|
|
619
668
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
620
669
|
- errors (list(str) | None): Errors occured during tool call
|
|
621
670
|
"""
|
|
622
|
-
|
|
671
|
+
start = datetime.now()
|
|
672
|
+
output = self._operator.run(
|
|
623
673
|
# User parameters
|
|
624
674
|
text=text,
|
|
625
675
|
target_language=target_language,
|
|
@@ -630,13 +680,16 @@ class TheTool:
|
|
|
630
680
|
top_logprobs=top_logprobs,
|
|
631
681
|
validator=validator,
|
|
632
682
|
max_validation_retries=max_validation_retries,
|
|
683
|
+
priority=priority,
|
|
633
684
|
# Internal parameters
|
|
634
685
|
prompt_file="translate.yaml",
|
|
635
686
|
output_model=Models.StrOutput,
|
|
636
687
|
mode=None,
|
|
637
688
|
output_lang=None,
|
|
638
|
-
priority=priority,
|
|
639
689
|
)
|
|
690
|
+
end = datetime.now()
|
|
691
|
+
output.execution_time = (end - start).total_seconds()
|
|
692
|
+
return output
|
|
640
693
|
|
|
641
694
|
def detect_entity(
|
|
642
695
|
self,
|
|
@@ -673,7 +726,8 @@ class TheTool:
|
|
|
673
726
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
674
727
|
- errors (list(str) | None): Errors occured during tool call
|
|
675
728
|
"""
|
|
676
|
-
|
|
729
|
+
start = datetime.now()
|
|
730
|
+
output = self._operator.run(
|
|
677
731
|
# User parameters
|
|
678
732
|
text=text,
|
|
679
733
|
with_analysis=with_analysis,
|
|
@@ -684,12 +738,15 @@ class TheTool:
|
|
|
684
738
|
top_logprobs=top_logprobs,
|
|
685
739
|
validator=validator,
|
|
686
740
|
max_validation_retries=max_validation_retries,
|
|
741
|
+
priority=priority,
|
|
687
742
|
# Internal parameters
|
|
688
743
|
prompt_file="detect_entity.yaml",
|
|
689
744
|
output_model=Models.EntityDetectorOutput,
|
|
690
745
|
mode=None,
|
|
691
|
-
priority=priority,
|
|
692
746
|
)
|
|
747
|
+
end = datetime.now()
|
|
748
|
+
output.execution_time = (end - start).total_seconds()
|
|
749
|
+
return output
|
|
693
750
|
|
|
694
751
|
def run_custom(
|
|
695
752
|
self,
|
|
@@ -723,7 +780,8 @@ class TheTool:
|
|
|
723
780
|
- analysis (str | None): Detailed reasoning if with_analysis enabled
|
|
724
781
|
- errors (list(str) | None): Errors occured during tool call
|
|
725
782
|
"""
|
|
726
|
-
|
|
783
|
+
start = datetime.now()
|
|
784
|
+
output = self._operator.run(
|
|
727
785
|
# User paramaeters
|
|
728
786
|
text=prompt,
|
|
729
787
|
output_model=output_model,
|
|
@@ -734,10 +792,13 @@ class TheTool:
|
|
|
734
792
|
top_logprobs=top_logprobs,
|
|
735
793
|
validator=validator,
|
|
736
794
|
max_validation_retries=max_validation_retries,
|
|
795
|
+
priority=priority,
|
|
737
796
|
# Internal parameters
|
|
738
797
|
prompt_file="run_custom.yaml",
|
|
739
798
|
user_prompt=None,
|
|
740
799
|
with_analysis=False,
|
|
741
800
|
mode=None,
|
|
742
|
-
priority=priority,
|
|
743
801
|
)
|
|
802
|
+
end = datetime.now()
|
|
803
|
+
output.execution_time = (end - start).total_seconds()
|
|
804
|
+
return output
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
|
|
3
|
-
from dotenv import load_dotenv
|
|
4
|
-
from openai import OpenAI
|
|
5
|
-
|
|
6
|
-
from texttools import TheTool, CategoryTree
|
|
7
|
-
|
|
8
|
-
# Load environment variables from .env
|
|
9
|
-
load_dotenv()
|
|
10
|
-
API_KEY = os.getenv("OPENAI_API_KEY")
|
|
11
|
-
BASE_URL = os.getenv("BASE_URL")
|
|
12
|
-
MODEL = os.getenv("MODEL")
|
|
13
|
-
|
|
14
|
-
# Create OpenAI client
|
|
15
|
-
client = OpenAI(base_url=BASE_URL, api_key=API_KEY)
|
|
16
|
-
|
|
17
|
-
# Create an instance of TheTool
|
|
18
|
-
t = TheTool(client=client, model=MODEL)
|
|
19
|
-
|
|
20
|
-
# Create a category tree
|
|
21
|
-
tree = CategoryTree("category_test_tree")
|
|
22
|
-
tree.add_node("اخلاق")
|
|
23
|
-
tree.add_node("معرفت شناسی")
|
|
24
|
-
tree.add_node("متافیزیک", description="اراده قدرت در حیطه متافیزیک است")
|
|
25
|
-
tree.add_node("فلسفه ذهن", description="فلسفه ذهن به چگونگی درک ما از جهان می پردازد")
|
|
26
|
-
tree.add_node("آگاهی", "فلسفه ذهن", description="آگاهی خیلی مهم است")
|
|
27
|
-
tree.add_node("ذهن و بدن", "فلسفه ذهن")
|
|
28
|
-
tree.add_node("امکان و ضرورت", "متافیزیک")
|
|
29
|
-
|
|
30
|
-
# Test category tree
|
|
31
|
-
categories = t.categorize(
|
|
32
|
-
"اراده قدرت مفهومی مهم در مابعد الطبیعه است که توسط نیچه مطرح شده",
|
|
33
|
-
tree,
|
|
34
|
-
mode="category_tree",
|
|
35
|
-
)
|
|
36
|
-
print(repr(categories))
|
|
37
|
-
|
|
38
|
-
# Create category list
|
|
39
|
-
category_list = ["اخلاق", "معرفت شناسی", "متافیزیک", "فلسفه ذهن"]
|
|
40
|
-
|
|
41
|
-
# Test list mode
|
|
42
|
-
category = t.categorize(
|
|
43
|
-
"اراده قدرت مفهومی مهم در مابعد الطبیعه است که توسط نیچه مطرح شده",
|
|
44
|
-
category_list,
|
|
45
|
-
mode="category_list",
|
|
46
|
-
)
|
|
47
|
-
print(repr(category))
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
|
|
3
|
-
from dotenv import load_dotenv
|
|
4
|
-
from openai import OpenAI
|
|
5
|
-
|
|
6
|
-
from texttools import TheTool
|
|
7
|
-
|
|
8
|
-
# Load environment variables from .env
|
|
9
|
-
load_dotenv()
|
|
10
|
-
API_KEY = os.getenv("OPENAI_API_KEY")
|
|
11
|
-
BASE_URL = os.getenv("BASE_URL")
|
|
12
|
-
MODEL = os.getenv("MODEL")
|
|
13
|
-
|
|
14
|
-
# Create OpenAI client
|
|
15
|
-
client = OpenAI(base_url=BASE_URL, api_key=API_KEY)
|
|
16
|
-
|
|
17
|
-
# Create an instance of TheTool
|
|
18
|
-
t = TheTool(client=client, model=MODEL)
|
|
19
|
-
|
|
20
|
-
# Auto mode
|
|
21
|
-
keywords = t.extract_keywords(
|
|
22
|
-
"چرا در قرآن پاره ای از آیات تکرار شده است، و همچنین چرا بعضی از داستانها در موارد متعدّد آورده شده است؟!",
|
|
23
|
-
output_lang="Farsi",
|
|
24
|
-
mode="auto",
|
|
25
|
-
)
|
|
26
|
-
print(repr(keywords))
|
|
27
|
-
|
|
28
|
-
# Threshold mode
|
|
29
|
-
keywords = t.extract_keywords(
|
|
30
|
-
"چرا در قرآن پاره ای از آیات تکرار شده است، و همچنین چرا بعضی از داستانها در موارد متعدّد آورده شده است؟!",
|
|
31
|
-
output_lang="Farsi",
|
|
32
|
-
mode="threshold",
|
|
33
|
-
)
|
|
34
|
-
print(repr(keywords))
|
|
35
|
-
|
|
36
|
-
# Count mode
|
|
37
|
-
keywords = t.extract_keywords(
|
|
38
|
-
"چرا در قرآن پاره ای از آیات تکرار شده است، و همچنین چرا بعضی از داستانها در موارد متعدّد آورده شده است؟!",
|
|
39
|
-
output_lang="Farsi",
|
|
40
|
-
mode="count",
|
|
41
|
-
number_of_keywords=2,
|
|
42
|
-
)
|
|
43
|
-
print(repr(keywords))
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
|
|
3
|
-
from dotenv import load_dotenv
|
|
4
|
-
from openai import OpenAI
|
|
5
|
-
|
|
6
|
-
from texttools import TheTool
|
|
7
|
-
|
|
8
|
-
# Load environment variables from .env
|
|
9
|
-
load_dotenv()
|
|
10
|
-
API_KEY = os.getenv("OPENAI_API_KEY")
|
|
11
|
-
BASE_URL = os.getenv("BASE_URL")
|
|
12
|
-
MODEL = os.getenv("MODEL")
|
|
13
|
-
|
|
14
|
-
# Create OpenAI client
|
|
15
|
-
client = OpenAI(base_url=BASE_URL, api_key=API_KEY)
|
|
16
|
-
|
|
17
|
-
# Create an instance of TheTool
|
|
18
|
-
t = TheTool(client=client, model=MODEL)
|
|
19
|
-
|
|
20
|
-
# Keyword Extractor
|
|
21
|
-
print("\n\nKEYWORD EXTRACTOR\n")
|
|
22
|
-
keywords = t.extract_keywords(
|
|
23
|
-
"Tomorrow, we will be dead by the car crash", logprobs=True
|
|
24
|
-
)
|
|
25
|
-
logprobs = keywords.logprobs
|
|
26
|
-
for d in logprobs:
|
|
27
|
-
print(d)
|
|
28
|
-
print("-" * 40)
|
|
29
|
-
|
|
30
|
-
# Question Detector
|
|
31
|
-
print("\n\nQUESTION DETECTOR\n")
|
|
32
|
-
detection = t.is_question(
|
|
33
|
-
"What is the capital of France?", logprobs=True, top_logprobs=3
|
|
34
|
-
)
|
|
35
|
-
logprobs = detection.logprobs
|
|
36
|
-
for d in logprobs:
|
|
37
|
-
print(d)
|
|
38
|
-
print("-" * 40)
|
|
File without changes
|
|
File without changes
|
{hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/hamtaa_texttools.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/batch/internals/batch_manager.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/prompts/subject_to_question.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/tools/internals/operator_utils.py
RENAMED
|
File without changes
|
{hamtaa_texttools-1.1.14 → hamtaa_texttools-1.1.16}/texttools/tools/internals/prompt_loader.py
RENAMED
|
File without changes
|