hamtaa-texttools 1.0.4__py3-none-any.whl → 1.0.5__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.
Potentially problematic release.
This version of hamtaa-texttools might be problematic. Click here for more details.
- {hamtaa_texttools-1.0.4.dist-info → hamtaa_texttools-1.0.5.dist-info}/METADATA +192 -141
- hamtaa_texttools-1.0.5.dist-info/RECORD +30 -0
- {hamtaa_texttools-1.0.4.dist-info → hamtaa_texttools-1.0.5.dist-info}/licenses/LICENSE +20 -20
- {hamtaa_texttools-1.0.4.dist-info → hamtaa_texttools-1.0.5.dist-info}/top_level.txt +0 -0
- texttools/__init__.py +9 -9
- texttools/batch/__init__.py +4 -4
- texttools/batch/batch_manager.py +240 -240
- texttools/batch/batch_runner.py +212 -212
- texttools/formatters/base_formatter.py +33 -33
- texttools/formatters/{user_merge_formatter/user_merge_formatter.py → user_merge_formatter.py} +30 -30
- texttools/prompts/README.md +31 -31
- texttools/prompts/categorizer.yaml +28 -31
- texttools/prompts/custom_tool.yaml +7 -0
- texttools/prompts/keyword_extractor.yaml +18 -14
- texttools/prompts/ner_extractor.yaml +20 -21
- texttools/prompts/question_detector.yaml +13 -14
- texttools/prompts/question_generator.yaml +19 -22
- texttools/prompts/question_merger.yaml +45 -48
- texttools/prompts/rewriter.yaml +111 -0
- texttools/prompts/subject_question_generator.yaml +22 -26
- texttools/prompts/summarizer.yaml +13 -11
- texttools/prompts/translator.yaml +14 -14
- texttools/tools/__init__.py +4 -4
- texttools/tools/async_the_tool.py +277 -263
- texttools/tools/internals/async_operator.py +297 -288
- texttools/tools/internals/operator.py +295 -306
- texttools/tools/internals/output_models.py +52 -62
- texttools/tools/internals/prompt_loader.py +76 -82
- texttools/tools/the_tool.py +501 -400
- hamtaa_texttools-1.0.4.dist-info/RECORD +0 -29
- texttools/prompts/question_rewriter.yaml +0 -46
- {hamtaa_texttools-1.0.4.dist-info → hamtaa_texttools-1.0.5.dist-info}/WHEEL +0 -0
|
@@ -1,263 +1,277 @@
|
|
|
1
|
-
from typing import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
) -> dict[str, list[str]]:
|
|
64
|
-
results = await self.operator.run(
|
|
65
|
-
text,
|
|
66
|
-
prompt_file="keyword_extractor.yaml",
|
|
67
|
-
output_model=OutputModels.ListStrOutput,
|
|
68
|
-
with_analysis=with_analysis,
|
|
69
|
-
resp_format="parse",
|
|
70
|
-
user_prompt=user_prompt,
|
|
71
|
-
output_lang=output_lang,
|
|
72
|
-
logprobs=logprobs,
|
|
73
|
-
top_logprobs=top_logprobs,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
1
|
+
from typing import Literal
|
|
2
|
+
|
|
3
|
+
from openai import AsyncOpenAI
|
|
4
|
+
|
|
5
|
+
import texttools.tools.internals.output_models as OutputModels
|
|
6
|
+
from texttools.tools.internals.async_operator import AsyncOperator
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AsyncTheTool:
|
|
10
|
+
"""
|
|
11
|
+
Async counterpart to TheTool.
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
async_client = AsyncOpenAI(...)
|
|
15
|
+
tool = TheToolAsync(async_client, model="gemma-3")
|
|
16
|
+
result = await tool.categorize("متن ...", with_analysis=True)
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
client: AsyncOpenAI,
|
|
22
|
+
*,
|
|
23
|
+
model: str,
|
|
24
|
+
temperature: float = 0.0,
|
|
25
|
+
):
|
|
26
|
+
self.operator = AsyncOperator(
|
|
27
|
+
client=client,
|
|
28
|
+
model=model,
|
|
29
|
+
temperature=temperature,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
async def categorize(
|
|
33
|
+
self,
|
|
34
|
+
text: str,
|
|
35
|
+
with_analysis: bool = False,
|
|
36
|
+
user_prompt: str = "",
|
|
37
|
+
logprobs: bool = False,
|
|
38
|
+
top_logprobs: int = 8,
|
|
39
|
+
max_tokens: int | None = None,
|
|
40
|
+
) -> dict[str, str]:
|
|
41
|
+
results = await self.operator.run(
|
|
42
|
+
text,
|
|
43
|
+
prompt_file="categorizer.yaml",
|
|
44
|
+
output_model=OutputModels.CategorizerOutput,
|
|
45
|
+
with_analysis=with_analysis,
|
|
46
|
+
resp_format="parse",
|
|
47
|
+
user_prompt=user_prompt,
|
|
48
|
+
logprobs=logprobs,
|
|
49
|
+
top_logprobs=top_logprobs,
|
|
50
|
+
max_tokens=max_tokens,
|
|
51
|
+
)
|
|
52
|
+
return results
|
|
53
|
+
|
|
54
|
+
async def extract_keywords(
|
|
55
|
+
self,
|
|
56
|
+
text: str,
|
|
57
|
+
output_lang: str | None = None,
|
|
58
|
+
with_analysis: bool = False,
|
|
59
|
+
user_prompt: str = "",
|
|
60
|
+
logprobs: bool = False,
|
|
61
|
+
top_logprobs: int = 3,
|
|
62
|
+
max_tokens: int | None = None,
|
|
63
|
+
) -> dict[str, list[str]]:
|
|
64
|
+
results = await self.operator.run(
|
|
65
|
+
text,
|
|
66
|
+
prompt_file="keyword_extractor.yaml",
|
|
67
|
+
output_model=OutputModels.ListStrOutput,
|
|
68
|
+
with_analysis=with_analysis,
|
|
69
|
+
resp_format="parse",
|
|
70
|
+
user_prompt=user_prompt,
|
|
71
|
+
output_lang=output_lang,
|
|
72
|
+
logprobs=logprobs,
|
|
73
|
+
top_logprobs=top_logprobs,
|
|
74
|
+
max_tokens=max_tokens,
|
|
75
|
+
)
|
|
76
|
+
return results
|
|
77
|
+
|
|
78
|
+
async def extract_entities(
|
|
79
|
+
self,
|
|
80
|
+
text: str,
|
|
81
|
+
output_lang: str | None = None,
|
|
82
|
+
with_analysis: bool = False,
|
|
83
|
+
user_prompt: str = "",
|
|
84
|
+
logprobs: bool = False,
|
|
85
|
+
top_logprobs: int = 3,
|
|
86
|
+
max_tokens: int | None = None,
|
|
87
|
+
) -> dict[str, list[dict[str, str]]]:
|
|
88
|
+
results = await self.operator.run(
|
|
89
|
+
text,
|
|
90
|
+
prompt_file="ner_extractor.yaml",
|
|
91
|
+
output_model=OutputModels.ListDictStrStrOutput,
|
|
92
|
+
with_analysis=with_analysis,
|
|
93
|
+
resp_format="parse",
|
|
94
|
+
user_prompt=user_prompt,
|
|
95
|
+
output_lang=output_lang,
|
|
96
|
+
logprobs=logprobs,
|
|
97
|
+
top_logprobs=top_logprobs,
|
|
98
|
+
max_tokens=max_tokens,
|
|
99
|
+
)
|
|
100
|
+
return results
|
|
101
|
+
|
|
102
|
+
async def detect_question(
|
|
103
|
+
self,
|
|
104
|
+
question: str,
|
|
105
|
+
output_lang: str | None = None,
|
|
106
|
+
with_analysis: bool = False,
|
|
107
|
+
user_prompt: str = "",
|
|
108
|
+
logprobs: bool = False,
|
|
109
|
+
top_logprobs: int = 2,
|
|
110
|
+
max_tokens: int | None = None,
|
|
111
|
+
) -> dict[str, bool]:
|
|
112
|
+
results = await self.operator.run(
|
|
113
|
+
question,
|
|
114
|
+
prompt_file="question_detector.yaml",
|
|
115
|
+
output_model=OutputModels.BoolOutput,
|
|
116
|
+
with_analysis=with_analysis,
|
|
117
|
+
resp_format="parse",
|
|
118
|
+
user_prompt=user_prompt,
|
|
119
|
+
output_lang=output_lang,
|
|
120
|
+
logprobs=logprobs,
|
|
121
|
+
top_logprobs=top_logprobs,
|
|
122
|
+
max_tokens=max_tokens,
|
|
123
|
+
)
|
|
124
|
+
return results
|
|
125
|
+
|
|
126
|
+
async def generate_question_from_text(
|
|
127
|
+
self,
|
|
128
|
+
text: str,
|
|
129
|
+
output_lang: str | None = None,
|
|
130
|
+
with_analysis: bool = False,
|
|
131
|
+
user_prompt: str = "",
|
|
132
|
+
logprobs: bool = False,
|
|
133
|
+
top_logprobs: int = 3,
|
|
134
|
+
max_tokens: int | None = None,
|
|
135
|
+
) -> dict[str, str]:
|
|
136
|
+
results = await self.operator.run(
|
|
137
|
+
text,
|
|
138
|
+
prompt_file="question_generator.yaml",
|
|
139
|
+
output_model=OutputModels.StrOutput,
|
|
140
|
+
with_analysis=with_analysis,
|
|
141
|
+
resp_format="parse",
|
|
142
|
+
user_prompt=user_prompt,
|
|
143
|
+
output_lang=output_lang,
|
|
144
|
+
logprobs=logprobs,
|
|
145
|
+
top_logprobs=top_logprobs,
|
|
146
|
+
max_tokens=max_tokens,
|
|
147
|
+
)
|
|
148
|
+
return results
|
|
149
|
+
|
|
150
|
+
async def merge_questions(
|
|
151
|
+
self,
|
|
152
|
+
questions: list[str],
|
|
153
|
+
output_lang: str | None = None,
|
|
154
|
+
mode: Literal["default", "reason"] = "default",
|
|
155
|
+
with_analysis: bool = False,
|
|
156
|
+
user_prompt: str = "",
|
|
157
|
+
logprobs: bool = False,
|
|
158
|
+
top_logprobs: int = 3,
|
|
159
|
+
max_tokens: int | None = None,
|
|
160
|
+
) -> dict[str, str]:
|
|
161
|
+
question_str = ", ".join(questions)
|
|
162
|
+
results = await self.operator.run(
|
|
163
|
+
question_str,
|
|
164
|
+
prompt_file="question_merger.yaml",
|
|
165
|
+
output_model=OutputModels.StrOutput,
|
|
166
|
+
with_analysis=with_analysis,
|
|
167
|
+
use_modes=True,
|
|
168
|
+
mode=mode,
|
|
169
|
+
resp_format="parse",
|
|
170
|
+
user_prompt=user_prompt,
|
|
171
|
+
output_lang=output_lang,
|
|
172
|
+
logprobs=logprobs,
|
|
173
|
+
top_logprobs=top_logprobs,
|
|
174
|
+
max_tokens=max_tokens,
|
|
175
|
+
)
|
|
176
|
+
return results
|
|
177
|
+
|
|
178
|
+
async def rewrite(
|
|
179
|
+
self,
|
|
180
|
+
question: str,
|
|
181
|
+
output_lang: str | None = None,
|
|
182
|
+
mode: Literal["positive", "negative", "hard_negative"] = "positive",
|
|
183
|
+
with_analysis: bool = False,
|
|
184
|
+
user_prompt: str = "",
|
|
185
|
+
logprobs: bool = False,
|
|
186
|
+
top_logprobs: int = 3,
|
|
187
|
+
max_tokens: int | None = None,
|
|
188
|
+
) -> dict[str, str]:
|
|
189
|
+
results = await self.operator.run(
|
|
190
|
+
question,
|
|
191
|
+
prompt_file="rewriter.yaml",
|
|
192
|
+
output_model=OutputModels.StrOutput,
|
|
193
|
+
with_analysis=with_analysis,
|
|
194
|
+
use_modes=True,
|
|
195
|
+
mode=mode,
|
|
196
|
+
resp_format="parse",
|
|
197
|
+
user_prompt=user_prompt,
|
|
198
|
+
output_lang=output_lang,
|
|
199
|
+
logprobs=logprobs,
|
|
200
|
+
top_logprobs=top_logprobs,
|
|
201
|
+
max_tokens=max_tokens,
|
|
202
|
+
)
|
|
203
|
+
return results
|
|
204
|
+
|
|
205
|
+
async def generate_questions_from_subject(
|
|
206
|
+
self,
|
|
207
|
+
subject: str,
|
|
208
|
+
number_of_questions: int,
|
|
209
|
+
output_lang: str | None = None,
|
|
210
|
+
with_analysis: bool = False,
|
|
211
|
+
user_prompt: str = "",
|
|
212
|
+
logprobs: bool = False,
|
|
213
|
+
top_logprobs: int = 3,
|
|
214
|
+
max_tokens: int | None = None,
|
|
215
|
+
) -> dict[str, list[str]]:
|
|
216
|
+
results = await self.operator.run(
|
|
217
|
+
subject,
|
|
218
|
+
prompt_file="subject_question_generator.yaml",
|
|
219
|
+
output_model=OutputModels.ReasonListStrOutput,
|
|
220
|
+
with_analysis=with_analysis,
|
|
221
|
+
resp_format="parse",
|
|
222
|
+
user_prompt=user_prompt,
|
|
223
|
+
number_of_questions=number_of_questions,
|
|
224
|
+
output_lang=output_lang,
|
|
225
|
+
logprobs=logprobs,
|
|
226
|
+
top_logprobs=top_logprobs,
|
|
227
|
+
max_tokens=max_tokens,
|
|
228
|
+
)
|
|
229
|
+
return results
|
|
230
|
+
|
|
231
|
+
async def summarize(
|
|
232
|
+
self,
|
|
233
|
+
text: str,
|
|
234
|
+
output_lang: str | None = None,
|
|
235
|
+
with_analysis: bool = False,
|
|
236
|
+
user_prompt: str = "",
|
|
237
|
+
logprobs: bool = False,
|
|
238
|
+
top_logprobs: int = 3,
|
|
239
|
+
max_tokens: int | None = None,
|
|
240
|
+
) -> dict[str, str]:
|
|
241
|
+
results = await self.operator.run(
|
|
242
|
+
text,
|
|
243
|
+
prompt_file="summarizer.yaml",
|
|
244
|
+
output_model=OutputModels.StrOutput,
|
|
245
|
+
with_analysis=with_analysis,
|
|
246
|
+
resp_format="parse",
|
|
247
|
+
user_prompt=user_prompt,
|
|
248
|
+
output_lang=output_lang,
|
|
249
|
+
logprobs=logprobs,
|
|
250
|
+
top_logprobs=top_logprobs,
|
|
251
|
+
max_tokens=max_tokens,
|
|
252
|
+
)
|
|
253
|
+
return results
|
|
254
|
+
|
|
255
|
+
async def translate(
|
|
256
|
+
self,
|
|
257
|
+
text: str,
|
|
258
|
+
target_language: str,
|
|
259
|
+
with_analysis: bool = False,
|
|
260
|
+
user_prompt: str = "",
|
|
261
|
+
logprobs: bool = False,
|
|
262
|
+
top_logprobs: int = 3,
|
|
263
|
+
max_tokens: int | None = None,
|
|
264
|
+
) -> dict[str, str]:
|
|
265
|
+
results = await self.operator.run(
|
|
266
|
+
text,
|
|
267
|
+
prompt_file="translator.yaml",
|
|
268
|
+
output_model=OutputModels.StrOutput,
|
|
269
|
+
with_analysis=with_analysis,
|
|
270
|
+
resp_format="parse",
|
|
271
|
+
user_prompt=user_prompt,
|
|
272
|
+
target_language=target_language,
|
|
273
|
+
logprobs=logprobs,
|
|
274
|
+
top_logprobs=top_logprobs,
|
|
275
|
+
max_tokens=max_tokens,
|
|
276
|
+
)
|
|
277
|
+
return results
|