hamtaa-texttools 1.1.1__py3-none-any.whl → 1.1.16__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.
Files changed (30) hide show
  1. {hamtaa_texttools-1.1.1.dist-info → hamtaa_texttools-1.1.16.dist-info}/METADATA +98 -26
  2. hamtaa_texttools-1.1.16.dist-info/RECORD +31 -0
  3. texttools/__init__.py +6 -8
  4. texttools/batch/batch_config.py +26 -0
  5. texttools/batch/batch_runner.py +105 -151
  6. texttools/batch/{batch_manager.py → internals/batch_manager.py} +39 -40
  7. texttools/batch/internals/utils.py +16 -0
  8. texttools/prompts/README.md +4 -4
  9. texttools/prompts/categorize.yaml +77 -0
  10. texttools/prompts/detect_entity.yaml +22 -0
  11. texttools/prompts/extract_keywords.yaml +68 -18
  12. texttools/tools/async_tools.py +804 -0
  13. texttools/tools/internals/async_operator.py +90 -69
  14. texttools/tools/internals/models.py +183 -0
  15. texttools/tools/internals/operator_utils.py +54 -0
  16. texttools/tools/internals/prompt_loader.py +13 -14
  17. texttools/tools/internals/sync_operator.py +201 -0
  18. texttools/tools/sync_tools.py +804 -0
  19. hamtaa_texttools-1.1.1.dist-info/RECORD +0 -30
  20. texttools/batch/__init__.py +0 -4
  21. texttools/prompts/categorizer.yaml +0 -28
  22. texttools/tools/__init__.py +0 -4
  23. texttools/tools/async_the_tool.py +0 -414
  24. texttools/tools/internals/base_operator.py +0 -91
  25. texttools/tools/internals/operator.py +0 -179
  26. texttools/tools/internals/output_models.py +0 -59
  27. texttools/tools/the_tool.py +0 -412
  28. {hamtaa_texttools-1.1.1.dist-info → hamtaa_texttools-1.1.16.dist-info}/WHEEL +0 -0
  29. {hamtaa_texttools-1.1.1.dist-info → hamtaa_texttools-1.1.16.dist-info}/licenses/LICENSE +0 -0
  30. {hamtaa_texttools-1.1.1.dist-info → hamtaa_texttools-1.1.16.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,804 @@
1
+ from datetime import datetime
2
+ from typing import Literal, Any
3
+ from collections.abc import Callable
4
+
5
+ from openai import AsyncOpenAI
6
+
7
+ from texttools.tools.internals.async_operator import AsyncOperator
8
+ import texttools.tools.internals.models as Models
9
+
10
+
11
+ class AsyncTheTool:
12
+ """
13
+ Async counterpart to TheTool.
14
+
15
+ Each method configures the async operator with a specific YAML prompt,
16
+ output schema, and flags, then delegates execution to `operator.run()`.
17
+
18
+ Usage:
19
+ async_client = AsyncOpenAI(...)
20
+ tool = TheToolAsync(async_client, model="model-name")
21
+ result = await tool.categorize("text ...", with_analysis=True)
22
+ """
23
+
24
+ def __init__(
25
+ self,
26
+ client: AsyncOpenAI,
27
+ model: str,
28
+ ):
29
+ self._operator = AsyncOperator(client=client, model=model)
30
+
31
+ async def categorize(
32
+ self,
33
+ text: str,
34
+ categories: list[str] | Models.CategoryTree,
35
+ with_analysis: bool = False,
36
+ user_prompt: str | None = None,
37
+ temperature: float | None = 0.0,
38
+ logprobs: bool = False,
39
+ top_logprobs: int | None = None,
40
+ mode: Literal["category_list", "category_tree"] = "category_list",
41
+ validator: Callable[[Any], bool] | None = None,
42
+ max_validation_retries: int | None = None,
43
+ priority: int | None = 0,
44
+ ) -> Models.ToolOutput:
45
+ """
46
+ Categorize a text into a category / category tree.
47
+
48
+ Arguments:
49
+ text: The input text to categorize
50
+ categories: The category / category_tree to give to LLM
51
+ with_analysis: Whether to include detailed reasoning analysis
52
+ user_prompt: Additional instructions for the categorization
53
+ temperature: Controls randomness (0.0 = deterministic, 1.0 = creative)
54
+ logprobs: Whether to return token probability information
55
+ top_logprobs: Number of top token alternatives to return if logprobs enabled
56
+ validator: Custom validation function to validate the output
57
+ max_validation_retries: Maximum number of retry attempts if validation fails
58
+ priority: Task execution priority (if enabled by vLLM and model)
59
+
60
+ Returns:
61
+ ToolOutput: Object containing:
62
+ - result (str): The assigned category
63
+ - logprobs (list | None): Probability data if logprobs enabled
64
+ - analysis (str | None): Detailed reasoning if with_analysis enabled
65
+ - errors (list(str) | None): Errors occured during tool call
66
+ """
67
+ start = datetime.now()
68
+
69
+ if mode == "category_tree":
70
+ # Initializations
71
+ output = Models.ToolOutput()
72
+ levels = categories.get_level_count()
73
+ parent_id = 0
74
+ final_output = []
75
+
76
+ for _ in range(levels):
77
+ # Get child nodes for current parent
78
+ parent_node = categories.find_node(parent_id)
79
+ children = categories.find_children(parent_node)
80
+
81
+ # Check if child nodes exist
82
+ if not children:
83
+ output.errors.append(
84
+ f"No categories found for parent_id {parent_id} in the tree"
85
+ )
86
+ end = datetime.now()
87
+ output.execution_time = (end - start).total_seconds()
88
+ return output
89
+
90
+ # Extract category names and descriptions
91
+ category_list = [
92
+ f"Category Name: {node.name}, Description: {node.description}"
93
+ for node in children
94
+ ]
95
+ category_names = [node.name for node in children]
96
+
97
+ # Run categorization for this level
98
+ level_output = await self._operator.run(
99
+ # User parameters
100
+ text=text,
101
+ category_list=category_list,
102
+ with_analysis=with_analysis,
103
+ user_prompt=user_prompt,
104
+ temperature=temperature,
105
+ logprobs=logprobs,
106
+ top_logprobs=top_logprobs,
107
+ mode=mode,
108
+ validator=validator,
109
+ max_validation_retries=max_validation_retries,
110
+ # Internal parameters
111
+ prompt_file="categorize.yaml",
112
+ output_model=Models.create_dynamic_model(category_names),
113
+ output_lang=None,
114
+ )
115
+
116
+ # Check for errors from operator
117
+ if level_output.errors:
118
+ output.errors.extend(level_output.errors)
119
+ end = datetime.now()
120
+ output.execution_time = (end - start).total_seconds()
121
+ return output
122
+
123
+ # Get the chosen category
124
+ chosen_category = level_output.result
125
+
126
+ # Find the corresponding node
127
+ parent_node = categories.find_node(chosen_category)
128
+ if parent_node is None:
129
+ output.errors.append(
130
+ f"Category '{chosen_category}' not found in tree after selection"
131
+ )
132
+ end = datetime.now()
133
+ output.execution_time = (end - start).total_seconds()
134
+ return output
135
+
136
+ parent_id = parent_node.node_id
137
+ final_output.append(parent_node.name)
138
+
139
+ # Copy analysis/logprobs/process from the last level's output
140
+ output.analysis = level_output.analysis
141
+ output.logprobs = level_output.logprobs
142
+ output.process = level_output.process
143
+
144
+ output.result = final_output
145
+ end = datetime.now()
146
+ output.execution_time = (end - start).total_seconds()
147
+ return output
148
+
149
+ else:
150
+ output = await self._operator.run(
151
+ # User parameters
152
+ text=text,
153
+ category_list=categories,
154
+ with_analysis=with_analysis,
155
+ user_prompt=user_prompt,
156
+ temperature=temperature,
157
+ logprobs=logprobs,
158
+ top_logprobs=top_logprobs,
159
+ mode=mode,
160
+ validator=validator,
161
+ max_validation_retries=max_validation_retries,
162
+ # Internal parameters
163
+ prompt_file="categorize.yaml",
164
+ output_model=Models.create_dynamic_model(categories),
165
+ output_lang=None,
166
+ )
167
+ end = datetime.now()
168
+ output.execution_time = (end - start).total_seconds()
169
+ return output
170
+
171
+ async def extract_keywords(
172
+ self,
173
+ text: str,
174
+ with_analysis: bool = False,
175
+ output_lang: str | None = None,
176
+ user_prompt: str | None = None,
177
+ temperature: float | None = 0.0,
178
+ logprobs: bool = False,
179
+ top_logprobs: int | None = None,
180
+ mode: Literal["auto", "threshold", "count"] = "auto",
181
+ number_of_keywords: int | None = None,
182
+ validator: Callable[[Any], bool] | None = None,
183
+ max_validation_retries: int | None = None,
184
+ priority: int | None = 0,
185
+ ) -> Models.ToolOutput:
186
+ """
187
+ Extract salient keywords from text.
188
+
189
+ Arguments:
190
+ text: The input text to extract keywords from
191
+ with_analysis: Whether to include detailed reasoning analysis
192
+ output_lang: Language for the output response
193
+ user_prompt: Additional instructions for keyword extraction
194
+ temperature: Controls randomness (0.0 = deterministic, 1.0 = creative)
195
+ logprobs: Whether to return token probability information
196
+ top_logprobs: Number of top token alternatives to return if logprobs enabled
197
+ validator: Custom validation function to validate the output
198
+ max_validation_retries: Maximum number of retry attempts if validation fails
199
+ priority: Task execution priority (if enabled by vLLM and model)
200
+
201
+ Returns:
202
+ ToolOutput: Object containing:
203
+ - result (list[str]): List of extracted keywords
204
+ - logprobs (list | None): Probability data if logprobs enabled
205
+ - analysis (str | None): Detailed reasoning if with_analysis enabled
206
+ - errors (list(str) | None): Errors occured during tool call
207
+ """
208
+ start = datetime.now()
209
+ output = await self._operator.run(
210
+ # User parameters
211
+ text=text,
212
+ with_analysis=with_analysis,
213
+ output_lang=output_lang,
214
+ user_prompt=user_prompt,
215
+ temperature=temperature,
216
+ logprobs=logprobs,
217
+ top_logprobs=top_logprobs,
218
+ mode=mode,
219
+ number_of_keywords=number_of_keywords,
220
+ validator=validator,
221
+ max_validation_retries=max_validation_retries,
222
+ priority=priority,
223
+ # Internal parameters
224
+ prompt_file="extract_keywords.yaml",
225
+ output_model=Models.ListStrOutput,
226
+ )
227
+ end = datetime.now()
228
+ output.execution_time = (end - start).total_seconds()
229
+ return output
230
+
231
+ async def extract_entities(
232
+ self,
233
+ text: str,
234
+ with_analysis: bool = False,
235
+ output_lang: str | None = None,
236
+ user_prompt: str | None = None,
237
+ temperature: float | None = 0.0,
238
+ logprobs: bool = False,
239
+ top_logprobs: int | None = None,
240
+ validator: Callable[[Any], bool] | None = None,
241
+ max_validation_retries: int | None = None,
242
+ priority: int | None = 0,
243
+ ) -> Models.ToolOutput:
244
+ """
245
+ Perform Named Entity Recognition (NER) over the input text.
246
+
247
+ Arguments:
248
+ text: The input text to extract entities from
249
+ with_analysis: Whether to include detailed reasoning analysis
250
+ output_lang: Language for the output response
251
+ user_prompt: Additional instructions for entity extraction
252
+ temperature: Controls randomness (0.0 = deterministic, 1.0 = creative)
253
+ logprobs: Whether to return token probability information
254
+ top_logprobs: Number of top token alternatives to return if logprobs enabled
255
+ validator: Custom validation function to validate the output
256
+ max_validation_retries: Maximum number of retry attempts if validation fails
257
+ priority: Task execution priority (if enabled by vLLM and model)
258
+
259
+ Returns:
260
+ ToolOutput: Object containing:
261
+ - result (list[dict]): List of entities with 'text' and 'type' keys
262
+ - logprobs (list | None): Probability data if logprobs enabled
263
+ - analysis (str | None): Detailed reasoning if with_analysis enabled
264
+ - errors (list(str) | None): Errors occured during tool call
265
+ """
266
+ start = datetime.now()
267
+ output = await self._operator.run(
268
+ # User parameters
269
+ text=text,
270
+ with_analysis=with_analysis,
271
+ output_lang=output_lang,
272
+ user_prompt=user_prompt,
273
+ temperature=temperature,
274
+ logprobs=logprobs,
275
+ top_logprobs=top_logprobs,
276
+ validator=validator,
277
+ max_validation_retries=max_validation_retries,
278
+ priority=priority,
279
+ # Internal parameters
280
+ prompt_file="extract_entities.yaml",
281
+ output_model=Models.ListDictStrStrOutput,
282
+ mode=None,
283
+ )
284
+ end = datetime.now()
285
+ output.execution_time = (end - start).total_seconds()
286
+ return output
287
+
288
+ async def is_question(
289
+ self,
290
+ text: str,
291
+ with_analysis: bool = False,
292
+ user_prompt: str | None = None,
293
+ temperature: float | None = 0.0,
294
+ logprobs: bool = False,
295
+ top_logprobs: int | None = None,
296
+ validator: Callable[[Any], bool] | None = None,
297
+ max_validation_retries: int | None = None,
298
+ priority: int | None = 0,
299
+ ) -> Models.ToolOutput:
300
+ """
301
+ Detect if the input is phrased as a question.
302
+
303
+ Arguments:
304
+ text: The input text to analyze
305
+ with_analysis: Whether to include detailed reasoning analysis
306
+ user_prompt: Additional instructions for question detection
307
+ temperature: Controls randomness (0.0 = deterministic, 1.0 = creative)
308
+ logprobs: Whether to return token probability information
309
+ top_logprobs: Number of top token alternatives to return if logprobs enabled
310
+ validator: Custom validation function to validate the output
311
+ max_validation_retries: Maximum number of retry attempts if validation fails
312
+ priority: Task execution priority (if enabled by vLLM and model)
313
+
314
+ Returns:
315
+ ToolOutput: Object containing:
316
+ - result (bool): True if text is a question, False otherwise
317
+ - logprobs (list | None): Probability data if logprobs enabled
318
+ - analysis (str | None): Detailed reasoning if with_analysis enabled
319
+ - errors (list(str) | None): Errors occured during tool call
320
+ """
321
+ start = datetime.now()
322
+ output = await self._operator.run(
323
+ # User parameters
324
+ text=text,
325
+ with_analysis=with_analysis,
326
+ user_prompt=user_prompt,
327
+ temperature=temperature,
328
+ logprobs=logprobs,
329
+ top_logprobs=top_logprobs,
330
+ validator=validator,
331
+ max_validation_retries=max_validation_retries,
332
+ priority=priority,
333
+ # Internal parameters
334
+ prompt_file="is_question.yaml",
335
+ output_model=Models.BoolOutput,
336
+ mode=None,
337
+ output_lang=None,
338
+ )
339
+ end = datetime.now()
340
+ output.execution_time = (end - start).total_seconds()
341
+ return output
342
+
343
+ async def text_to_question(
344
+ self,
345
+ text: str,
346
+ with_analysis: bool = False,
347
+ output_lang: str | None = None,
348
+ user_prompt: str | None = None,
349
+ temperature: float | None = 0.0,
350
+ logprobs: bool = False,
351
+ top_logprobs: int | None = None,
352
+ validator: Callable[[Any], bool] | None = None,
353
+ max_validation_retries: int | None = None,
354
+ priority: int | None = 0,
355
+ ) -> Models.ToolOutput:
356
+ """
357
+ Generate a single question from the given text.
358
+
359
+ Arguments:
360
+ text: The input text to generate a question from
361
+ with_analysis: Whether to include detailed reasoning analysis
362
+ output_lang: Language for the output question
363
+ user_prompt: Additional instructions for question generation
364
+ temperature: Controls randomness (0.0 = deterministic, 1.0 = creative)
365
+ logprobs: Whether to return token probability information
366
+ top_logprobs: Number of top token alternatives to return if logprobs enabled
367
+ validator: Custom validation function to validate the output
368
+ max_validation_retries: Maximum number of retry attempts if validation fails
369
+ priority: Task execution priority (if enabled by vLLM and model)
370
+
371
+ Returns:
372
+ ToolOutput: Object containing:
373
+ - result (str): The generated question
374
+ - logprobs (list | None): Probability data if logprobs enabled
375
+ - analysis (str | None): Detailed reasoning if with_analysis enabled
376
+ - errors (list(str) | None): Errors occured during tool call
377
+ """
378
+ start = datetime.now()
379
+ output = await self._operator.run(
380
+ # User parameters
381
+ text=text,
382
+ with_analysis=with_analysis,
383
+ output_lang=output_lang,
384
+ user_prompt=user_prompt,
385
+ temperature=temperature,
386
+ logprobs=logprobs,
387
+ top_logprobs=top_logprobs,
388
+ validator=validator,
389
+ max_validation_retries=max_validation_retries,
390
+ priority=priority,
391
+ # Internal parameters
392
+ prompt_file="text_to_question.yaml",
393
+ output_model=Models.StrOutput,
394
+ mode=None,
395
+ )
396
+ end = datetime.now()
397
+ output.execution_time = (end - start).total_seconds()
398
+ return output
399
+
400
+ async def merge_questions(
401
+ self,
402
+ text: list[str],
403
+ with_analysis: bool = False,
404
+ output_lang: str | None = None,
405
+ user_prompt: str | None = None,
406
+ temperature: float | None = 0.0,
407
+ logprobs: bool = False,
408
+ top_logprobs: int | None = None,
409
+ mode: Literal["default", "reason"] = "default",
410
+ validator: Callable[[Any], bool] | None = None,
411
+ max_validation_retries: int | None = None,
412
+ priority: int | None = 0,
413
+ ) -> Models.ToolOutput:
414
+ """
415
+ Merge multiple questions into a single unified question.
416
+
417
+ Arguments:
418
+ text: List of questions to merge
419
+ with_analysis: Whether to include detailed reasoning analysis
420
+ output_lang: Language for the output merged question
421
+ user_prompt: Additional instructions for question merging
422
+ temperature: Controls randomness (0.0 = deterministic, 1.0 = creative)
423
+ logprobs: Whether to return token probability information
424
+ top_logprobs: Number of top token alternatives to return if logprobs enabled
425
+ mode: Merging strategy - 'default' for direct merge, 'reason' for reasoned merge
426
+ validator: Custom validation function to validate the output
427
+ max_validation_retries: Maximum number of retry attempts if validation fails
428
+ priority: Task execution priority (if enabled by vLLM and model)
429
+
430
+ Returns:
431
+ ToolOutput: Object containing:
432
+ - result (str): The merged question
433
+ - logprobs (list | None): Probability data if logprobs enabled
434
+ - analysis (str | None): Detailed reasoning if with_analysis enabled
435
+ - errors (list(str) | None): Errors occured during tool call
436
+ """
437
+ start = datetime.now()
438
+ text_combined = ", ".join(text)
439
+ output = await self._operator.run(
440
+ # User parameters
441
+ text=text_combined,
442
+ with_analysis=with_analysis,
443
+ output_lang=output_lang,
444
+ user_prompt=user_prompt,
445
+ temperature=temperature,
446
+ logprobs=logprobs,
447
+ top_logprobs=top_logprobs,
448
+ validator=validator,
449
+ max_validation_retries=max_validation_retries,
450
+ priority=priority,
451
+ # Internal parameters
452
+ prompt_file="merge_questions.yaml",
453
+ output_model=Models.StrOutput,
454
+ mode=mode,
455
+ )
456
+ end = datetime.now()
457
+ output.execution_time = (end - start).total_seconds()
458
+ return output
459
+
460
+ async def rewrite(
461
+ self,
462
+ text: str,
463
+ with_analysis: bool = False,
464
+ output_lang: str | None = None,
465
+ user_prompt: str | None = None,
466
+ temperature: float | None = 0.0,
467
+ logprobs: bool = False,
468
+ top_logprobs: int | None = None,
469
+ mode: Literal["positive", "negative", "hard_negative"] = "positive",
470
+ validator: Callable[[Any], bool] | None = None,
471
+ max_validation_retries: int | None = None,
472
+ priority: int | None = 0,
473
+ ) -> Models.ToolOutput:
474
+ """
475
+ Rewrite a text with different modes.
476
+
477
+ Arguments:
478
+ text: The input text to rewrite
479
+ with_analysis: Whether to include detailed reasoning analysis
480
+ output_lang: Language for the output rewritten text
481
+ user_prompt: Additional instructions for rewriting
482
+ temperature: Controls randomness (0.0 = deterministic, 1.0 = creative)
483
+ logprobs: Whether to return token probability information
484
+ top_logprobs: Number of top token alternatives to return if logprobs enabled
485
+ mode: Rewriting mode - 'positive', 'negative', or 'hard_negative'
486
+ validator: Custom validation function to validate the output
487
+ max_validation_retries: Maximum number of retry attempts if validation fails
488
+ priority: Task execution priority (if enabled by vLLM and model)
489
+
490
+ Returns:
491
+ ToolOutput: Object containing:
492
+ - result (str): The rewritten text
493
+ - logprobs (list | None): Probability data if logprobs enabled
494
+ - analysis (str | None): Detailed reasoning if with_analysis enabled
495
+ - errors (list(str) | None): Errors occured during tool call
496
+ """
497
+ start = datetime.now()
498
+ 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
+ prompt_file="rewrite.yaml",
512
+ output_model=Models.StrOutput,
513
+ mode=mode,
514
+ )
515
+ end = datetime.now()
516
+ output.execution_time = (end - start).total_seconds()
517
+ return output
518
+
519
+ async def subject_to_question(
520
+ self,
521
+ text: str,
522
+ number_of_questions: int,
523
+ with_analysis: bool = False,
524
+ output_lang: str | None = None,
525
+ user_prompt: str | None = None,
526
+ temperature: float | None = 0.0,
527
+ logprobs: bool = False,
528
+ top_logprobs: int | None = None,
529
+ validator: Callable[[Any], bool] | None = None,
530
+ max_validation_retries: int | None = None,
531
+ priority: int | None = 0,
532
+ ) -> Models.ToolOutput:
533
+ """
534
+ Generate a list of questions about a subject.
535
+
536
+ Arguments:
537
+ text: The subject text to generate questions about
538
+ number_of_questions: Number of questions to generate
539
+ with_analysis: Whether to include detailed reasoning analysis
540
+ output_lang: Language for the output questions
541
+ user_prompt: Additional instructions for question generation
542
+ temperature: Controls randomness (0.0 = deterministic, 1.0 = creative)
543
+ logprobs: Whether to return token probability information
544
+ top_logprobs: Number of top token alternatives to return if logprobs enabled
545
+ validator: Custom validation function to validate the output
546
+ max_validation_retries: Maximum number of retry attempts if validation fails
547
+ priority: Task execution priority (if enabled by vLLM and model)
548
+
549
+ Returns:
550
+ ToolOutput: Object containing:
551
+ - result (list[str]): List of generated questions
552
+ - logprobs (list | None): Probability data if logprobs enabled
553
+ - analysis (str | None): Detailed reasoning if with_analysis enabled
554
+ - errors (list(str) | None): Errors occured during tool call
555
+ """
556
+ start = datetime.now()
557
+ output = await self._operator.run(
558
+ # User parameters
559
+ text=text,
560
+ number_of_questions=number_of_questions,
561
+ with_analysis=with_analysis,
562
+ output_lang=output_lang,
563
+ user_prompt=user_prompt,
564
+ temperature=temperature,
565
+ logprobs=logprobs,
566
+ top_logprobs=top_logprobs,
567
+ validator=validator,
568
+ max_validation_retries=max_validation_retries,
569
+ priority=priority,
570
+ # Internal parameters
571
+ prompt_file="subject_to_question.yaml",
572
+ output_model=Models.ReasonListStrOutput,
573
+ mode=None,
574
+ )
575
+ end = datetime.now()
576
+ output.execution_time = (end - start).total_seconds()
577
+ return output
578
+
579
+ async def summarize(
580
+ self,
581
+ text: str,
582
+ with_analysis: bool = False,
583
+ output_lang: str | None = None,
584
+ user_prompt: str | None = None,
585
+ temperature: float | None = 0.0,
586
+ logprobs: bool = False,
587
+ top_logprobs: int | None = None,
588
+ validator: Callable[[Any], bool] | None = None,
589
+ max_validation_retries: int | None = None,
590
+ priority: int | None = 0,
591
+ ) -> Models.ToolOutput:
592
+ """
593
+ Summarize the given subject text.
594
+
595
+ Arguments:
596
+ text: The input text to summarize
597
+ with_analysis: Whether to include detailed reasoning analysis
598
+ output_lang: Language for the output summary
599
+ user_prompt: Additional instructions for summarization
600
+ temperature: Controls randomness (0.0 = deterministic, 1.0 = creative)
601
+ logprobs: Whether to return token probability information
602
+ top_logprobs: Number of top token alternatives to return if logprobs enabled
603
+ validator: Custom validation function to validate the output
604
+ max_validation_retries: Maximum number of retry attempts if validation fails
605
+ priority: Task execution priority (if enabled by vLLM and model)
606
+
607
+ Returns:
608
+ ToolOutput: Object containing:
609
+ - result (str): The summary text
610
+ - logprobs (list | None): Probability data if logprobs enabled
611
+ - analysis (str | None): Detailed reasoning if with_analysis enabled
612
+ - errors (list(str) | None): Errors occured during tool call
613
+ """
614
+ start = datetime.now()
615
+ output = await self._operator.run(
616
+ # User parameters
617
+ text=text,
618
+ with_analysis=with_analysis,
619
+ output_lang=output_lang,
620
+ user_prompt=user_prompt,
621
+ temperature=temperature,
622
+ logprobs=logprobs,
623
+ top_logprobs=top_logprobs,
624
+ validator=validator,
625
+ max_validation_retries=max_validation_retries,
626
+ priority=priority,
627
+ # Internal parameters
628
+ prompt_file="summarize.yaml",
629
+ output_model=Models.StrOutput,
630
+ mode=None,
631
+ )
632
+ end = datetime.now()
633
+ output.execution_time = (end - start).total_seconds()
634
+ return output
635
+
636
+ async def translate(
637
+ self,
638
+ text: str,
639
+ target_language: str,
640
+ with_analysis: bool = False,
641
+ user_prompt: str | None = None,
642
+ temperature: float | None = 0.0,
643
+ logprobs: bool = False,
644
+ top_logprobs: int | None = None,
645
+ validator: Callable[[Any], bool] | None = None,
646
+ max_validation_retries: int | None = None,
647
+ priority: int | None = 0,
648
+ ) -> Models.ToolOutput:
649
+ """
650
+ Translate text between languages.
651
+
652
+ Arguments:
653
+ text: The input text to translate
654
+ target_language: The target language for translation
655
+ with_analysis: Whether to include detailed reasoning analysis
656
+ user_prompt: Additional instructions for translation
657
+ temperature: Controls randomness (0.0 = deterministic, 1.0 = creative)
658
+ logprobs: Whether to return token probability information
659
+ top_logprobs: Number of top token alternatives to return if logprobs enabled
660
+ validator: Custom validation function to validate the output
661
+ max_validation_retries: Maximum number of retry attempts if validation fails
662
+ priority: Task execution priority (if enabled by vLLM and model)
663
+
664
+ Returns:
665
+ ToolOutput: Object containing:
666
+ - result (str): The translated text
667
+ - logprobs (list | None): Probability data if logprobs enabled
668
+ - analysis (str | None): Detailed reasoning if with_analysis enabled
669
+ - errors (list(str) | None): Errors occured during tool call
670
+ """
671
+ start = datetime.now()
672
+ output = await self._operator.run(
673
+ # User parameters
674
+ text=text,
675
+ target_language=target_language,
676
+ with_analysis=with_analysis,
677
+ user_prompt=user_prompt,
678
+ temperature=temperature,
679
+ logprobs=logprobs,
680
+ top_logprobs=top_logprobs,
681
+ validator=validator,
682
+ max_validation_retries=max_validation_retries,
683
+ priority=priority,
684
+ # Internal parameters
685
+ prompt_file="translate.yaml",
686
+ output_model=Models.StrOutput,
687
+ mode=None,
688
+ output_lang=None,
689
+ )
690
+ end = datetime.now()
691
+ output.execution_time = (end - start).total_seconds()
692
+ return output
693
+
694
+ async def detect_entity(
695
+ self,
696
+ text: str,
697
+ with_analysis: bool = False,
698
+ output_lang: str | None = None,
699
+ user_prompt: str | None = None,
700
+ temperature: float | None = 0.0,
701
+ logprobs: bool = False,
702
+ top_logprobs: int | None = None,
703
+ validator: Callable[[Any], bool] | None = None,
704
+ max_validation_retries: int | None = None,
705
+ priority: int | None = 0,
706
+ ) -> Models.ToolOutput:
707
+ """
708
+ Detects entities in a given text based on the entity_detector.yaml prompt.
709
+
710
+ Arguments:
711
+ text: The input text
712
+ with_analysis: Whether to include detailed reasoning analysis
713
+ output_lang: Language for the output summary
714
+ user_prompt: Additional instructions for summarization
715
+ temperature: Controls randomness (0.0 = deterministic, 1.0 = creative)
716
+ logprobs: Whether to return token probability information
717
+ top_logprobs: Number of top token alternatives to return if logprobs enabled
718
+ validator: Custom validation function to validate the output
719
+ max_validation_retries: Maximum number of retry attempts if validation fails
720
+ priority: Task execution priority (if enabled by vLLM and model)
721
+
722
+ Returns:
723
+ ToolOutput: Object containing:
724
+ - result (list[Entity]): The entities
725
+ - logprobs (list | None): Probability data if logprobs enabled
726
+ - analysis (str | None): Detailed reasoning if with_analysis enabled
727
+ - errors (list(str) | None): Errors occured during tool call
728
+ """
729
+ start = datetime.now()
730
+ output = await self._operator.run(
731
+ # User parameters
732
+ text=text,
733
+ with_analysis=with_analysis,
734
+ output_lang=output_lang,
735
+ user_prompt=user_prompt,
736
+ temperature=temperature,
737
+ logprobs=logprobs,
738
+ top_logprobs=top_logprobs,
739
+ validator=validator,
740
+ max_validation_retries=max_validation_retries,
741
+ priority=priority,
742
+ # Internal parameters
743
+ prompt_file="detect_entity.yaml",
744
+ output_model=Models.EntityDetectorOutput,
745
+ mode=None,
746
+ )
747
+ end = datetime.now()
748
+ output.execution_time = (end - start).total_seconds()
749
+ return output
750
+
751
+ async def run_custom(
752
+ self,
753
+ prompt: str,
754
+ output_model: Any,
755
+ output_lang: str | None = None,
756
+ temperature: float | None = None,
757
+ logprobs: bool | None = None,
758
+ top_logprobs: int | None = None,
759
+ validator: Callable[[Any], bool] | None = None,
760
+ max_validation_retries: int | None = None,
761
+ priority: int | None = 0,
762
+ ) -> Models.ToolOutput:
763
+ """
764
+ Custom tool that can do almost anything!
765
+
766
+ Arguments:
767
+ text: The user prompt
768
+ output_lang: Language for the output summary
769
+ temperature: Controls randomness (0.0 = deterministic, 1.0 = creative)
770
+ logprobs: Whether to return token probability information
771
+ top_logprobs: Number of top token alternatives to return if logprobs enabled
772
+ validator: Custom validation function to validate the output
773
+ max_validation_retries: Maximum number of retry attempts if validation fails
774
+ priority: Task execution priority (if enabled by vLLM and model)
775
+
776
+ Returns:
777
+ ToolOutput: Object containing:
778
+ - result (str): The translated text
779
+ - logprobs (list | None): Probability data if logprobs enabled
780
+ - analysis (str | None): Detailed reasoning if with_analysis enabled
781
+ - errors (list(str) | None): Errors occured during tool call
782
+ """
783
+ start = datetime.now()
784
+ output = await self._operator.run(
785
+ # User paramaeters
786
+ text=prompt,
787
+ output_model=output_model,
788
+ output_model_str=output_model.model_json_schema(),
789
+ output_lang=output_lang,
790
+ temperature=temperature,
791
+ logprobs=logprobs,
792
+ top_logprobs=top_logprobs,
793
+ validator=validator,
794
+ max_validation_retries=max_validation_retries,
795
+ priority=priority,
796
+ # Internal parameters
797
+ prompt_file="run_custom.yaml",
798
+ user_prompt=None,
799
+ with_analysis=False,
800
+ mode=None,
801
+ )
802
+ end = datetime.now()
803
+ output.execution_time = (end - start).total_seconds()
804
+ return output