hamtaa-texttools 1.0.6__py3-none-any.whl → 1.0.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hamtaa_texttools-1.0.6.dist-info → hamtaa_texttools-1.0.8.dist-info}/METADATA +13 -22
- hamtaa_texttools-1.0.8.dist-info/RECORD +30 -0
- texttools/tools/async_the_tool.py +246 -140
- texttools/tools/internals/async_operator.py +81 -212
- texttools/tools/internals/base_operator.py +85 -0
- texttools/tools/internals/formatters.py +24 -0
- texttools/tools/internals/operator.py +32 -150
- texttools/tools/internals/prompt_loader.py +3 -12
- texttools/tools/the_tool.py +163 -283
- hamtaa_texttools-1.0.6.dist-info/RECORD +0 -30
- texttools/formatters/base_formatter.py +0 -33
- texttools/formatters/user_merge_formatter.py +0 -30
- {hamtaa_texttools-1.0.6.dist-info → hamtaa_texttools-1.0.8.dist-info}/WHEEL +0 -0
- {hamtaa_texttools-1.0.6.dist-info → hamtaa_texttools-1.0.8.dist-info}/licenses/LICENSE +0 -0
- {hamtaa_texttools-1.0.6.dist-info → hamtaa_texttools-1.0.8.dist-info}/top_level.txt +0 -0
- /texttools/prompts/{ner_extractor.yaml → extract_entities.yaml} +0 -0
- /texttools/prompts/{keyword_extractor.yaml → extract_keywords.yaml} +0 -0
- /texttools/prompts/{question_merger.yaml → merge_questions.yaml} +0 -0
- /texttools/prompts/{rewriter.yaml → rewrite.yaml} +0 -0
- /texttools/prompts/{summarizer.yaml → summarize.yaml} +0 -0
- /texttools/prompts/{translator.yaml → translate.yaml} +0 -0
texttools/tools/the_tool.py
CHANGED
|
@@ -8,466 +8,350 @@ import texttools.tools.internals.output_models as OutputModels
|
|
|
8
8
|
|
|
9
9
|
class TheTool:
|
|
10
10
|
"""
|
|
11
|
-
High-level interface exposing specialized text tools for.
|
|
12
|
-
|
|
13
11
|
Each method configures the operator with a specific YAML prompt,
|
|
14
12
|
output schema, and flags, then delegates execution to `operator.run()`.
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
- categorize: assign a text to one of several Islamic categories.
|
|
18
|
-
- extract_keywords: produce a keyword list from text.
|
|
19
|
-
- extract_entities: simple NER (name/type pairs).
|
|
20
|
-
- is_question: binary check whether input is a question.
|
|
21
|
-
- text_to_question: produce a new question from a text.
|
|
22
|
-
- merge_questions: combine multiple questions (default/reason modes).
|
|
23
|
-
- rewrite: rephrase questions (same meaning/different wording, or vice versa).
|
|
24
|
-
- subject_to_question: generate multiple questions given a subject.
|
|
25
|
-
- summarize: produce a concise summary of a subject.
|
|
26
|
-
- translate: translate text between languages.
|
|
27
|
-
|
|
28
|
-
Usage pattern:
|
|
14
|
+
Usage:
|
|
29
15
|
client = OpenAI(...)
|
|
30
|
-
tool = TheTool(client, model="
|
|
31
|
-
result = tool.categorize("
|
|
16
|
+
tool = TheTool(client, model="model-name")
|
|
17
|
+
result = tool.categorize("text ...", with_analysis=True)
|
|
32
18
|
"""
|
|
33
19
|
|
|
34
20
|
def __init__(
|
|
35
21
|
self,
|
|
36
22
|
client: OpenAI,
|
|
37
|
-
|
|
38
|
-
model: str = "google/gemma-3n-e4b-it",
|
|
39
|
-
user_prompt: str | None = None,
|
|
40
|
-
output_lang: str | None = None,
|
|
41
|
-
with_analysis: bool = False,
|
|
42
|
-
temperature: float = 0.0,
|
|
43
|
-
logprobs: bool = False,
|
|
44
|
-
top_logprobs: int = 3,
|
|
23
|
+
model: str,
|
|
45
24
|
):
|
|
46
|
-
|
|
47
|
-
self.operator = Operator(client=client)
|
|
48
|
-
|
|
49
|
-
# Initialize default values
|
|
50
|
-
self.model = model
|
|
51
|
-
self.user_prompt = user_prompt
|
|
52
|
-
self.output_lang = output_lang
|
|
53
|
-
self.with_analysis = with_analysis
|
|
54
|
-
self.temperature = temperature
|
|
55
|
-
self.logprobs = logprobs
|
|
56
|
-
self.top_logprobs = top_logprobs
|
|
25
|
+
self.operator = Operator(client=client, model=model)
|
|
57
26
|
|
|
58
27
|
def categorize(
|
|
59
28
|
self,
|
|
60
29
|
text: str,
|
|
61
|
-
|
|
30
|
+
with_analysis: bool = False,
|
|
62
31
|
user_prompt: str | None = None,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
temperature: float | None = None,
|
|
66
|
-
logprobs: bool | None = None,
|
|
32
|
+
temperature: float | None = 0.0,
|
|
33
|
+
logprobs: bool = False,
|
|
67
34
|
top_logprobs: int | None = None,
|
|
68
35
|
) -> dict[str, str]:
|
|
69
36
|
"""
|
|
70
37
|
Categorize a text into a single Islamic studies domain category.
|
|
71
38
|
|
|
72
|
-
Args:
|
|
73
|
-
text: Input string to categorize.
|
|
74
|
-
with_analysis: If True, first runs an LLM "analysis" step and
|
|
75
|
-
conditions the main prompt on that analysis.
|
|
76
|
-
|
|
77
39
|
Returns:
|
|
78
|
-
{"result": <category string>}
|
|
79
|
-
Example: {"result": "باورهای دینی"}
|
|
40
|
+
{"result": <category string>} + ("logprobs" and "analysis" if enabled)
|
|
80
41
|
"""
|
|
81
42
|
return self.operator.run(
|
|
43
|
+
# User parameters
|
|
44
|
+
text=text,
|
|
45
|
+
with_analysis=with_analysis,
|
|
46
|
+
user_prompt=user_prompt,
|
|
47
|
+
temperature=temperature,
|
|
48
|
+
logprobs=logprobs,
|
|
49
|
+
top_logprobs=top_logprobs,
|
|
82
50
|
# Internal parameters
|
|
83
51
|
prompt_file="categorizer.yaml",
|
|
84
52
|
output_model=OutputModels.CategorizerOutput,
|
|
85
53
|
resp_format="parse",
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
model=self.model if model is None else model,
|
|
89
|
-
user_prompt=self.user_prompt if user_prompt is None else user_prompt,
|
|
90
|
-
output_lang=self.output_lang if output_lang is None else output_lang,
|
|
91
|
-
with_analysis=self.with_analysis
|
|
92
|
-
if with_analysis is None
|
|
93
|
-
else with_analysis,
|
|
94
|
-
temperature=self.temperature if temperature is None else temperature,
|
|
95
|
-
logprobs=self.logprobs if logprobs is None else logprobs,
|
|
96
|
-
top_logprobs=self.top_logprobs if top_logprobs is None else top_logprobs,
|
|
54
|
+
mode=None,
|
|
55
|
+
output_lang=None,
|
|
97
56
|
)
|
|
98
57
|
|
|
99
58
|
def extract_keywords(
|
|
100
59
|
self,
|
|
101
60
|
text: str,
|
|
102
|
-
|
|
103
|
-
user_prompt: str | None = None,
|
|
61
|
+
with_analysis: bool = False,
|
|
104
62
|
output_lang: str | None = None,
|
|
105
|
-
|
|
106
|
-
temperature: float | None =
|
|
107
|
-
logprobs: bool
|
|
63
|
+
user_prompt: str | None = None,
|
|
64
|
+
temperature: float | None = 0.0,
|
|
65
|
+
logprobs: bool = False,
|
|
108
66
|
top_logprobs: int | None = None,
|
|
109
67
|
) -> dict[str, list[str]]:
|
|
110
68
|
"""
|
|
111
69
|
Extract salient keywords from text.
|
|
112
70
|
|
|
113
|
-
Args:
|
|
114
|
-
text: Input string to analyze.
|
|
115
|
-
with_analysis: Whether to run an extra LLM reasoning step.
|
|
116
|
-
|
|
117
71
|
Returns:
|
|
118
|
-
{"result": [<keyword1>, <keyword2>, ...]}
|
|
72
|
+
{"result": [<keyword1>, <keyword2>, ...]} + ("logprobs" and "analysis" if enabled)
|
|
119
73
|
"""
|
|
120
74
|
return self.operator.run(
|
|
75
|
+
# User parameters
|
|
76
|
+
text=text,
|
|
77
|
+
with_analysis=with_analysis,
|
|
78
|
+
output_lang=output_lang,
|
|
79
|
+
user_prompt=user_prompt,
|
|
80
|
+
temperature=temperature,
|
|
81
|
+
logprobs=logprobs,
|
|
82
|
+
top_logprobs=top_logprobs,
|
|
121
83
|
# Internal parameters
|
|
122
|
-
prompt_file="
|
|
84
|
+
prompt_file="extract_keywords.yaml",
|
|
123
85
|
output_model=OutputModels.ListStrOutput,
|
|
124
86
|
resp_format="parse",
|
|
125
|
-
|
|
126
|
-
text=text,
|
|
127
|
-
model=self.model if model is None else model,
|
|
128
|
-
user_prompt=self.user_prompt if user_prompt is None else user_prompt,
|
|
129
|
-
output_lang=self.output_lang if output_lang is None else output_lang,
|
|
130
|
-
with_analysis=self.with_analysis
|
|
131
|
-
if with_analysis is None
|
|
132
|
-
else with_analysis,
|
|
133
|
-
temperature=self.temperature if temperature is None else temperature,
|
|
134
|
-
logprobs=self.logprobs if logprobs is None else logprobs,
|
|
135
|
-
top_logprobs=self.top_logprobs if top_logprobs is None else top_logprobs,
|
|
87
|
+
mode=None,
|
|
136
88
|
)
|
|
137
89
|
|
|
138
90
|
def extract_entities(
|
|
139
91
|
self,
|
|
140
92
|
text: str,
|
|
141
|
-
|
|
142
|
-
user_prompt: str | None = None,
|
|
93
|
+
with_analysis: bool = False,
|
|
143
94
|
output_lang: str | None = None,
|
|
144
|
-
|
|
145
|
-
temperature: float | None =
|
|
146
|
-
logprobs: bool
|
|
95
|
+
user_prompt: str | None = None,
|
|
96
|
+
temperature: float | None = 0.0,
|
|
97
|
+
logprobs: bool = False,
|
|
147
98
|
top_logprobs: int | None = None,
|
|
148
99
|
) -> dict[str, list[dict[str, str]]]:
|
|
149
100
|
"""
|
|
150
101
|
Perform Named Entity Recognition (NER) over the input text.
|
|
151
102
|
|
|
152
|
-
Args:
|
|
153
|
-
text: Input string.
|
|
154
|
-
with_analysis: Whether to run an extra LLM reasoning step.
|
|
155
|
-
|
|
156
103
|
Returns:
|
|
157
|
-
{"result": [{"text": <entity>, "type": <entity_type>}, ...]}
|
|
104
|
+
{"result": [{"text": <entity>, "type": <entity_type>}, ...]} + ("logprobs" and "analysis" if enabled)
|
|
158
105
|
"""
|
|
159
106
|
return self.operator.run(
|
|
107
|
+
# User parameters
|
|
108
|
+
text=text,
|
|
109
|
+
with_analysis=with_analysis,
|
|
110
|
+
output_lang=output_lang,
|
|
111
|
+
user_prompt=user_prompt,
|
|
112
|
+
temperature=temperature,
|
|
113
|
+
logprobs=logprobs,
|
|
114
|
+
top_logprobs=top_logprobs,
|
|
160
115
|
# Internal parameters
|
|
161
|
-
prompt_file="
|
|
116
|
+
prompt_file="extract_entities.yaml",
|
|
162
117
|
output_model=OutputModels.ListDictStrStrOutput,
|
|
163
118
|
resp_format="parse",
|
|
164
|
-
|
|
165
|
-
text=text,
|
|
166
|
-
model=self.model if model is None else model,
|
|
167
|
-
user_prompt=self.user_prompt if user_prompt is None else user_prompt,
|
|
168
|
-
output_lang=self.output_lang if output_lang is None else output_lang,
|
|
169
|
-
with_analysis=self.with_analysis
|
|
170
|
-
if with_analysis is None
|
|
171
|
-
else with_analysis,
|
|
172
|
-
temperature=self.temperature if temperature is None else temperature,
|
|
173
|
-
logprobs=self.logprobs if logprobs is None else logprobs,
|
|
174
|
-
top_logprobs=self.top_logprobs if top_logprobs is None else top_logprobs,
|
|
119
|
+
mode=None,
|
|
175
120
|
)
|
|
176
121
|
|
|
177
122
|
def is_question(
|
|
178
123
|
self,
|
|
179
124
|
text: str,
|
|
180
|
-
|
|
125
|
+
with_analysis: bool = False,
|
|
181
126
|
user_prompt: str | None = None,
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
logprobs: bool | None = None,
|
|
127
|
+
temperature: float | None = 0.0,
|
|
128
|
+
logprobs: bool = False,
|
|
185
129
|
top_logprobs: int | None = None,
|
|
186
130
|
) -> dict[str, bool]:
|
|
187
131
|
"""
|
|
188
132
|
Detect if the input is phrased as a question.
|
|
189
133
|
|
|
190
|
-
Args:
|
|
191
|
-
question: Input string to evaluate.
|
|
192
|
-
with_analysis: Whether to include an analysis step.
|
|
193
|
-
|
|
194
134
|
Returns:
|
|
195
|
-
{"result":
|
|
135
|
+
{"result": True} or {"result": False} + ("logprobs" and "analysis" if enabled)
|
|
196
136
|
"""
|
|
197
137
|
return self.operator.run(
|
|
138
|
+
# User parameters
|
|
139
|
+
text=text,
|
|
140
|
+
with_analysis=with_analysis,
|
|
141
|
+
user_prompt=user_prompt,
|
|
142
|
+
temperature=temperature,
|
|
143
|
+
logprobs=logprobs,
|
|
144
|
+
top_logprobs=top_logprobs,
|
|
198
145
|
# Internal parameters
|
|
199
146
|
prompt_file="is_question.yaml",
|
|
200
147
|
output_model=OutputModels.BoolOutput,
|
|
201
148
|
resp_format="parse",
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
text=text,
|
|
205
|
-
model=self.model if model is None else model,
|
|
206
|
-
user_prompt=self.user_prompt if user_prompt is None else user_prompt,
|
|
207
|
-
with_analysis=self.with_analysis
|
|
208
|
-
if with_analysis is None
|
|
209
|
-
else with_analysis,
|
|
210
|
-
temperature=self.temperature if temperature is None else temperature,
|
|
211
|
-
logprobs=self.logprobs if logprobs is None else logprobs,
|
|
212
|
-
top_logprobs=self.top_logprobs if top_logprobs is None else top_logprobs,
|
|
149
|
+
mode=None,
|
|
150
|
+
output_lang=None,
|
|
213
151
|
)
|
|
214
152
|
|
|
215
153
|
def text_to_question(
|
|
216
154
|
self,
|
|
217
155
|
text: str,
|
|
218
|
-
|
|
219
|
-
user_prompt: str | None = None,
|
|
156
|
+
with_analysis: bool = False,
|
|
220
157
|
output_lang: str | None = None,
|
|
221
|
-
|
|
222
|
-
temperature: float | None =
|
|
223
|
-
logprobs: bool
|
|
158
|
+
user_prompt: str | None = None,
|
|
159
|
+
temperature: float | None = 0.0,
|
|
160
|
+
logprobs: bool = False,
|
|
224
161
|
top_logprobs: int | None = None,
|
|
225
162
|
) -> dict[str, str]:
|
|
226
163
|
"""
|
|
227
164
|
Generate a single question from the given text.
|
|
228
165
|
|
|
229
|
-
Args:
|
|
230
|
-
text: Source text to derive a question from.
|
|
231
|
-
with_analysis: Whether to use analysis before generation.
|
|
232
|
-
|
|
233
166
|
Returns:
|
|
234
|
-
{"result": <generated_question>}
|
|
167
|
+
{"result": <generated_question>} + ("logprobs" and "analysis" if enabled)
|
|
235
168
|
"""
|
|
236
169
|
return self.operator.run(
|
|
170
|
+
# User parameters
|
|
171
|
+
text=text,
|
|
172
|
+
with_analysis=with_analysis,
|
|
173
|
+
output_lang=output_lang,
|
|
174
|
+
user_prompt=user_prompt,
|
|
175
|
+
temperature=temperature,
|
|
176
|
+
logprobs=logprobs,
|
|
177
|
+
top_logprobs=top_logprobs,
|
|
237
178
|
# Internal parameters
|
|
238
179
|
prompt_file="text_to_question.yaml",
|
|
239
180
|
output_model=OutputModels.StrOutput,
|
|
240
181
|
resp_format="parse",
|
|
241
|
-
|
|
242
|
-
text=text,
|
|
243
|
-
model=self.model if model is None else model,
|
|
244
|
-
user_prompt=self.user_prompt if user_prompt is None else user_prompt,
|
|
245
|
-
output_lang=self.output_lang if output_lang is None else output_lang,
|
|
246
|
-
with_analysis=self.with_analysis
|
|
247
|
-
if with_analysis is None
|
|
248
|
-
else with_analysis,
|
|
249
|
-
temperature=self.temperature if temperature is None else temperature,
|
|
250
|
-
logprobs=self.logprobs if logprobs is None else logprobs,
|
|
251
|
-
top_logprobs=self.top_logprobs if top_logprobs is None else top_logprobs,
|
|
182
|
+
mode=None,
|
|
252
183
|
)
|
|
253
184
|
|
|
254
185
|
def merge_questions(
|
|
255
186
|
self,
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
model: str | None = None,
|
|
259
|
-
user_prompt: str | None = None,
|
|
187
|
+
text: list[str],
|
|
188
|
+
with_analysis: bool = False,
|
|
260
189
|
output_lang: str | None = None,
|
|
261
|
-
|
|
262
|
-
temperature: float | None =
|
|
263
|
-
logprobs: bool
|
|
190
|
+
user_prompt: str | None = None,
|
|
191
|
+
temperature: float | None = 0.0,
|
|
192
|
+
logprobs: bool = False,
|
|
264
193
|
top_logprobs: int | None = None,
|
|
194
|
+
mode: Literal["default", "reason"] = "default",
|
|
265
195
|
) -> dict[str, str]:
|
|
266
196
|
"""
|
|
267
197
|
Merge multiple questions into a single unified question.
|
|
268
198
|
|
|
269
|
-
Args:
|
|
270
|
-
questions: List of question strings.
|
|
271
|
-
mode: Merge strategy:
|
|
272
|
-
- "default": simple merging.
|
|
273
|
-
- "reason": merging with reasoning explanation.
|
|
274
|
-
with_analysis: Whether to use an analysis step.
|
|
275
|
-
|
|
276
199
|
Returns:
|
|
277
|
-
{"result": <merged_question>}
|
|
200
|
+
{"result": <merged_question>} + ("logprobs" and "analysis" if enabled)
|
|
278
201
|
"""
|
|
279
|
-
text = ", ".join(
|
|
202
|
+
text = ", ".join(text)
|
|
280
203
|
return self.operator.run(
|
|
204
|
+
# User parameters
|
|
205
|
+
text=text,
|
|
206
|
+
with_analysis=with_analysis,
|
|
207
|
+
output_lang=output_lang,
|
|
208
|
+
user_prompt=user_prompt,
|
|
209
|
+
temperature=temperature,
|
|
210
|
+
logprobs=logprobs,
|
|
211
|
+
top_logprobs=top_logprobs,
|
|
281
212
|
# Internal parameters
|
|
282
|
-
prompt_file="
|
|
213
|
+
prompt_file="merge_questions.yaml",
|
|
283
214
|
output_model=OutputModels.StrOutput,
|
|
284
215
|
resp_format="parse",
|
|
285
|
-
# User parameters
|
|
286
|
-
text=text,
|
|
287
216
|
mode=mode,
|
|
288
|
-
model=self.model if model is None else model,
|
|
289
|
-
user_prompt=self.user_prompt if user_prompt is None else user_prompt,
|
|
290
|
-
output_lang=self.output_lang if output_lang is None else output_lang,
|
|
291
|
-
with_analysis=self.with_analysis
|
|
292
|
-
if with_analysis is None
|
|
293
|
-
else with_analysis,
|
|
294
|
-
temperature=self.temperature if temperature is None else temperature,
|
|
295
|
-
logprobs=self.logprobs if logprobs is None else logprobs,
|
|
296
|
-
top_logprobs=self.top_logprobs if top_logprobs is None else top_logprobs,
|
|
297
217
|
)
|
|
298
218
|
|
|
299
219
|
def rewrite(
|
|
300
220
|
self,
|
|
301
221
|
text: str,
|
|
302
|
-
|
|
303
|
-
model: str | None = None,
|
|
304
|
-
user_prompt: str | None = None,
|
|
222
|
+
with_analysis: bool = False,
|
|
305
223
|
output_lang: str | None = None,
|
|
306
|
-
|
|
307
|
-
temperature: float | None =
|
|
308
|
-
logprobs: bool
|
|
224
|
+
user_prompt: str | None = None,
|
|
225
|
+
temperature: float | None = 0.0,
|
|
226
|
+
logprobs: bool = False,
|
|
309
227
|
top_logprobs: int | None = None,
|
|
228
|
+
mode: Literal["positive", "negative", "hard_negative"] = "positive",
|
|
310
229
|
) -> dict[str, str]:
|
|
311
230
|
"""
|
|
312
|
-
Rewrite a
|
|
313
|
-
|
|
314
|
-
Args:
|
|
315
|
-
question: Input question to rewrite.
|
|
316
|
-
mode: Rewrite strategy:
|
|
317
|
-
- "positive": keep meaning, change words.
|
|
318
|
-
- "negative": alter meaning, preserve wording style.
|
|
319
|
-
with_analysis: Whether to include an analysis step.
|
|
231
|
+
Rewrite a text with different modes.
|
|
320
232
|
|
|
321
233
|
Returns:
|
|
322
|
-
{"result": <
|
|
234
|
+
{"result": <rewritten_text>} + ("logprobs" and "analysis" if enabled)
|
|
323
235
|
"""
|
|
324
236
|
return self.operator.run(
|
|
237
|
+
# User parameters
|
|
238
|
+
text=text,
|
|
239
|
+
with_analysis=with_analysis,
|
|
240
|
+
output_lang=output_lang,
|
|
241
|
+
user_prompt=user_prompt,
|
|
242
|
+
temperature=temperature,
|
|
243
|
+
logprobs=logprobs,
|
|
244
|
+
top_logprobs=top_logprobs,
|
|
325
245
|
# Internal parameters
|
|
326
|
-
prompt_file="
|
|
246
|
+
prompt_file="rewrite.yaml",
|
|
327
247
|
output_model=OutputModels.StrOutput,
|
|
328
248
|
resp_format="parse",
|
|
329
|
-
# User parameters
|
|
330
|
-
text=text,
|
|
331
249
|
mode=mode,
|
|
332
|
-
model=self.model if model is None else model,
|
|
333
|
-
user_prompt=self.user_prompt if user_prompt is None else user_prompt,
|
|
334
|
-
output_lang=self.output_lang if output_lang is None else output_lang,
|
|
335
|
-
with_analysis=self.with_analysis
|
|
336
|
-
if with_analysis is None
|
|
337
|
-
else with_analysis,
|
|
338
|
-
temperature=self.temperature if temperature is None else temperature,
|
|
339
|
-
logprobs=self.logprobs if logprobs is None else logprobs,
|
|
340
|
-
top_logprobs=self.top_logprobs if top_logprobs is None else top_logprobs,
|
|
341
250
|
)
|
|
342
251
|
|
|
343
252
|
def subject_to_question(
|
|
344
253
|
self,
|
|
345
254
|
text: str,
|
|
346
255
|
number_of_questions: int,
|
|
347
|
-
|
|
348
|
-
user_prompt: str | None = None,
|
|
256
|
+
with_analysis: bool = False,
|
|
349
257
|
output_lang: str | None = None,
|
|
350
|
-
|
|
351
|
-
temperature: float | None =
|
|
352
|
-
logprobs: bool
|
|
258
|
+
user_prompt: str | None = None,
|
|
259
|
+
temperature: float | None = 0.0,
|
|
260
|
+
logprobs: bool = False,
|
|
353
261
|
top_logprobs: int | None = None,
|
|
354
262
|
) -> dict[str, list[str]]:
|
|
355
263
|
"""
|
|
356
264
|
Generate a list of questions about a subject.
|
|
357
265
|
|
|
358
|
-
Args:
|
|
359
|
-
subject: Topic of interest.
|
|
360
|
-
number_of_questions: Number of questions to produce.
|
|
361
|
-
language: Target language for generated questions.
|
|
362
|
-
with_analysis: Whether to include an analysis step.
|
|
363
|
-
|
|
364
266
|
Returns:
|
|
365
|
-
{"result": [<question1>, <question2>, ...]}
|
|
267
|
+
{"result": [<question1>, <question2>, ...]} + ("logprobs" and "analysis" if enabled)
|
|
366
268
|
"""
|
|
367
269
|
return self.operator.run(
|
|
270
|
+
# User parameters
|
|
271
|
+
text=text,
|
|
272
|
+
number_of_questions=number_of_questions,
|
|
273
|
+
with_analysis=with_analysis,
|
|
274
|
+
output_lang=output_lang,
|
|
275
|
+
user_prompt=user_prompt,
|
|
276
|
+
temperature=temperature,
|
|
277
|
+
logprobs=logprobs,
|
|
278
|
+
top_logprobs=top_logprobs,
|
|
368
279
|
# Internal parameters
|
|
369
280
|
prompt_file="subject_to_question.yaml",
|
|
370
281
|
output_model=OutputModels.ReasonListStrOutput,
|
|
371
282
|
resp_format="parse",
|
|
372
|
-
|
|
373
|
-
text=text,
|
|
374
|
-
number_of_questions=number_of_questions,
|
|
375
|
-
model=self.model if model is None else model,
|
|
376
|
-
user_prompt=self.user_prompt if user_prompt is None else user_prompt,
|
|
377
|
-
output_lang=self.output_lang if output_lang is None else output_lang,
|
|
378
|
-
with_analysis=self.with_analysis
|
|
379
|
-
if with_analysis is None
|
|
380
|
-
else with_analysis,
|
|
381
|
-
temperature=self.temperature if temperature is None else temperature,
|
|
382
|
-
logprobs=self.logprobs if logprobs is None else logprobs,
|
|
383
|
-
top_logprobs=self.top_logprobs if top_logprobs is None else top_logprobs,
|
|
283
|
+
mode=None,
|
|
384
284
|
)
|
|
385
285
|
|
|
386
286
|
def summarize(
|
|
387
287
|
self,
|
|
388
288
|
text: str,
|
|
389
|
-
|
|
390
|
-
user_prompt: str | None = None,
|
|
289
|
+
with_analysis: bool = False,
|
|
391
290
|
output_lang: str | None = None,
|
|
392
|
-
|
|
393
|
-
temperature: float | None =
|
|
394
|
-
logprobs: bool
|
|
291
|
+
user_prompt: str | None = None,
|
|
292
|
+
temperature: float | None = 0.0,
|
|
293
|
+
logprobs: bool = False,
|
|
395
294
|
top_logprobs: int | None = None,
|
|
396
295
|
) -> dict[str, str]:
|
|
397
296
|
"""
|
|
398
297
|
Summarize the given subject text.
|
|
399
298
|
|
|
400
|
-
Args:
|
|
401
|
-
subject: Input text to summarize.
|
|
402
|
-
with_analysis: Whether to include an analysis step.
|
|
403
|
-
|
|
404
299
|
Returns:
|
|
405
|
-
{"result": <summary>}
|
|
300
|
+
{"result": <summary>} + ("logprobs" and "analysis" if enabled)
|
|
406
301
|
"""
|
|
407
302
|
return self.operator.run(
|
|
303
|
+
# User parameters
|
|
304
|
+
text=text,
|
|
305
|
+
with_analysis=with_analysis,
|
|
306
|
+
output_lang=output_lang,
|
|
307
|
+
user_prompt=user_prompt,
|
|
308
|
+
temperature=temperature,
|
|
309
|
+
logprobs=logprobs,
|
|
310
|
+
top_logprobs=top_logprobs,
|
|
408
311
|
# Internal parameters
|
|
409
|
-
prompt_file="
|
|
312
|
+
prompt_file="summarize.yaml",
|
|
410
313
|
output_model=OutputModels.StrOutput,
|
|
411
314
|
resp_format="parse",
|
|
412
|
-
|
|
413
|
-
text=text,
|
|
414
|
-
model=self.model if model is None else model,
|
|
415
|
-
user_prompt=self.user_prompt if user_prompt is None else user_prompt,
|
|
416
|
-
output_lang=self.output_lang if output_lang is None else output_lang,
|
|
417
|
-
with_analysis=self.with_analysis
|
|
418
|
-
if with_analysis is None
|
|
419
|
-
else with_analysis,
|
|
420
|
-
temperature=self.temperature if temperature is None else temperature,
|
|
421
|
-
logprobs=self.logprobs if logprobs is None else logprobs,
|
|
422
|
-
top_logprobs=self.top_logprobs if top_logprobs is None else top_logprobs,
|
|
315
|
+
mode=None,
|
|
423
316
|
)
|
|
424
317
|
|
|
425
318
|
def translate(
|
|
426
319
|
self,
|
|
427
320
|
text: str,
|
|
428
321
|
target_language: str,
|
|
429
|
-
|
|
322
|
+
with_analysis: bool = False,
|
|
430
323
|
user_prompt: str | None = None,
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
logprobs: bool | None = None,
|
|
324
|
+
temperature: float | None = 0.0,
|
|
325
|
+
logprobs: bool = False,
|
|
434
326
|
top_logprobs: int | None = None,
|
|
435
327
|
) -> dict[str, str]:
|
|
436
328
|
"""
|
|
437
329
|
Translate text between languages.
|
|
438
330
|
|
|
439
|
-
Args:
|
|
440
|
-
text: Input string to translate.
|
|
441
|
-
target_language: Language code or name to translate into.
|
|
442
|
-
with_analysis: Whether to include an analysis step.
|
|
443
|
-
|
|
444
331
|
Returns:
|
|
445
|
-
{"result": <translated_text>}
|
|
332
|
+
{"result": <translated_text>} + ("logprobs" and "analysis" if enabled)
|
|
446
333
|
"""
|
|
447
334
|
return self.operator.run(
|
|
448
|
-
# Internal parameters
|
|
449
|
-
prompt_file="translator.yaml",
|
|
450
|
-
output_model=OutputModels.StrOutput,
|
|
451
|
-
resp_format="parse",
|
|
452
|
-
output_lang=False,
|
|
453
335
|
# User parameters
|
|
454
336
|
text=text,
|
|
455
337
|
target_language=target_language,
|
|
456
|
-
|
|
457
|
-
user_prompt=
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
338
|
+
with_analysis=with_analysis,
|
|
339
|
+
user_prompt=user_prompt,
|
|
340
|
+
temperature=temperature,
|
|
341
|
+
logprobs=logprobs,
|
|
342
|
+
top_logprobs=top_logprobs,
|
|
343
|
+
# Internal parameters
|
|
344
|
+
prompt_file="translate.yaml",
|
|
345
|
+
output_model=OutputModels.StrOutput,
|
|
346
|
+
resp_format="parse",
|
|
347
|
+
mode=None,
|
|
348
|
+
output_lang=None,
|
|
464
349
|
)
|
|
465
350
|
|
|
466
351
|
def run_custom(
|
|
467
352
|
self,
|
|
468
353
|
prompt: str,
|
|
469
354
|
output_model: Any,
|
|
470
|
-
model: str | None = None,
|
|
471
355
|
output_lang: str | None = None,
|
|
472
356
|
temperature: float | None = None,
|
|
473
357
|
logprobs: bool | None = None,
|
|
@@ -476,26 +360,22 @@ class TheTool:
|
|
|
476
360
|
"""
|
|
477
361
|
Custom tool that can do almost anything!
|
|
478
362
|
|
|
479
|
-
Args:
|
|
480
|
-
prompt: Custom prompt.
|
|
481
|
-
output_model: Custom BaseModel output model.
|
|
482
|
-
|
|
483
363
|
Returns:
|
|
484
364
|
{"result": <Any>}
|
|
485
365
|
"""
|
|
486
366
|
return self.operator.run(
|
|
487
|
-
# Internal parameters
|
|
488
|
-
prompt_file="run_custom.yaml",
|
|
489
|
-
resp_format="parse",
|
|
490
|
-
user_prompt=False,
|
|
491
|
-
with_analysis=False,
|
|
492
367
|
# User paramaeters
|
|
493
368
|
text=prompt,
|
|
494
369
|
output_model=output_model,
|
|
495
370
|
output_model_str=output_model.model_json_schema(),
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
371
|
+
output_lang=output_lang,
|
|
372
|
+
temperature=temperature,
|
|
373
|
+
logprobs=logprobs,
|
|
374
|
+
top_logprobs=top_logprobs,
|
|
375
|
+
# Internal parameters
|
|
376
|
+
prompt_file="run_custom.yaml",
|
|
377
|
+
resp_format="parse",
|
|
378
|
+
user_prompt=None,
|
|
379
|
+
with_analysis=False,
|
|
380
|
+
mode=None,
|
|
501
381
|
)
|