hamtaa-texttools 1.1.10__py3-none-any.whl → 1.1.11__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.1.10
3
+ Version: 1.1.11
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
@@ -79,7 +79,7 @@ TextTools provides several optional flags to customize LLM behavior:
79
79
 
80
80
  - **`temperature (float)`** → Determines how creative the model should respond. Takes a float number from `0.0` to `2.0`.
81
81
 
82
- - **`validator (Callable)`** → Forces TheTool to validate the output result based on your custom validator. Validator should return bool (True if there were no problem, False if the validation failed.) If validator failed, TheTool will retry to get another output by modifying `temperature`.
82
+ - **`validator (Callable)`** → Forces TheTool to validate the output result based on your custom validator. Validator should return bool (True if there were no problem, False if the validation failed.) If validator failed, TheTool will retry to get another output by modifying `temperature`. You can specify `max_validation_retries=<N>` to change the number of retries.
83
83
 
84
84
  All these parameters can be used individually or together to tailor the behavior of any tool in **TextTools**.
85
85
 
@@ -1,4 +1,4 @@
1
- hamtaa_texttools-1.1.10.dist-info/licenses/LICENSE,sha256=Hb2YOBKy2MJQLnyLrX37B4ZVuac8eaIcE71SvVIMOLg,1082
1
+ hamtaa_texttools-1.1.11.dist-info/licenses/LICENSE,sha256=Hb2YOBKy2MJQLnyLrX37B4ZVuac8eaIcE71SvVIMOLg,1082
2
2
  texttools/__init__.py,sha256=EZPPNPafVGvBaxjG9anP0piqH3gAC0DdjdAckQeAgNU,251
3
3
  texttools/batch/batch_config.py,sha256=FCDXy9TfH7xjd1PHvn_CtdwEQSq-YO5sktiaMZEId58,740
4
4
  texttools/batch/batch_runner.py,sha256=zzzVIXedmaq-8fqsFtGRR64F7CtYRLlhQeBu8uMwJQg,9385
@@ -16,15 +16,15 @@ texttools/prompts/subject_to_question.yaml,sha256=C7x7rNNm6U_ZG9HOn6zuzYOtvJUZ2s
16
16
  texttools/prompts/summarize.yaml,sha256=o6rxGPfWtZd61Duvm8NVvCJqfq73b-wAuMSKR6UYUqY,459
17
17
  texttools/prompts/text_to_question.yaml,sha256=UheKYpDn6iyKI8NxunHZtFpNyfCLZZe5cvkuXpurUJY,783
18
18
  texttools/prompts/translate.yaml,sha256=mGT2uBCei6uucWqVbs4silk-UV060v3G0jnt0P6sr50,634
19
- texttools/tools/async_tools.py,sha256=yEj4dM2bdW_12hxvimhxPOGfGhl1PqFsHM3Z4toCTaM,14813
20
- texttools/tools/sync_tools.py,sha256=wHY0O8R9HipUz0P268zk1w3SlFxEIffm5EjX4tcWxNM,14579
21
- texttools/tools/internals/async_operator.py,sha256=5sVc5K5-Vuulsxly0IfrLmzd8W7ySI4cY09myyOGL0I,7022
22
- texttools/tools/internals/base_operator.py,sha256=l2Mg59MGIf396yPx1CAgcplKclOptQWeTR0UIz9VTdk,2255
19
+ texttools/tools/async_tools.py,sha256=rLg2oU9isa_3UF9sKNzwIFjYK8pZNXcHR6P8QSKexYA,15933
20
+ texttools/tools/sync_tools.py,sha256=eSNxPNmU1FY5u5LDJGshXSXpHb-CMrSL3Q-acacpuXU,15704
21
+ texttools/tools/internals/async_operator.py,sha256=XawSPIylrOIN8EGXQn-X6jRXHSX-B6k-Af1lAnT2F4Y,7073
22
+ texttools/tools/internals/base_operator.py,sha256=VgZISYaPwPaoTyoWLT_7wU17Oq4KGQ6XWDZpLwOyOm8,2179
23
23
  texttools/tools/internals/formatters.py,sha256=tACNLP6PeoqaRpNudVxBaHA25zyWqWYPZQuYysIu88g,941
24
- texttools/tools/internals/operator.py,sha256=W0DxTGB3cbtDfzLqwMCM8x5xiVWgN0vZWX8PzJwAQKE,6795
25
24
  texttools/tools/internals/output_models.py,sha256=ekpbyocmXj_dee7ieOT1zOkMo9cPHT7xcUFCZoUaXA0,1886
26
25
  texttools/tools/internals/prompt_loader.py,sha256=4g6-U8kqrGN7VpNaRcrBcnF-h03PXjUDBP0lL0_4EZY,1953
27
- hamtaa_texttools-1.1.10.dist-info/METADATA,sha256=6X7Qd8nOAIn7reZ5l-66CyK5fczMADtlIfdIbypJIUE,9101
28
- hamtaa_texttools-1.1.10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
29
- hamtaa_texttools-1.1.10.dist-info/top_level.txt,sha256=5Mh0jIxxZ5rOXHGJ6Mp-JPKviywwN0MYuH0xk5bEWqE,10
30
- hamtaa_texttools-1.1.10.dist-info/RECORD,,
26
+ texttools/tools/internals/sync_operator.py,sha256=UCzQatIeZ_o6sQr3lna1elYpUphHcO6EeJwMK8PymAk,6846
27
+ hamtaa_texttools-1.1.11.dist-info/METADATA,sha256=nSiDrQTIQRX957pwvXAHsppGuwI5eU8HdAmgqyrTgew,9179
28
+ hamtaa_texttools-1.1.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
29
+ hamtaa_texttools-1.1.11.dist-info/top_level.txt,sha256=5Mh0jIxxZ5rOXHGJ6Mp-JPKviywwN0MYuH0xk5bEWqE,10
30
+ hamtaa_texttools-1.1.11.dist-info/RECORD,,
@@ -35,6 +35,7 @@ class AsyncTheTool:
35
35
  logprobs: bool = False,
36
36
  top_logprobs: int | None = None,
37
37
  validator: Callable[[Any], bool] | None = None,
38
+ max_validation_retries: int | None = None,
38
39
  ) -> OM.ToolOutput:
39
40
  """
40
41
  Categorize a text into a single Islamic studies domain category.
@@ -54,6 +55,7 @@ class AsyncTheTool:
54
55
  logprobs=logprobs,
55
56
  top_logprobs=top_logprobs,
56
57
  validator=validator,
58
+ max_validation_retries=max_validation_retries,
57
59
  # Internal parameters
58
60
  prompt_file="categorizer.yaml",
59
61
  output_model=OM.CategorizerOutput,
@@ -71,6 +73,7 @@ class AsyncTheTool:
71
73
  logprobs: bool = False,
72
74
  top_logprobs: int | None = None,
73
75
  validator: Callable[[Any], bool] | None = None,
76
+ max_validation_retries: int | None = None,
74
77
  ) -> OM.ToolOutput:
75
78
  """
76
79
  Extract salient keywords from text.
@@ -91,6 +94,7 @@ class AsyncTheTool:
91
94
  logprobs=logprobs,
92
95
  top_logprobs=top_logprobs,
93
96
  validator=validator,
97
+ max_validation_retries=max_validation_retries,
94
98
  # Internal parameters
95
99
  prompt_file="extract_keywords.yaml",
96
100
  output_model=OM.ListStrOutput,
@@ -107,6 +111,7 @@ class AsyncTheTool:
107
111
  logprobs: bool = False,
108
112
  top_logprobs: int | None = None,
109
113
  validator: Callable[[Any], bool] | None = None,
114
+ max_validation_retries: int | None = None,
110
115
  ) -> OM.ToolOutput:
111
116
  """
112
117
  Perform Named Entity Recognition (NER) over the input text.
@@ -127,6 +132,7 @@ class AsyncTheTool:
127
132
  logprobs=logprobs,
128
133
  top_logprobs=top_logprobs,
129
134
  validator=validator,
135
+ max_validation_retries=max_validation_retries,
130
136
  # Internal parameters
131
137
  prompt_file="extract_entities.yaml",
132
138
  output_model=OM.ListDictStrStrOutput,
@@ -142,6 +148,7 @@ class AsyncTheTool:
142
148
  logprobs: bool = False,
143
149
  top_logprobs: int | None = None,
144
150
  validator: Callable[[Any], bool] | None = None,
151
+ max_validation_retries: int | None = None,
145
152
  ) -> OM.ToolOutput:
146
153
  """
147
154
  Detect if the input is phrased as a question.
@@ -161,6 +168,7 @@ class AsyncTheTool:
161
168
  logprobs=logprobs,
162
169
  top_logprobs=top_logprobs,
163
170
  validator=validator,
171
+ max_validation_retries=max_validation_retries,
164
172
  # Internal parameters
165
173
  prompt_file="is_question.yaml",
166
174
  output_model=OM.BoolOutput,
@@ -178,6 +186,7 @@ class AsyncTheTool:
178
186
  logprobs: bool = False,
179
187
  top_logprobs: int | None = None,
180
188
  validator: Callable[[Any], bool] | None = None,
189
+ max_validation_retries: int | None = None,
181
190
  ) -> OM.ToolOutput:
182
191
  """
183
192
  Generate a single question from the given text.
@@ -198,6 +207,7 @@ class AsyncTheTool:
198
207
  logprobs=logprobs,
199
208
  top_logprobs=top_logprobs,
200
209
  validator=validator,
210
+ max_validation_retries=max_validation_retries,
201
211
  # Internal parameters
202
212
  prompt_file="text_to_question.yaml",
203
213
  output_model=OM.StrOutput,
@@ -215,6 +225,7 @@ class AsyncTheTool:
215
225
  top_logprobs: int | None = None,
216
226
  mode: Literal["default", "reason"] = "default",
217
227
  validator: Callable[[Any], bool] | None = None,
228
+ max_validation_retries: int | None = None,
218
229
  ) -> OM.ToolOutput:
219
230
  """
220
231
  Merge multiple questions into a single unified question.
@@ -236,6 +247,7 @@ class AsyncTheTool:
236
247
  logprobs=logprobs,
237
248
  top_logprobs=top_logprobs,
238
249
  validator=validator,
250
+ max_validation_retries=max_validation_retries,
239
251
  # Internal parameters
240
252
  prompt_file="merge_questions.yaml",
241
253
  output_model=OM.StrOutput,
@@ -253,6 +265,7 @@ class AsyncTheTool:
253
265
  top_logprobs: int | None = None,
254
266
  mode: Literal["positive", "negative", "hard_negative"] = "positive",
255
267
  validator: Callable[[Any], bool] | None = None,
268
+ max_validation_retries: int | None = None,
256
269
  ) -> OM.ToolOutput:
257
270
  """
258
271
  Rewrite a text with different modes.
@@ -273,6 +286,7 @@ class AsyncTheTool:
273
286
  logprobs=logprobs,
274
287
  top_logprobs=top_logprobs,
275
288
  validator=validator,
289
+ max_validation_retries=max_validation_retries,
276
290
  # Internal parameters
277
291
  prompt_file="rewrite.yaml",
278
292
  output_model=OM.StrOutput,
@@ -290,6 +304,7 @@ class AsyncTheTool:
290
304
  logprobs: bool = False,
291
305
  top_logprobs: int | None = None,
292
306
  validator: Callable[[Any], bool] | None = None,
307
+ max_validation_retries: int | None = None,
293
308
  ) -> OM.ToolOutput:
294
309
  """
295
310
  Generate a list of questions about a subject.
@@ -311,6 +326,7 @@ class AsyncTheTool:
311
326
  logprobs=logprobs,
312
327
  top_logprobs=top_logprobs,
313
328
  validator=validator,
329
+ max_validation_retries=max_validation_retries,
314
330
  # Internal parameters
315
331
  prompt_file="subject_to_question.yaml",
316
332
  output_model=OM.ReasonListStrOutput,
@@ -327,6 +343,7 @@ class AsyncTheTool:
327
343
  logprobs: bool = False,
328
344
  top_logprobs: int | None = None,
329
345
  validator: Callable[[Any], bool] | None = None,
346
+ max_validation_retries: int | None = None,
330
347
  ) -> OM.ToolOutput:
331
348
  """
332
349
  Summarize the given subject text.
@@ -347,6 +364,7 @@ class AsyncTheTool:
347
364
  logprobs=logprobs,
348
365
  top_logprobs=top_logprobs,
349
366
  validator=validator,
367
+ max_validation_retries=max_validation_retries,
350
368
  # Internal parameters
351
369
  prompt_file="summarize.yaml",
352
370
  output_model=OM.StrOutput,
@@ -363,6 +381,7 @@ class AsyncTheTool:
363
381
  logprobs: bool = False,
364
382
  top_logprobs: int | None = None,
365
383
  validator: Callable[[Any], bool] | None = None,
384
+ max_validation_retries: int | None = None,
366
385
  ) -> OM.ToolOutput:
367
386
  """
368
387
  Translate text between languages.
@@ -383,6 +402,7 @@ class AsyncTheTool:
383
402
  logprobs=logprobs,
384
403
  top_logprobs=top_logprobs,
385
404
  validator=validator,
405
+ max_validation_retries=max_validation_retries,
386
406
  # Internal parameters
387
407
  prompt_file="translate.yaml",
388
408
  output_model=OM.StrOutput,
@@ -81,6 +81,7 @@ class AsyncOperator(BaseOperator):
81
81
  logprobs: bool,
82
82
  top_logprobs: int | None,
83
83
  validator: Callable[[Any], bool] | None,
84
+ max_validation_retries: int | None,
84
85
  # Internal parameters
85
86
  prompt_file: str,
86
87
  output_model: Type[T],
@@ -141,7 +142,7 @@ class AsyncOperator(BaseOperator):
141
142
 
142
143
  # Retry logic if validation fails
143
144
  if validator and not validator(output.result):
144
- for attempt in range(self.MAX_RETRIES):
145
+ for attempt in range(max_validation_retries):
145
146
  logger.warning(
146
147
  f"Validation failed, retrying for the {attempt + 1} time."
147
148
  )
@@ -13,9 +13,6 @@ ClientType = Union[OpenAI, AsyncOpenAI]
13
13
 
14
14
 
15
15
  class BaseOperator:
16
- # Max retry in case of failed output validation
17
- MAX_RETRIES = 3
18
-
19
16
  def __init__(self, client: ClientType, model: str):
20
17
  self._client = client
21
18
  self._model = model
@@ -80,6 +80,7 @@ class Operator(BaseOperator):
80
80
  logprobs: bool,
81
81
  top_logprobs: int | None,
82
82
  validator: Callable[[Any], bool] | None,
83
+ max_validation_retries: int | None,
83
84
  # Internal parameters
84
85
  prompt_file: str,
85
86
  output_model: Type[T],
@@ -139,7 +140,7 @@ class Operator(BaseOperator):
139
140
 
140
141
  # Retry logic if validation fails
141
142
  if validator and not validator(output.result):
142
- for attempt in range(self.MAX_RETRIES):
143
+ for attempt in range(max_validation_retries):
143
144
  logger.warning(
144
145
  f"Validation failed, retrying for the {attempt + 1} time."
145
146
  )
@@ -2,7 +2,7 @@ from typing import Literal, Any, Callable
2
2
 
3
3
  from openai import OpenAI
4
4
 
5
- from texttools.tools.internals.operator import Operator
5
+ from texttools.tools.internals.sync_operator import Operator
6
6
  import texttools.tools.internals.output_models as OM
7
7
 
8
8
 
@@ -33,6 +33,7 @@ class TheTool:
33
33
  logprobs: bool = False,
34
34
  top_logprobs: int | None = None,
35
35
  validator: Callable[[Any], bool] | None = None,
36
+ max_validation_retries: int | None = None,
36
37
  ) -> OM.ToolOutput:
37
38
  """
38
39
  Categorize a text into a single Islamic studies domain category.
@@ -52,6 +53,7 @@ class TheTool:
52
53
  logprobs=logprobs,
53
54
  top_logprobs=top_logprobs,
54
55
  validator=validator,
56
+ max_validation_retries=max_validation_retries,
55
57
  # Internal parameters
56
58
  prompt_file="categorizer.yaml",
57
59
  output_model=OM.CategorizerOutput,
@@ -69,6 +71,7 @@ class TheTool:
69
71
  logprobs: bool = False,
70
72
  top_logprobs: int | None = None,
71
73
  validator: Callable[[Any], bool] | None = None,
74
+ max_validation_retries: int | None = None,
72
75
  ) -> OM.ToolOutput:
73
76
  """
74
77
  Extract salient keywords from text.
@@ -89,6 +92,7 @@ class TheTool:
89
92
  logprobs=logprobs,
90
93
  top_logprobs=top_logprobs,
91
94
  validator=validator,
95
+ max_validation_retries=max_validation_retries,
92
96
  # Internal parameters
93
97
  prompt_file="extract_keywords.yaml",
94
98
  output_model=OM.ListStrOutput,
@@ -105,6 +109,7 @@ class TheTool:
105
109
  logprobs: bool = False,
106
110
  top_logprobs: int | None = None,
107
111
  validator: Callable[[Any], bool] | None = None,
112
+ max_validation_retries: int | None = None,
108
113
  ) -> OM.ToolOutput:
109
114
  """
110
115
  Perform Named Entity Recognition (NER) over the input text.
@@ -125,6 +130,7 @@ class TheTool:
125
130
  logprobs=logprobs,
126
131
  top_logprobs=top_logprobs,
127
132
  validator=validator,
133
+ max_validation_retries=max_validation_retries,
128
134
  # Internal parameters
129
135
  prompt_file="extract_entities.yaml",
130
136
  output_model=OM.ListDictStrStrOutput,
@@ -140,6 +146,7 @@ class TheTool:
140
146
  logprobs: bool = False,
141
147
  top_logprobs: int | None = None,
142
148
  validator: Callable[[Any], bool] | None = None,
149
+ max_validation_retries: int | None = None,
143
150
  ) -> OM.ToolOutput:
144
151
  """
145
152
  Detect if the input is phrased as a question.
@@ -159,6 +166,7 @@ class TheTool:
159
166
  logprobs=logprobs,
160
167
  top_logprobs=top_logprobs,
161
168
  validator=validator,
169
+ max_validation_retries=max_validation_retries,
162
170
  # Internal parameters
163
171
  prompt_file="is_question.yaml",
164
172
  output_model=OM.BoolOutput,
@@ -176,6 +184,7 @@ class TheTool:
176
184
  logprobs: bool = False,
177
185
  top_logprobs: int | None = None,
178
186
  validator: Callable[[Any], bool] | None = None,
187
+ max_validation_retries: int | None = None,
179
188
  ) -> OM.ToolOutput:
180
189
  """
181
190
  Generate a single question from the given text.
@@ -196,6 +205,7 @@ class TheTool:
196
205
  logprobs=logprobs,
197
206
  top_logprobs=top_logprobs,
198
207
  validator=validator,
208
+ max_validation_retries=max_validation_retries,
199
209
  # Internal parameters
200
210
  prompt_file="text_to_question.yaml",
201
211
  output_model=OM.StrOutput,
@@ -213,6 +223,7 @@ class TheTool:
213
223
  top_logprobs: int | None = None,
214
224
  mode: Literal["default", "reason"] = "default",
215
225
  validator: Callable[[Any], bool] | None = None,
226
+ max_validation_retries: int | None = None,
216
227
  ) -> OM.ToolOutput:
217
228
  """
218
229
  Merge multiple questions into a single unified question.
@@ -234,6 +245,7 @@ class TheTool:
234
245
  logprobs=logprobs,
235
246
  top_logprobs=top_logprobs,
236
247
  validator=validator,
248
+ max_validation_retries=max_validation_retries,
237
249
  # Internal parameters
238
250
  prompt_file="merge_questions.yaml",
239
251
  output_model=OM.StrOutput,
@@ -251,6 +263,7 @@ class TheTool:
251
263
  top_logprobs: int | None = None,
252
264
  mode: Literal["positive", "negative", "hard_negative"] = "positive",
253
265
  validator: Callable[[Any], bool] | None = None,
266
+ max_validation_retries: int | None = None,
254
267
  ) -> OM.ToolOutput:
255
268
  """
256
269
  Rewrite a text with different modes.
@@ -271,6 +284,7 @@ class TheTool:
271
284
  logprobs=logprobs,
272
285
  top_logprobs=top_logprobs,
273
286
  validator=validator,
287
+ max_validation_retries=max_validation_retries,
274
288
  # Internal parameters
275
289
  prompt_file="rewrite.yaml",
276
290
  output_model=OM.StrOutput,
@@ -288,6 +302,7 @@ class TheTool:
288
302
  logprobs: bool = False,
289
303
  top_logprobs: int | None = None,
290
304
  validator: Callable[[Any], bool] | None = None,
305
+ max_validation_retries: int | None = None,
291
306
  ) -> OM.ToolOutput:
292
307
  """
293
308
  Generate a list of questions about a subject.
@@ -309,6 +324,7 @@ class TheTool:
309
324
  logprobs=logprobs,
310
325
  top_logprobs=top_logprobs,
311
326
  validator=validator,
327
+ max_validation_retries=max_validation_retries,
312
328
  # Internal parameters
313
329
  prompt_file="subject_to_question.yaml",
314
330
  output_model=OM.ReasonListStrOutput,
@@ -325,6 +341,7 @@ class TheTool:
325
341
  logprobs: bool = False,
326
342
  top_logprobs: int | None = None,
327
343
  validator: Callable[[Any], bool] | None = None,
344
+ max_validation_retries: int | None = None,
328
345
  ) -> OM.ToolOutput:
329
346
  """
330
347
  Summarize the given subject text.
@@ -345,6 +362,7 @@ class TheTool:
345
362
  logprobs=logprobs,
346
363
  top_logprobs=top_logprobs,
347
364
  validator=validator,
365
+ max_validation_retries=max_validation_retries,
348
366
  # Internal parameters
349
367
  prompt_file="summarize.yaml",
350
368
  output_model=OM.StrOutput,
@@ -361,6 +379,7 @@ class TheTool:
361
379
  logprobs: bool = False,
362
380
  top_logprobs: int | None = None,
363
381
  validator: Callable[[Any], bool] | None = None,
382
+ max_validation_retries: int | None = None,
364
383
  ) -> OM.ToolOutput:
365
384
  """
366
385
  Translate text between languages.
@@ -381,6 +400,7 @@ class TheTool:
381
400
  logprobs=logprobs,
382
401
  top_logprobs=top_logprobs,
383
402
  validator=validator,
403
+ max_validation_retries=max_validation_retries,
384
404
  # Internal parameters
385
405
  prompt_file="translate.yaml",
386
406
  output_model=OM.StrOutput,