hamtaa-texttools 1.2.0__py3-none-any.whl → 1.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hamtaa-texttools
3
- Version: 1.2.0
3
+ Version: 1.3.0
4
4
  Summary: A high-level NLP toolkit built on top of modern LLMs.
5
5
  Author-email: Tohidi <the.mohammad.tohidi@gmail.com>, Erfan Moosavi <erfanmoosavi84@gmail.com>, Montazer <montazerh82@gmail.com>, Givechi <mohamad.m.givechi@gmail.com>, Zareshahi <a.zareshahi1377@gmail.com>
6
6
  Maintainer-email: Erfan Moosavi <erfanmoosavi84@gmail.com>, Tohidi <the.mohammad.tohidi@gmail.com>
@@ -73,7 +73,7 @@ pip install -U hamtaa-texttools
73
73
 
74
74
  ---
75
75
 
76
- ## ⚙️ `with_analysis`, `logprobs`, `output_lang`, `user_prompt`, `temperature`, `validator` and `priority` parameters
76
+ ## ⚙️ `with_analysis`, `logprobs`, `output_lang`, `user_prompt`, `temperature`, `validator`, `priority` and `timeout` parameters
77
77
 
78
78
  TextTools provides several optional flags to customize LLM behavior:
79
79
 
@@ -94,6 +94,10 @@ TextTools provides several optional flags to customize LLM behavior:
94
94
  - **`priority: int (Experimental)`** → Task execution priority level. Affects processing order in queues.
95
95
  **Note:** This feature works if it's supported by the model and vLLM.
96
96
 
97
+ - **`timeout: float`** → Maximum time in seconds to wait for the response before raising a timeout error
98
+ **Note:** This feature only exists in `AsyncTheTool`.
99
+
100
+
97
101
  ---
98
102
 
99
103
  ## 🧩 ToolOutput
@@ -1,4 +1,4 @@
1
- hamtaa_texttools-1.2.0.dist-info/licenses/LICENSE,sha256=Hb2YOBKy2MJQLnyLrX37B4ZVuac8eaIcE71SvVIMOLg,1082
1
+ hamtaa_texttools-1.3.0.dist-info/licenses/LICENSE,sha256=Hb2YOBKy2MJQLnyLrX37B4ZVuac8eaIcE71SvVIMOLg,1082
2
2
  texttools/__init__.py,sha256=4z7wInlrgbGSlWlXHQNeZMCGQH1sN2xtARsbgLHOLd8,283
3
3
  texttools/models.py,sha256=5eT2cSrFq8Xa38kANznV7gbi7lwB2PoDxciLKTpsd6c,2516
4
4
  texttools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -7,7 +7,7 @@ texttools/batch/config.py,sha256=GDDXuhRZ_bOGVwSIlU4tWP247tx1_A7qzLJn7VqDyLU,105
7
7
  texttools/batch/manager.py,sha256=XZtf8UkdClfQlnRKne4nWEcFvdSKE67EamEePKy7jwI,8730
8
8
  texttools/batch/runner.py,sha256=9qxXIMfYRXW5SXDqqKtRr61rnQdYZkbCGqKImhSrY6I,9923
9
9
  texttools/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- texttools/core/engine.py,sha256=WhEtxZjYEbCnD0gExGRR4eSmAY4J05E9csovt2Qqlm8,9281
10
+ texttools/core/engine.py,sha256=iRHdlIOPuUwIN6_72HNyTQQE7h_7xUZhC-WO-fDA5k8,9597
11
11
  texttools/core/exceptions.py,sha256=6SDjUL1rmd3ngzD3ytF4LyTRj3bQMSFR9ECrLoqXXHw,395
12
12
  texttools/core/internal_models.py,sha256=aExdLvhXhSev8NY1kuAJckeXdFBEisQtKZPxybd3rW8,1703
13
13
  texttools/core/operators/async_operator.py,sha256=wFs7eZ9QJrL0jBOu00YffgfPnIrCSavNjecSorXh-mE,6452
@@ -26,9 +26,9 @@ texttools/prompts/summarize.yaml,sha256=rPh060Bx_yI1W2JNg-nr83LUk9itatYLKM8ciH2p
26
26
  texttools/prompts/text_to_question.yaml,sha256=pUwPgK9l5f8S4E5fCht9JY7PFVK2aY1InPfASr7R5o4,1017
27
27
  texttools/prompts/translate.yaml,sha256=Dd5bs3O8SI-FlVSwHMYGeEjMmdOWeRlcfBHkhixCx7c,665
28
28
  texttools/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
- texttools/tools/async_tools.py,sha256=DonASaaOPbWp7Gh1UY4RlP3yPoYTuhJtVmLns8KYupE,42949
30
- texttools/tools/sync_tools.py,sha256=y4nMlabgvRapb-YFoiGA5-5HflKrRHttiWSHpkg9tug,42742
31
- hamtaa_texttools-1.2.0.dist-info/METADATA,sha256=vN4XmIWdH6mdAGfgSkjRdQLEoFNzbhhH32jOyEv9H6w,7846
32
- hamtaa_texttools-1.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
33
- hamtaa_texttools-1.2.0.dist-info/top_level.txt,sha256=5Mh0jIxxZ5rOXHGJ6Mp-JPKviywwN0MYuH0xk5bEWqE,10
34
- hamtaa_texttools-1.2.0.dist-info/RECORD,,
29
+ texttools/tools/async_tools.py,sha256=2suwx8N0aRnowaSOpV6C57AqPlmQe5Z0Yx4E5QIMkmU,46939
30
+ texttools/tools/sync_tools.py,sha256=mEuL-nlbxVW30dPE3hGkAUnYXbul-3gN2Le4CMVFCgU,42528
31
+ hamtaa_texttools-1.3.0.dist-info/METADATA,sha256=_CXrOjvT2jwWcs1LHID0vVyo9eKlSIK_BzU8YUeNypo,8024
32
+ hamtaa_texttools-1.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
33
+ hamtaa_texttools-1.3.0.dist-info/top_level.txt,sha256=5Mh0jIxxZ5rOXHGJ6Mp-JPKviywwN0MYuH0xk5bEWqE,10
34
+ hamtaa_texttools-1.3.0.dist-info/RECORD,,
texttools/core/engine.py CHANGED
@@ -1,3 +1,4 @@
1
+ import asyncio
1
2
  import math
2
3
  import random
3
4
  import re
@@ -252,3 +253,12 @@ def text_to_chunks(text: str, size: int, overlap: int) -> list[str]:
252
253
  return final_chunks
253
254
 
254
255
  return _split_text(text, separators)
256
+
257
+
258
+ async def run_with_timeout(coro, timeout: float | None):
259
+ if timeout is None:
260
+ return await coro
261
+ try:
262
+ return await asyncio.wait_for(coro, timeout=timeout)
263
+ except asyncio.TimeoutError:
264
+ raise TimeoutError(f"Operation exceeded timeout of {timeout} seconds")
@@ -1,11 +1,10 @@
1
- import sys
2
1
  from collections.abc import Callable
3
2
  from time import perf_counter
4
3
  from typing import Any, Literal
5
4
 
6
5
  from openai import AsyncOpenAI
7
6
 
8
- from ..core.engine import text_to_chunks
7
+ from ..core.engine import text_to_chunks, run_with_timeout
9
8
  from ..core.exceptions import LLMError, PromptError, TextToolsError, ValidationError
10
9
  from ..core.internal_models import (
11
10
  Bool,
@@ -44,6 +43,7 @@ class AsyncTheTool:
44
43
  validator: Callable[[Any], bool] | None = None,
45
44
  max_validation_retries: int | None = None,
46
45
  priority: int | None = None,
46
+ timeout: float | None = None,
47
47
  ) -> ToolOutput:
48
48
  """
49
49
  Categorize a text into a category / category tree.
@@ -61,33 +61,37 @@ class AsyncTheTool:
61
61
  validator: Custom validation function to validate the output
62
62
  max_validation_retries: Maximum number of retry attempts if validation fails
63
63
  priority: Task execution priority (if enabled by vLLM and the model)
64
+ timeout: Maximum time in seconds to wait for the response before raising a timeout error
64
65
 
65
66
  Returns:
66
67
  ToolOutput
67
68
 
68
69
  """
69
- tool_name = sys._getframe().f_code.co_name
70
+ tool_name = "categorize"
70
71
  start = perf_counter()
71
72
 
72
73
  try:
73
74
  if isinstance(categories, list):
74
- operator_output = await self._operator.run(
75
- # User parameters
76
- text=text,
77
- category_list=categories,
78
- with_analysis=with_analysis,
79
- user_prompt=user_prompt,
80
- temperature=temperature,
81
- logprobs=logprobs,
82
- top_logprobs=top_logprobs,
83
- validator=validator,
84
- max_validation_retries=max_validation_retries,
85
- priority=priority,
86
- # Internal parameters
87
- tool_name=tool_name,
88
- output_model=create_dynamic_model(categories),
89
- mode=None,
90
- output_lang=None,
75
+ operator_output = await run_with_timeout(
76
+ self._operator.run(
77
+ # User parameters
78
+ text=text,
79
+ category_list=categories,
80
+ with_analysis=with_analysis,
81
+ user_prompt=user_prompt,
82
+ temperature=temperature,
83
+ logprobs=logprobs,
84
+ top_logprobs=top_logprobs,
85
+ validator=validator,
86
+ max_validation_retries=max_validation_retries,
87
+ priority=priority,
88
+ # Internal parameters
89
+ tool_name=tool_name,
90
+ output_model=create_dynamic_model(categories),
91
+ mode=None,
92
+ output_lang=None,
93
+ ),
94
+ timeout=timeout,
91
95
  )
92
96
 
93
97
  metadata = ToolOutputMetadata(
@@ -117,23 +121,26 @@ class AsyncTheTool:
117
121
  ]
118
122
  category_names = list(parent_node.children.keys())
119
123
 
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,
124
+ level_operator_output = await run_with_timeout(
125
+ self._operator.run(
126
+ # User parameters
127
+ text=text,
128
+ category_list=category_list,
129
+ with_analysis=with_analysis,
130
+ user_prompt=user_prompt,
131
+ temperature=temperature,
132
+ logprobs=logprobs,
133
+ top_logprobs=top_logprobs,
134
+ validator=validator,
135
+ max_validation_retries=max_validation_retries,
136
+ priority=priority,
137
+ # Internal parameters
138
+ tool_name=tool_name,
139
+ output_model=create_dynamic_model(category_names),
140
+ mode=None,
141
+ output_lang=None,
142
+ ),
143
+ timeout=timeout,
137
144
  )
138
145
 
139
146
  chosen_category = level_operator_output.result
@@ -179,6 +186,7 @@ class AsyncTheTool:
179
186
  validator: Callable[[Any], bool] | None = None,
180
187
  max_validation_retries: int | None = None,
181
188
  priority: int | None = None,
189
+ timeout: float | None = None,
182
190
  ) -> ToolOutput:
183
191
  """
184
192
  Extract salient keywords from text.
@@ -194,31 +202,35 @@ class AsyncTheTool:
194
202
  validator: Custom validation function to validate the output
195
203
  max_validation_retries: Maximum number of retry attempts if validation fails
196
204
  priority: Task execution priority (if enabled by vLLM and the model)
205
+ timeout: Maximum time in seconds to wait for the response before raising a timeout error
197
206
 
198
207
  Returns:
199
208
  ToolOutput
200
209
  """
201
- tool_name = sys._getframe().f_code.co_name
210
+ tool_name = "extract_keywords"
202
211
  start = perf_counter()
203
212
 
204
213
  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,
214
+ operator_output = await run_with_timeout(
215
+ self._operator.run(
216
+ # User parameters
217
+ text=text,
218
+ with_analysis=with_analysis,
219
+ output_lang=output_lang,
220
+ user_prompt=user_prompt,
221
+ temperature=temperature,
222
+ logprobs=logprobs,
223
+ top_logprobs=top_logprobs,
224
+ number_of_keywords=number_of_keywords,
225
+ validator=validator,
226
+ max_validation_retries=max_validation_retries,
227
+ priority=priority,
228
+ # Internal parameters
229
+ tool_name=tool_name,
230
+ output_model=ListStr,
231
+ mode=mode,
232
+ ),
233
+ timeout=timeout,
222
234
  )
223
235
 
224
236
  metadata = ToolOutputMetadata(
@@ -252,6 +264,7 @@ class AsyncTheTool:
252
264
  validator: Callable[[Any], bool] | None = None,
253
265
  max_validation_retries: int | None = None,
254
266
  priority: int | None = None,
267
+ timeout: float | None = None,
255
268
  ) -> ToolOutput:
256
269
  """
257
270
  Perform Named Entity Recognition (NER) over the input text.
@@ -268,32 +281,36 @@ class AsyncTheTool:
268
281
  validator: Custom validation function to validate the output
269
282
  max_validation_retries: Maximum number of retry attempts if validation fails
270
283
  priority: Task execution priority (if enabled by vLLM and the model)
284
+ timeout: Maximum time in seconds to wait for the response before raising a timeout error
271
285
 
272
286
  Returns:
273
287
  ToolOutput
274
288
  """
275
- tool_name = sys._getframe().f_code.co_name
289
+ tool_name = "extract_entities"
276
290
  start = perf_counter()
277
291
 
278
292
  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,
293
+ operator_output = await run_with_timeout(
294
+ self._operator.run(
295
+ # User parameters
296
+ text=text,
297
+ entities=entities
298
+ or "all named entities (e.g., PER, ORG, LOC, DAT, etc.)",
299
+ with_analysis=with_analysis,
300
+ output_lang=output_lang,
301
+ user_prompt=user_prompt,
302
+ temperature=temperature,
303
+ logprobs=logprobs,
304
+ top_logprobs=top_logprobs,
305
+ validator=validator,
306
+ max_validation_retries=max_validation_retries,
307
+ priority=priority,
308
+ # Internal parameters
309
+ tool_name=tool_name,
310
+ output_model=ListDictStrStr,
311
+ mode=None,
312
+ ),
313
+ timeout=timeout,
297
314
  )
298
315
 
299
316
  metadata = ToolOutputMetadata(
@@ -325,6 +342,7 @@ class AsyncTheTool:
325
342
  validator: Callable[[Any], bool] | None = None,
326
343
  max_validation_retries: int | None = None,
327
344
  priority: int | None = None,
345
+ timeout: float | None = None,
328
346
  ) -> ToolOutput:
329
347
  """
330
348
  Detect if the input is phrased as a question.
@@ -339,31 +357,34 @@ class AsyncTheTool:
339
357
  validator: Custom validation function to validate the output
340
358
  max_validation_retries: Maximum number of retry attempts if validation fails
341
359
  priority: Task execution priority (if enabled by vLLM and the model)
360
+ timeout: Maximum time in seconds to wait for the response before raising a timeout error
342
361
 
343
362
  Returns:
344
363
  ToolOutput
345
364
  """
346
- tool_name = sys._getframe().f_code.co_name
347
-
365
+ tool_name = "is_question"
348
366
  start = perf_counter()
349
367
 
350
368
  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,
369
+ operator_output = await run_with_timeout(
370
+ self._operator.run(
371
+ # User parameters
372
+ text=text,
373
+ with_analysis=with_analysis,
374
+ user_prompt=user_prompt,
375
+ temperature=temperature,
376
+ logprobs=logprobs,
377
+ top_logprobs=top_logprobs,
378
+ validator=validator,
379
+ max_validation_retries=max_validation_retries,
380
+ priority=priority,
381
+ # Internal parameters
382
+ tool_name=tool_name,
383
+ output_model=Bool,
384
+ mode=None,
385
+ output_lang=None,
386
+ ),
387
+ timeout=timeout,
367
388
  )
368
389
 
369
390
  metadata = ToolOutputMetadata(
@@ -397,6 +418,7 @@ class AsyncTheTool:
397
418
  validator: Callable[[Any], bool] | None = None,
398
419
  max_validation_retries: int | None = None,
399
420
  priority: int | None = None,
421
+ timeout: float | None = None,
400
422
  ) -> ToolOutput:
401
423
  """
402
424
  Generate a single question from the given text.
@@ -413,31 +435,35 @@ class AsyncTheTool:
413
435
  validator: Custom validation function to validate the output
414
436
  max_validation_retries: Maximum number of retry attempts if validation fails
415
437
  priority: Task execution priority (if enabled by vLLM and the model)
438
+ timeout: Maximum time in seconds to wait for the response before raising a timeout error
416
439
 
417
440
  Returns:
418
441
  ToolOutput
419
442
  """
420
- tool_name = sys._getframe().f_code.co_name
443
+ tool_name = "text_to_question"
421
444
  start = perf_counter()
422
445
 
423
446
  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,
447
+ operator_output = await run_with_timeout(
448
+ self._operator.run(
449
+ # User parameters
450
+ text=text,
451
+ number_of_questions=number_of_questions,
452
+ with_analysis=with_analysis,
453
+ output_lang=output_lang,
454
+ user_prompt=user_prompt,
455
+ temperature=temperature,
456
+ logprobs=logprobs,
457
+ top_logprobs=top_logprobs,
458
+ validator=validator,
459
+ max_validation_retries=max_validation_retries,
460
+ priority=priority,
461
+ # Internal parameters
462
+ tool_name=tool_name,
463
+ output_model=ReasonListStr,
464
+ mode=None,
465
+ ),
466
+ timeout=timeout,
441
467
  )
442
468
 
443
469
  metadata = ToolOutputMetadata(
@@ -471,6 +497,7 @@ class AsyncTheTool:
471
497
  validator: Callable[[Any], bool] | None = None,
472
498
  max_validation_retries: int | None = None,
473
499
  priority: int | None = None,
500
+ timeout: float | None = None,
474
501
  ) -> ToolOutput:
475
502
  """
476
503
  Merge multiple questions into a single unified question.
@@ -486,31 +513,35 @@ class AsyncTheTool:
486
513
  validator: Custom validation function to validate the output
487
514
  max_validation_retries: Maximum number of retry attempts if validation fails
488
515
  priority: Task execution priority (if enabled by vLLM and the model)
516
+ timeout: Maximum time in seconds to wait for the response before raising a timeout error
489
517
 
490
518
  Returns:
491
519
  ToolOutput
492
520
  """
493
- tool_name = sys._getframe().f_code.co_name
521
+ tool_name = "merge_questions"
494
522
  start = perf_counter()
495
523
 
496
524
  try:
497
525
  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,
526
+ operator_output = await run_with_timeout(
527
+ self._operator.run(
528
+ # User parameters
529
+ text=text,
530
+ with_analysis=with_analysis,
531
+ output_lang=output_lang,
532
+ user_prompt=user_prompt,
533
+ temperature=temperature,
534
+ logprobs=logprobs,
535
+ top_logprobs=top_logprobs,
536
+ validator=validator,
537
+ max_validation_retries=max_validation_retries,
538
+ priority=priority,
539
+ # Internal parameters
540
+ tool_name=tool_name,
541
+ output_model=Str,
542
+ mode=mode,
543
+ ),
544
+ timeout=timeout,
514
545
  )
515
546
 
516
547
  metadata = ToolOutputMetadata(
@@ -544,6 +575,7 @@ class AsyncTheTool:
544
575
  validator: Callable[[Any], bool] | None = None,
545
576
  max_validation_retries: int | None = None,
546
577
  priority: int | None = None,
578
+ timeout: float | None = None,
547
579
  ) -> ToolOutput:
548
580
  """
549
581
  Rewrite a text with different modes.
@@ -559,30 +591,34 @@ class AsyncTheTool:
559
591
  validator: Custom validation function to validate the output
560
592
  max_validation_retries: Maximum number of retry attempts if validation fails
561
593
  priority: Task execution priority (if enabled by vLLM and the model)
594
+ timeout: Maximum time in seconds to wait for the response before raising a timeout error
562
595
 
563
596
  Returns:
564
597
  ToolOutput
565
598
  """
566
- tool_name = sys._getframe().f_code.co_name
599
+ tool_name = "rewrite"
567
600
  start = perf_counter()
568
601
 
569
602
  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,
603
+ operator_output = await run_with_timeout(
604
+ self._operator.run(
605
+ # User parameters
606
+ text=text,
607
+ with_analysis=with_analysis,
608
+ output_lang=output_lang,
609
+ user_prompt=user_prompt,
610
+ temperature=temperature,
611
+ logprobs=logprobs,
612
+ top_logprobs=top_logprobs,
613
+ validator=validator,
614
+ max_validation_retries=max_validation_retries,
615
+ priority=priority,
616
+ # Internal parameters
617
+ tool_name=tool_name,
618
+ output_model=Str,
619
+ mode=mode,
620
+ ),
621
+ timeout=timeout,
586
622
  )
587
623
 
588
624
  metadata = ToolOutputMetadata(
@@ -616,6 +652,7 @@ class AsyncTheTool:
616
652
  validator: Callable[[Any], bool] | None = None,
617
653
  max_validation_retries: int | None = None,
618
654
  priority: int | None = None,
655
+ timeout: float | None = None,
619
656
  ) -> ToolOutput:
620
657
  """
621
658
  Generate a list of questions about a subject.
@@ -632,31 +669,35 @@ class AsyncTheTool:
632
669
  validator: Custom validation function to validate the output
633
670
  max_validation_retries: Maximum number of retry attempts if validation fails
634
671
  priority: Task execution priority (if enabled by vLLM and the model)
672
+ timeout: Maximum time in seconds to wait for the response before raising a timeout error
635
673
 
636
674
  Returns:
637
675
  ToolOutput
638
676
  """
639
- tool_name = sys._getframe().f_code.co_name
677
+ tool_name = "subject_to_question"
640
678
  start = perf_counter()
641
679
 
642
680
  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,
681
+ operator_output = await run_with_timeout(
682
+ self._operator.run(
683
+ # User parameters
684
+ text=text,
685
+ number_of_questions=number_of_questions,
686
+ with_analysis=with_analysis,
687
+ output_lang=output_lang,
688
+ user_prompt=user_prompt,
689
+ temperature=temperature,
690
+ logprobs=logprobs,
691
+ top_logprobs=top_logprobs,
692
+ validator=validator,
693
+ max_validation_retries=max_validation_retries,
694
+ priority=priority,
695
+ # Internal parameters
696
+ tool_name=tool_name,
697
+ output_model=ReasonListStr,
698
+ mode=None,
699
+ ),
700
+ timeout=timeout,
660
701
  )
661
702
 
662
703
  metadata = ToolOutputMetadata(
@@ -689,6 +730,7 @@ class AsyncTheTool:
689
730
  validator: Callable[[Any], bool] | None = None,
690
731
  max_validation_retries: int | None = None,
691
732
  priority: int | None = None,
733
+ timeout: float | None = None,
692
734
  ) -> ToolOutput:
693
735
  """
694
736
  Summarize the given subject text.
@@ -704,30 +746,34 @@ class AsyncTheTool:
704
746
  validator: Custom validation function to validate the output
705
747
  max_validation_retries: Maximum number of retry attempts if validation fails
706
748
  priority: Task execution priority (if enabled by vLLM and the model)
749
+ timeout: Maximum time in seconds to wait for the response before raising a timeout error
707
750
 
708
751
  Returns:
709
752
  ToolOutput
710
753
  """
711
- tool_name = sys._getframe().f_code.co_name
754
+ tool_name = "summarize"
712
755
  start = perf_counter()
713
756
 
714
757
  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,
758
+ operator_output = await run_with_timeout(
759
+ self._operator.run(
760
+ # User parameters
761
+ text=text,
762
+ with_analysis=with_analysis,
763
+ output_lang=output_lang,
764
+ user_prompt=user_prompt,
765
+ temperature=temperature,
766
+ logprobs=logprobs,
767
+ top_logprobs=top_logprobs,
768
+ validator=validator,
769
+ max_validation_retries=max_validation_retries,
770
+ priority=priority,
771
+ # Internal parameters
772
+ tool_name=tool_name,
773
+ output_model=Str,
774
+ mode=None,
775
+ ),
776
+ timeout=timeout,
731
777
  )
732
778
 
733
779
  metadata = ToolOutputMetadata(
@@ -761,6 +807,7 @@ class AsyncTheTool:
761
807
  validator: Callable[[Any], bool] | None = None,
762
808
  max_validation_retries: int | None = None,
763
809
  priority: int | None = None,
810
+ timeout: float | None = None,
764
811
  ) -> ToolOutput:
765
812
  """
766
813
  Translate text between languages.
@@ -779,11 +826,12 @@ class AsyncTheTool:
779
826
  validator: Custom validation function to validate the output
780
827
  max_validation_retries: Maximum number of retry attempts if validation fails
781
828
  priority: Task execution priority (if enabled by vLLM and the model)
829
+ timeout: Maximum time in seconds to wait for the response before raising a timeout error
782
830
 
783
831
  Returns:
784
832
  ToolOutput
785
833
  """
786
- tool_name = sys._getframe().f_code.co_name
834
+ tool_name = "translate"
787
835
  start = perf_counter()
788
836
 
789
837
  try:
@@ -794,23 +842,26 @@ class AsyncTheTool:
794
842
  logprobs_list = []
795
843
 
796
844
  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,
845
+ chunk_operator_output = await run_with_timeout(
846
+ self._operator.run(
847
+ # User parameters
848
+ text=chunk,
849
+ target_language=target_language,
850
+ with_analysis=with_analysis,
851
+ user_prompt=user_prompt,
852
+ temperature=temperature,
853
+ logprobs=logprobs,
854
+ top_logprobs=top_logprobs,
855
+ validator=validator,
856
+ max_validation_retries=max_validation_retries,
857
+ priority=priority,
858
+ # Internal parameters
859
+ tool_name=tool_name,
860
+ output_model=Str,
861
+ mode=None,
862
+ output_lang=None,
863
+ ),
864
+ timeout=timeout,
814
865
  )
815
866
 
816
867
  translation += chunk_operator_output.result + "\n"
@@ -831,23 +882,26 @@ class AsyncTheTool:
831
882
  )
832
883
 
833
884
  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,
885
+ operator_output = await run_with_timeout(
886
+ self._operator.run(
887
+ # User parameters
888
+ text=text,
889
+ target_language=target_language,
890
+ with_analysis=with_analysis,
891
+ user_prompt=user_prompt,
892
+ temperature=temperature,
893
+ logprobs=logprobs,
894
+ top_logprobs=top_logprobs,
895
+ validator=validator,
896
+ max_validation_retries=max_validation_retries,
897
+ priority=priority,
898
+ # Internal parameters
899
+ tool_name=tool_name,
900
+ output_model=Str,
901
+ mode=None,
902
+ output_lang=None,
903
+ ),
904
+ timeout=timeout,
851
905
  )
852
906
 
853
907
  metadata = ToolOutputMetadata(
@@ -880,6 +934,7 @@ class AsyncTheTool:
880
934
  validator: Callable[[Any], bool] | None = None,
881
935
  max_validation_retries: int | None = None,
882
936
  priority: int | None = None,
937
+ timeout: float | None = None,
883
938
  ) -> ToolOutput:
884
939
  """
885
940
  Proposition input text to meaningful sentences.
@@ -897,30 +952,34 @@ class AsyncTheTool:
897
952
  validator: Custom validation function to validate the output
898
953
  max_validation_retries: Maximum number of retry attempts if validation fails
899
954
  priority: Task execution priority (if enabled by vLLM and the model)
955
+ timeout: Maximum time in seconds to wait for the response before raising a timeout error
900
956
 
901
957
  Returns:
902
958
  ToolOutput
903
959
  """
904
- tool_name = sys._getframe().f_code.co_name
960
+ tool_name = "propositionize"
905
961
  start = perf_counter()
906
962
 
907
963
  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,
964
+ operator_output = await run_with_timeout(
965
+ self._operator.run(
966
+ # User parameters
967
+ text=text,
968
+ with_analysis=with_analysis,
969
+ output_lang=output_lang,
970
+ user_prompt=user_prompt,
971
+ temperature=temperature,
972
+ logprobs=logprobs,
973
+ top_logprobs=top_logprobs,
974
+ validator=validator,
975
+ max_validation_retries=max_validation_retries,
976
+ priority=priority,
977
+ # Internal parameters
978
+ tool_name=tool_name,
979
+ output_model=ListStr,
980
+ mode=None,
981
+ ),
982
+ timeout=timeout,
924
983
  )
925
984
 
926
985
  metadata = ToolOutputMetadata(
@@ -954,6 +1013,7 @@ class AsyncTheTool:
954
1013
  validator: Callable[[Any], bool] | None = None,
955
1014
  max_validation_retries: int | None = None,
956
1015
  priority: int | None = None,
1016
+ timeout: float | None = None,
957
1017
  ) -> ToolOutput:
958
1018
  """
959
1019
  Checks wheather a statement is relevant to the source text or not.
@@ -962,7 +1022,7 @@ class AsyncTheTool:
962
1022
 
963
1023
  Arguments:
964
1024
  text: The input text
965
- source_text: the source text that we want to check relation of text to it
1025
+ source_text: The source text that we want to check relation of text to it
966
1026
  with_analysis: Whether to include detailed reasoning analysis
967
1027
  output_lang: Language for the output
968
1028
  user_prompt: Additional instructions
@@ -972,31 +1032,35 @@ class AsyncTheTool:
972
1032
  validator: Custom validation function to validate the output
973
1033
  max_validation_retries: Maximum number of retry attempts if validation fails
974
1034
  priority: Task execution priority (if enabled by vLLM and the model)
1035
+ timeout: Maximum time in seconds to wait for the response before raising a timeout error
975
1036
 
976
1037
  Returns:
977
1038
  ToolOutput
978
1039
  """
979
- tool_name = sys._getframe().f_code.co_name
1040
+ tool_name = "check_fact"
980
1041
  start = perf_counter()
981
1042
 
982
1043
  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,
1044
+ operator_output = await run_with_timeout(
1045
+ self._operator.run(
1046
+ # User parameters
1047
+ text=text,
1048
+ source_text=source_text,
1049
+ with_analysis=with_analysis,
1050
+ output_lang=output_lang,
1051
+ user_prompt=user_prompt,
1052
+ temperature=temperature,
1053
+ logprobs=logprobs,
1054
+ top_logprobs=top_logprobs,
1055
+ validator=validator,
1056
+ max_validation_retries=max_validation_retries,
1057
+ priority=priority,
1058
+ # Internal parameters
1059
+ tool_name=tool_name,
1060
+ output_model=Bool,
1061
+ mode=None,
1062
+ ),
1063
+ timeout=timeout,
1000
1064
  )
1001
1065
 
1002
1066
  metadata = ToolOutputMetadata(
@@ -1030,6 +1094,7 @@ class AsyncTheTool:
1030
1094
  validator: Callable[[Any], bool] | None = None,
1031
1095
  max_validation_retries: int | None = None,
1032
1096
  priority: int | None = None,
1097
+ timeout: float | None = None,
1033
1098
  ) -> ToolOutput:
1034
1099
  """
1035
1100
  Custom tool that can do almost anything!
@@ -1046,32 +1111,36 @@ class AsyncTheTool:
1046
1111
  validator: Custom validation function to validate the output
1047
1112
  max_validation_retries: Maximum number of retry attempts if validation fails
1048
1113
  priority: Task execution priority (if enabled by vLLM and the model)
1114
+ timeout: Maximum time in seconds to wait for the response before raising a timeout error
1049
1115
 
1050
1116
  Returns:
1051
1117
  ToolOutput
1052
1118
  """
1053
- tool_name = sys._getframe().f_code.co_name
1119
+ tool_name = "run_custom"
1054
1120
  start = perf_counter()
1055
1121
 
1056
1122
  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,
1123
+ operator_output = await run_with_timeout(
1124
+ self._operator.run(
1125
+ # User paramaeters
1126
+ text=prompt,
1127
+ output_model=output_model,
1128
+ with_analysis=with_analysis,
1129
+ analyze_template=analyze_template,
1130
+ output_model_str=output_model.model_json_schema(),
1131
+ output_lang=output_lang,
1132
+ temperature=temperature,
1133
+ logprobs=logprobs,
1134
+ top_logprobs=top_logprobs,
1135
+ validator=validator,
1136
+ max_validation_retries=max_validation_retries,
1137
+ priority=priority,
1138
+ # Internal parameters
1139
+ tool_name=tool_name,
1140
+ user_prompt=None,
1141
+ mode=None,
1142
+ ),
1143
+ timeout=timeout,
1075
1144
  )
1076
1145
 
1077
1146
  metadata = ToolOutputMetadata(
@@ -1,4 +1,3 @@
1
- import sys
2
1
  from collections.abc import Callable
3
2
  from time import perf_counter
4
3
  from typing import Any, Literal
@@ -66,7 +65,7 @@ class TheTool:
66
65
  ToolOutput
67
66
 
68
67
  """
69
- tool_name = sys._getframe().f_code.co_name
68
+ tool_name = "categorize"
70
69
  start = perf_counter()
71
70
 
72
71
  try:
@@ -198,7 +197,7 @@ class TheTool:
198
197
  Returns:
199
198
  ToolOutput
200
199
  """
201
- tool_name = sys._getframe().f_code.co_name
200
+ tool_name = "extract_keywords"
202
201
  start = perf_counter()
203
202
 
204
203
  try:
@@ -211,7 +210,6 @@ class TheTool:
211
210
  temperature=temperature,
212
211
  logprobs=logprobs,
213
212
  top_logprobs=top_logprobs,
214
- mode=mode,
215
213
  number_of_keywords=number_of_keywords,
216
214
  validator=validator,
217
215
  max_validation_retries=max_validation_retries,
@@ -219,6 +217,7 @@ class TheTool:
219
217
  # Internal parameters
220
218
  tool_name=tool_name,
221
219
  output_model=ListStr,
220
+ mode=mode,
222
221
  )
223
222
 
224
223
  metadata = ToolOutputMetadata(
@@ -272,7 +271,7 @@ class TheTool:
272
271
  Returns:
273
272
  ToolOutput
274
273
  """
275
- tool_name = sys._getframe().f_code.co_name
274
+ tool_name = "extract_entities"
276
275
  start = perf_counter()
277
276
 
278
277
  try:
@@ -343,7 +342,7 @@ class TheTool:
343
342
  Returns:
344
343
  ToolOutput
345
344
  """
346
- tool_name = sys._getframe().f_code.co_name
345
+ tool_name = "is_question"
347
346
  start = perf_counter()
348
347
 
349
348
  try:
@@ -416,7 +415,7 @@ class TheTool:
416
415
  Returns:
417
416
  ToolOutput
418
417
  """
419
- tool_name = sys._getframe().f_code.co_name
418
+ tool_name = "text_to_question"
420
419
  start = perf_counter()
421
420
 
422
421
  try:
@@ -489,7 +488,7 @@ class TheTool:
489
488
  Returns:
490
489
  ToolOutput
491
490
  """
492
- tool_name = sys._getframe().f_code.co_name
491
+ tool_name = "merge_questions"
493
492
  start = perf_counter()
494
493
 
495
494
  try:
@@ -562,7 +561,7 @@ class TheTool:
562
561
  Returns:
563
562
  ToolOutput
564
563
  """
565
- tool_name = sys._getframe().f_code.co_name
564
+ tool_name = "rewrite"
566
565
  start = perf_counter()
567
566
 
568
567
  try:
@@ -635,7 +634,7 @@ class TheTool:
635
634
  Returns:
636
635
  ToolOutput
637
636
  """
638
- tool_name = sys._getframe().f_code.co_name
637
+ tool_name = "subject_to_question"
639
638
  start = perf_counter()
640
639
 
641
640
  try:
@@ -707,7 +706,7 @@ class TheTool:
707
706
  Returns:
708
707
  ToolOutput
709
708
  """
710
- tool_name = sys._getframe().f_code.co_name
709
+ tool_name = "summarize"
711
710
  start = perf_counter()
712
711
 
713
712
  try:
@@ -782,7 +781,7 @@ class TheTool:
782
781
  Returns:
783
782
  ToolOutput
784
783
  """
785
- tool_name = sys._getframe().f_code.co_name
784
+ tool_name = "translate"
786
785
  start = perf_counter()
787
786
 
788
787
  try:
@@ -900,7 +899,7 @@ class TheTool:
900
899
  Returns:
901
900
  ToolOutput
902
901
  """
903
- tool_name = sys._getframe().f_code.co_name
902
+ tool_name = "propositionize"
904
903
  start = perf_counter()
905
904
 
906
905
  try:
@@ -961,7 +960,7 @@ class TheTool:
961
960
 
962
961
  Arguments:
963
962
  text: The input text
964
- source_text: the source text that we want to check relation of text to it
963
+ source_text: The source text that we want to check relation of text to it
965
964
  with_analysis: Whether to include detailed reasoning analysis
966
965
  output_lang: Language for the output
967
966
  user_prompt: Additional instructions
@@ -975,13 +974,14 @@ class TheTool:
975
974
  Returns:
976
975
  ToolOutput
977
976
  """
978
- tool_name = sys._getframe().f_code.co_name
977
+ tool_name = "check_fact"
979
978
  start = perf_counter()
980
979
 
981
980
  try:
982
981
  operator_output = self._operator.run(
983
982
  # User parameters
984
983
  text=text,
984
+ source_text=source_text,
985
985
  with_analysis=with_analysis,
986
986
  output_lang=output_lang,
987
987
  user_prompt=user_prompt,
@@ -995,7 +995,6 @@ class TheTool:
995
995
  tool_name=tool_name,
996
996
  output_model=Bool,
997
997
  mode=None,
998
- source_text=source_text,
999
998
  )
1000
999
 
1001
1000
  metadata = ToolOutputMetadata(
@@ -1049,7 +1048,7 @@ class TheTool:
1049
1048
  Returns:
1050
1049
  ToolOutput
1051
1050
  """
1052
- tool_name = sys._getframe().f_code.co_name
1051
+ tool_name = "run_custom"
1053
1052
  start = perf_counter()
1054
1053
 
1055
1054
  try: