hamtaa-texttools 1.0.6__tar.gz → 1.0.8__tar.gz
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.6/hamtaa_texttools.egg-info → hamtaa_texttools-1.0.8}/PKG-INFO +13 -22
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/README.md +12 -21
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8/hamtaa_texttools.egg-info}/PKG-INFO +13 -22
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/hamtaa_texttools.egg-info/SOURCES.txt +8 -8
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/pyproject.toml +1 -1
- hamtaa_texttools-1.0.8/texttools/tools/async_the_tool.py +383 -0
- hamtaa_texttools-1.0.8/texttools/tools/internals/async_operator.py +177 -0
- hamtaa_texttools-1.0.8/texttools/tools/internals/base_operator.py +85 -0
- hamtaa_texttools-1.0.8/texttools/tools/internals/formatters.py +24 -0
- hamtaa_texttools-1.0.8/texttools/tools/internals/operator.py +177 -0
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/texttools/tools/internals/prompt_loader.py +3 -12
- hamtaa_texttools-1.0.8/texttools/tools/the_tool.py +381 -0
- hamtaa_texttools-1.0.6/texttools/formatters/base_formatter.py +0 -33
- hamtaa_texttools-1.0.6/texttools/formatters/user_merge_formatter.py +0 -30
- hamtaa_texttools-1.0.6/texttools/tools/async_the_tool.py +0 -277
- hamtaa_texttools-1.0.6/texttools/tools/internals/async_operator.py +0 -308
- hamtaa_texttools-1.0.6/texttools/tools/internals/operator.py +0 -295
- hamtaa_texttools-1.0.6/texttools/tools/the_tool.py +0 -501
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/LICENSE +0 -0
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/MANIFEST.in +0 -0
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/hamtaa_texttools.egg-info/dependency_links.txt +0 -0
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/hamtaa_texttools.egg-info/requires.txt +0 -0
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/hamtaa_texttools.egg-info/top_level.txt +0 -0
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/setup.cfg +0 -0
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/texttools/__init__.py +0 -0
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/texttools/batch/__init__.py +0 -0
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/texttools/batch/batch_manager.py +0 -0
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/texttools/batch/batch_runner.py +0 -0
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/texttools/prompts/README.md +0 -0
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/texttools/prompts/categorizer.yaml +0 -0
- /hamtaa_texttools-1.0.6/texttools/prompts/ner_extractor.yaml → /hamtaa_texttools-1.0.8/texttools/prompts/extract_entities.yaml +0 -0
- /hamtaa_texttools-1.0.6/texttools/prompts/keyword_extractor.yaml → /hamtaa_texttools-1.0.8/texttools/prompts/extract_keywords.yaml +0 -0
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/texttools/prompts/is_question.yaml +0 -0
- /hamtaa_texttools-1.0.6/texttools/prompts/question_merger.yaml → /hamtaa_texttools-1.0.8/texttools/prompts/merge_questions.yaml +0 -0
- /hamtaa_texttools-1.0.6/texttools/prompts/rewriter.yaml → /hamtaa_texttools-1.0.8/texttools/prompts/rewrite.yaml +0 -0
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/texttools/prompts/run_custom.yaml +0 -0
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/texttools/prompts/subject_to_question.yaml +0 -0
- /hamtaa_texttools-1.0.6/texttools/prompts/summarizer.yaml → /hamtaa_texttools-1.0.8/texttools/prompts/summarize.yaml +0 -0
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/texttools/prompts/text_to_question.yaml +0 -0
- /hamtaa_texttools-1.0.6/texttools/prompts/translator.yaml → /hamtaa_texttools-1.0.8/texttools/prompts/translate.yaml +0 -0
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/texttools/tools/__init__.py +0 -0
- {hamtaa_texttools-1.0.6 → hamtaa_texttools-1.0.8}/texttools/tools/internals/output_models.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hamtaa-texttools
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.8
|
|
4
4
|
Summary: TextTools is 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
|
|
@@ -42,8 +42,6 @@ It provides both **sync (`TheTool`)** and **async (`AsyncTheTool`)** APIs for ma
|
|
|
42
42
|
|
|
43
43
|
It provides ready-to-use utilities for **translation, question detection, keyword extraction, categorization, NER extractor, and more** — designed to help you integrate AI-powered text processing into your applications with minimal effort.
|
|
44
44
|
|
|
45
|
-
**Thread Safety:** All methods in AsyncTheTool are thread-safe, allowing concurrent usage across multiple threads without conflicts.
|
|
46
|
-
|
|
47
45
|
---
|
|
48
46
|
|
|
49
47
|
## ✨ Features
|
|
@@ -78,7 +76,11 @@ Note: This doubles token usage per call because it triggers an additional LLM re
|
|
|
78
76
|
|
|
79
77
|
- **`user_prompt="..."`** → Allows you to inject a custom instruction or prompt into the model alongside the main template. This gives you fine-grained control over how the model interprets or modifies the input text.
|
|
80
78
|
|
|
81
|
-
|
|
79
|
+
- **`temperature=0.0`** → Determines how creative the model should respond. Takes a float number from `0.0` to `1.0`.
|
|
80
|
+
|
|
81
|
+
All these parameters can be used individually or together to tailor the behavior of any tool in **TextTools**.
|
|
82
|
+
|
|
83
|
+
**Note:** There might be some tools that don't support some of the parameters above.
|
|
82
84
|
|
|
83
85
|
---
|
|
84
86
|
|
|
@@ -104,7 +106,6 @@ pip install -U hamtaa-texttools
|
|
|
104
106
|
|
|
105
107
|
```python
|
|
106
108
|
from openai import OpenAI
|
|
107
|
-
from pydantic import BaseModel
|
|
108
109
|
from texttools import TheTool
|
|
109
110
|
|
|
110
111
|
# Create your OpenAI client
|
|
@@ -114,29 +115,19 @@ client = OpenAI(base_url = "your_url", API_KEY = "your_api_key")
|
|
|
114
115
|
model = "gpt-4o-mini"
|
|
115
116
|
|
|
116
117
|
# Create an instance of TheTool
|
|
117
|
-
|
|
118
|
-
the_tool = TheTool(client=client, model=model, with_analysis=True, output_lang="English")
|
|
118
|
+
the_tool = TheTool(client=client, model=model)
|
|
119
119
|
|
|
120
120
|
# Example: Question Detection
|
|
121
121
|
detection = the_tool.is_question("Is this project open source?", logprobs=True, top_logprobs=2)
|
|
122
122
|
print(detection["result"])
|
|
123
123
|
print(detection["logprobs"])
|
|
124
|
-
# Output: True
|
|
124
|
+
# Output: True \n --logprobs
|
|
125
125
|
|
|
126
126
|
# Example: Translation
|
|
127
|
-
|
|
128
|
-
print(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
# Example: Custom Tool
|
|
132
|
-
# Note: Output model should only contain result key
|
|
133
|
-
# Everything else will be ignored
|
|
134
|
-
class Custom(BaseModel):
|
|
135
|
-
result: list[list[dict[str, int]]]
|
|
136
|
-
|
|
137
|
-
custom_prompt = "Something"
|
|
138
|
-
custom_result = the_tool.run_custom(custom_prompt, Custom)
|
|
139
|
-
print(custom_result)
|
|
127
|
+
translation = the_tool.translate("سلام، حالت چطوره؟" target_language="English", with_analysis=True)
|
|
128
|
+
print(translation["result"])
|
|
129
|
+
print(translation["analysis"])
|
|
130
|
+
# Output: "Hi! How are you?" \n --analysis
|
|
140
131
|
```
|
|
141
132
|
|
|
142
133
|
---
|
|
@@ -149,7 +140,7 @@ from openai import AsyncOpenAI
|
|
|
149
140
|
from texttools import AsyncTheTool
|
|
150
141
|
|
|
151
142
|
async def main():
|
|
152
|
-
# Create your
|
|
143
|
+
# Create your AsyncOpenAI client
|
|
153
144
|
async_client = AsyncOpenAI(base_url="your_url", api_key="your_api_key")
|
|
154
145
|
|
|
155
146
|
# Specify the model
|
|
@@ -8,8 +8,6 @@ It provides both **sync (`TheTool`)** and **async (`AsyncTheTool`)** APIs for ma
|
|
|
8
8
|
|
|
9
9
|
It provides ready-to-use utilities for **translation, question detection, keyword extraction, categorization, NER extractor, and more** — designed to help you integrate AI-powered text processing into your applications with minimal effort.
|
|
10
10
|
|
|
11
|
-
**Thread Safety:** All methods in AsyncTheTool are thread-safe, allowing concurrent usage across multiple threads without conflicts.
|
|
12
|
-
|
|
13
11
|
---
|
|
14
12
|
|
|
15
13
|
## ✨ Features
|
|
@@ -44,7 +42,11 @@ Note: This doubles token usage per call because it triggers an additional LLM re
|
|
|
44
42
|
|
|
45
43
|
- **`user_prompt="..."`** → Allows you to inject a custom instruction or prompt into the model alongside the main template. This gives you fine-grained control over how the model interprets or modifies the input text.
|
|
46
44
|
|
|
47
|
-
|
|
45
|
+
- **`temperature=0.0`** → Determines how creative the model should respond. Takes a float number from `0.0` to `1.0`.
|
|
46
|
+
|
|
47
|
+
All these parameters can be used individually or together to tailor the behavior of any tool in **TextTools**.
|
|
48
|
+
|
|
49
|
+
**Note:** There might be some tools that don't support some of the parameters above.
|
|
48
50
|
|
|
49
51
|
---
|
|
50
52
|
|
|
@@ -70,7 +72,6 @@ pip install -U hamtaa-texttools
|
|
|
70
72
|
|
|
71
73
|
```python
|
|
72
74
|
from openai import OpenAI
|
|
73
|
-
from pydantic import BaseModel
|
|
74
75
|
from texttools import TheTool
|
|
75
76
|
|
|
76
77
|
# Create your OpenAI client
|
|
@@ -80,29 +81,19 @@ client = OpenAI(base_url = "your_url", API_KEY = "your_api_key")
|
|
|
80
81
|
model = "gpt-4o-mini"
|
|
81
82
|
|
|
82
83
|
# Create an instance of TheTool
|
|
83
|
-
|
|
84
|
-
the_tool = TheTool(client=client, model=model, with_analysis=True, output_lang="English")
|
|
84
|
+
the_tool = TheTool(client=client, model=model)
|
|
85
85
|
|
|
86
86
|
# Example: Question Detection
|
|
87
87
|
detection = the_tool.is_question("Is this project open source?", logprobs=True, top_logprobs=2)
|
|
88
88
|
print(detection["result"])
|
|
89
89
|
print(detection["logprobs"])
|
|
90
|
-
# Output: True
|
|
90
|
+
# Output: True \n --logprobs
|
|
91
91
|
|
|
92
92
|
# Example: Translation
|
|
93
|
-
|
|
94
|
-
print(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
# Example: Custom Tool
|
|
98
|
-
# Note: Output model should only contain result key
|
|
99
|
-
# Everything else will be ignored
|
|
100
|
-
class Custom(BaseModel):
|
|
101
|
-
result: list[list[dict[str, int]]]
|
|
102
|
-
|
|
103
|
-
custom_prompt = "Something"
|
|
104
|
-
custom_result = the_tool.run_custom(custom_prompt, Custom)
|
|
105
|
-
print(custom_result)
|
|
93
|
+
translation = the_tool.translate("سلام، حالت چطوره؟" target_language="English", with_analysis=True)
|
|
94
|
+
print(translation["result"])
|
|
95
|
+
print(translation["analysis"])
|
|
96
|
+
# Output: "Hi! How are you?" \n --analysis
|
|
106
97
|
```
|
|
107
98
|
|
|
108
99
|
---
|
|
@@ -115,7 +106,7 @@ from openai import AsyncOpenAI
|
|
|
115
106
|
from texttools import AsyncTheTool
|
|
116
107
|
|
|
117
108
|
async def main():
|
|
118
|
-
# Create your
|
|
109
|
+
# Create your AsyncOpenAI client
|
|
119
110
|
async_client = AsyncOpenAI(base_url="your_url", api_key="your_api_key")
|
|
120
111
|
|
|
121
112
|
# Specify the model
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hamtaa-texttools
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.8
|
|
4
4
|
Summary: TextTools is 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
|
|
@@ -42,8 +42,6 @@ It provides both **sync (`TheTool`)** and **async (`AsyncTheTool`)** APIs for ma
|
|
|
42
42
|
|
|
43
43
|
It provides ready-to-use utilities for **translation, question detection, keyword extraction, categorization, NER extractor, and more** — designed to help you integrate AI-powered text processing into your applications with minimal effort.
|
|
44
44
|
|
|
45
|
-
**Thread Safety:** All methods in AsyncTheTool are thread-safe, allowing concurrent usage across multiple threads without conflicts.
|
|
46
|
-
|
|
47
45
|
---
|
|
48
46
|
|
|
49
47
|
## ✨ Features
|
|
@@ -78,7 +76,11 @@ Note: This doubles token usage per call because it triggers an additional LLM re
|
|
|
78
76
|
|
|
79
77
|
- **`user_prompt="..."`** → Allows you to inject a custom instruction or prompt into the model alongside the main template. This gives you fine-grained control over how the model interprets or modifies the input text.
|
|
80
78
|
|
|
81
|
-
|
|
79
|
+
- **`temperature=0.0`** → Determines how creative the model should respond. Takes a float number from `0.0` to `1.0`.
|
|
80
|
+
|
|
81
|
+
All these parameters can be used individually or together to tailor the behavior of any tool in **TextTools**.
|
|
82
|
+
|
|
83
|
+
**Note:** There might be some tools that don't support some of the parameters above.
|
|
82
84
|
|
|
83
85
|
---
|
|
84
86
|
|
|
@@ -104,7 +106,6 @@ pip install -U hamtaa-texttools
|
|
|
104
106
|
|
|
105
107
|
```python
|
|
106
108
|
from openai import OpenAI
|
|
107
|
-
from pydantic import BaseModel
|
|
108
109
|
from texttools import TheTool
|
|
109
110
|
|
|
110
111
|
# Create your OpenAI client
|
|
@@ -114,29 +115,19 @@ client = OpenAI(base_url = "your_url", API_KEY = "your_api_key")
|
|
|
114
115
|
model = "gpt-4o-mini"
|
|
115
116
|
|
|
116
117
|
# Create an instance of TheTool
|
|
117
|
-
|
|
118
|
-
the_tool = TheTool(client=client, model=model, with_analysis=True, output_lang="English")
|
|
118
|
+
the_tool = TheTool(client=client, model=model)
|
|
119
119
|
|
|
120
120
|
# Example: Question Detection
|
|
121
121
|
detection = the_tool.is_question("Is this project open source?", logprobs=True, top_logprobs=2)
|
|
122
122
|
print(detection["result"])
|
|
123
123
|
print(detection["logprobs"])
|
|
124
|
-
# Output: True
|
|
124
|
+
# Output: True \n --logprobs
|
|
125
125
|
|
|
126
126
|
# Example: Translation
|
|
127
|
-
|
|
128
|
-
print(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
# Example: Custom Tool
|
|
132
|
-
# Note: Output model should only contain result key
|
|
133
|
-
# Everything else will be ignored
|
|
134
|
-
class Custom(BaseModel):
|
|
135
|
-
result: list[list[dict[str, int]]]
|
|
136
|
-
|
|
137
|
-
custom_prompt = "Something"
|
|
138
|
-
custom_result = the_tool.run_custom(custom_prompt, Custom)
|
|
139
|
-
print(custom_result)
|
|
127
|
+
translation = the_tool.translate("سلام، حالت چطوره؟" target_language="English", with_analysis=True)
|
|
128
|
+
print(translation["result"])
|
|
129
|
+
print(translation["analysis"])
|
|
130
|
+
# Output: "Hi! How are you?" \n --analysis
|
|
140
131
|
```
|
|
141
132
|
|
|
142
133
|
---
|
|
@@ -149,7 +140,7 @@ from openai import AsyncOpenAI
|
|
|
149
140
|
from texttools import AsyncTheTool
|
|
150
141
|
|
|
151
142
|
async def main():
|
|
152
|
-
# Create your
|
|
143
|
+
# Create your AsyncOpenAI client
|
|
153
144
|
async_client = AsyncOpenAI(base_url="your_url", api_key="your_api_key")
|
|
154
145
|
|
|
155
146
|
# Specify the model
|
|
@@ -11,24 +11,24 @@ texttools/__init__.py
|
|
|
11
11
|
texttools/batch/__init__.py
|
|
12
12
|
texttools/batch/batch_manager.py
|
|
13
13
|
texttools/batch/batch_runner.py
|
|
14
|
-
texttools/formatters/base_formatter.py
|
|
15
|
-
texttools/formatters/user_merge_formatter.py
|
|
16
14
|
texttools/prompts/README.md
|
|
17
15
|
texttools/prompts/categorizer.yaml
|
|
16
|
+
texttools/prompts/extract_entities.yaml
|
|
17
|
+
texttools/prompts/extract_keywords.yaml
|
|
18
18
|
texttools/prompts/is_question.yaml
|
|
19
|
-
texttools/prompts/
|
|
20
|
-
texttools/prompts/
|
|
21
|
-
texttools/prompts/question_merger.yaml
|
|
22
|
-
texttools/prompts/rewriter.yaml
|
|
19
|
+
texttools/prompts/merge_questions.yaml
|
|
20
|
+
texttools/prompts/rewrite.yaml
|
|
23
21
|
texttools/prompts/run_custom.yaml
|
|
24
22
|
texttools/prompts/subject_to_question.yaml
|
|
25
|
-
texttools/prompts/
|
|
23
|
+
texttools/prompts/summarize.yaml
|
|
26
24
|
texttools/prompts/text_to_question.yaml
|
|
27
|
-
texttools/prompts/
|
|
25
|
+
texttools/prompts/translate.yaml
|
|
28
26
|
texttools/tools/__init__.py
|
|
29
27
|
texttools/tools/async_the_tool.py
|
|
30
28
|
texttools/tools/the_tool.py
|
|
31
29
|
texttools/tools/internals/async_operator.py
|
|
30
|
+
texttools/tools/internals/base_operator.py
|
|
31
|
+
texttools/tools/internals/formatters.py
|
|
32
32
|
texttools/tools/internals/operator.py
|
|
33
33
|
texttools/tools/internals/output_models.py
|
|
34
34
|
texttools/tools/internals/prompt_loader.py
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
from typing import Literal, Any
|
|
2
|
+
|
|
3
|
+
from openai import AsyncOpenAI
|
|
4
|
+
|
|
5
|
+
from texttools.tools.internals.async_operator import AsyncOperator
|
|
6
|
+
import texttools.tools.internals.output_models as OutputModels
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AsyncTheTool:
|
|
10
|
+
"""
|
|
11
|
+
Async counterpart to TheTool.
|
|
12
|
+
|
|
13
|
+
Each method configures the async operator with a specific YAML prompt,
|
|
14
|
+
output schema, and flags, then delegates execution to `operator.run()`.
|
|
15
|
+
|
|
16
|
+
Usage:
|
|
17
|
+
async_client = AsyncOpenAI(...)
|
|
18
|
+
tool = TheToolAsync(async_client, model="model-name")
|
|
19
|
+
result = await tool.categorize("text ...", with_analysis=True)
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
client: AsyncOpenAI,
|
|
25
|
+
model: str,
|
|
26
|
+
):
|
|
27
|
+
self.operator = AsyncOperator(client=client, model=model)
|
|
28
|
+
|
|
29
|
+
async def categorize(
|
|
30
|
+
self,
|
|
31
|
+
text: str,
|
|
32
|
+
with_analysis: bool = False,
|
|
33
|
+
user_prompt: str | None = None,
|
|
34
|
+
temperature: float | None = 0.0,
|
|
35
|
+
logprobs: bool = False,
|
|
36
|
+
top_logprobs: int | None = None,
|
|
37
|
+
) -> dict[str, str]:
|
|
38
|
+
"""
|
|
39
|
+
Categorize a text into a single Islamic studies domain category.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
{"result": <category string>} + ("logprobs" and "analysis" if enabled)
|
|
43
|
+
"""
|
|
44
|
+
return await self.operator.run(
|
|
45
|
+
# User parameters
|
|
46
|
+
text=text,
|
|
47
|
+
with_analysis=with_analysis,
|
|
48
|
+
user_prompt=user_prompt,
|
|
49
|
+
temperature=temperature,
|
|
50
|
+
logprobs=logprobs,
|
|
51
|
+
top_logprobs=top_logprobs,
|
|
52
|
+
# Internal parameters
|
|
53
|
+
prompt_file="categorizer.yaml",
|
|
54
|
+
output_model=OutputModels.CategorizerOutput,
|
|
55
|
+
resp_format="parse",
|
|
56
|
+
mode=None,
|
|
57
|
+
output_lang=None,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
async def extract_keywords(
|
|
61
|
+
self,
|
|
62
|
+
text: str,
|
|
63
|
+
with_analysis: bool = False,
|
|
64
|
+
output_lang: str | None = None,
|
|
65
|
+
user_prompt: str | None = None,
|
|
66
|
+
temperature: float | None = 0.0,
|
|
67
|
+
logprobs: bool = False,
|
|
68
|
+
top_logprobs: int | None = None,
|
|
69
|
+
) -> dict[str, list[str]]:
|
|
70
|
+
"""
|
|
71
|
+
Extract salient keywords from text.
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
{"result": [<keyword1>, <keyword2>, ...]} + ("logprobs" and "analysis" if enabled)
|
|
75
|
+
"""
|
|
76
|
+
return await self.operator.run(
|
|
77
|
+
# User parameters
|
|
78
|
+
text=text,
|
|
79
|
+
with_analysis=with_analysis,
|
|
80
|
+
output_lang=output_lang,
|
|
81
|
+
user_prompt=user_prompt,
|
|
82
|
+
temperature=temperature,
|
|
83
|
+
logprobs=logprobs,
|
|
84
|
+
top_logprobs=top_logprobs,
|
|
85
|
+
# Internal parameters
|
|
86
|
+
prompt_file="extract_keywords.yaml",
|
|
87
|
+
output_model=OutputModels.ListStrOutput,
|
|
88
|
+
resp_format="parse",
|
|
89
|
+
mode=None,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
async def extract_entities(
|
|
93
|
+
self,
|
|
94
|
+
text: str,
|
|
95
|
+
with_analysis: bool = False,
|
|
96
|
+
output_lang: str | None = None,
|
|
97
|
+
user_prompt: str | None = None,
|
|
98
|
+
temperature: float | None = 0.0,
|
|
99
|
+
logprobs: bool = False,
|
|
100
|
+
top_logprobs: int | None = None,
|
|
101
|
+
) -> dict[str, list[dict[str, str]]]:
|
|
102
|
+
"""
|
|
103
|
+
Perform Named Entity Recognition (NER) over the input text.
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
{"result": [{"text": <entity>, "type": <entity_type>}, ...]} + ("logprobs" and "analysis" if enabled)
|
|
107
|
+
"""
|
|
108
|
+
return await self.operator.run(
|
|
109
|
+
# User parameters
|
|
110
|
+
text=text,
|
|
111
|
+
with_analysis=with_analysis,
|
|
112
|
+
output_lang=output_lang,
|
|
113
|
+
user_prompt=user_prompt,
|
|
114
|
+
temperature=temperature,
|
|
115
|
+
logprobs=logprobs,
|
|
116
|
+
top_logprobs=top_logprobs,
|
|
117
|
+
# Internal parameters
|
|
118
|
+
prompt_file="extract_entities.yaml",
|
|
119
|
+
output_model=OutputModels.ListDictStrStrOutput,
|
|
120
|
+
resp_format="parse",
|
|
121
|
+
mode=None,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
async def is_question(
|
|
125
|
+
self,
|
|
126
|
+
text: str,
|
|
127
|
+
with_analysis: bool = False,
|
|
128
|
+
user_prompt: str | None = None,
|
|
129
|
+
temperature: float | None = 0.0,
|
|
130
|
+
logprobs: bool = False,
|
|
131
|
+
top_logprobs: int | None = None,
|
|
132
|
+
) -> dict[str, bool]:
|
|
133
|
+
"""
|
|
134
|
+
Detect if the input is phrased as a question.
|
|
135
|
+
|
|
136
|
+
Returns:
|
|
137
|
+
{"result": True} or {"result": False} + ("logprobs" and "analysis" if enabled)
|
|
138
|
+
"""
|
|
139
|
+
return await self.operator.run(
|
|
140
|
+
# User parameters
|
|
141
|
+
text=text,
|
|
142
|
+
with_analysis=with_analysis,
|
|
143
|
+
user_prompt=user_prompt,
|
|
144
|
+
temperature=temperature,
|
|
145
|
+
logprobs=logprobs,
|
|
146
|
+
top_logprobs=top_logprobs,
|
|
147
|
+
# Internal parameters
|
|
148
|
+
prompt_file="is_question.yaml",
|
|
149
|
+
output_model=OutputModels.BoolOutput,
|
|
150
|
+
resp_format="parse",
|
|
151
|
+
mode=None,
|
|
152
|
+
output_lang=None,
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
async def text_to_question(
|
|
156
|
+
self,
|
|
157
|
+
text: str,
|
|
158
|
+
with_analysis: bool = False,
|
|
159
|
+
output_lang: str | None = None,
|
|
160
|
+
user_prompt: str | None = None,
|
|
161
|
+
temperature: float | None = 0.0,
|
|
162
|
+
logprobs: bool = False,
|
|
163
|
+
top_logprobs: int | None = None,
|
|
164
|
+
) -> dict[str, str]:
|
|
165
|
+
"""
|
|
166
|
+
Generate a single question from the given text.
|
|
167
|
+
|
|
168
|
+
Returns:
|
|
169
|
+
{"result": <generated_question>} + ("logprobs" and "analysis" if enabled)
|
|
170
|
+
"""
|
|
171
|
+
return await self.operator.run(
|
|
172
|
+
# User parameters
|
|
173
|
+
text=text,
|
|
174
|
+
with_analysis=with_analysis,
|
|
175
|
+
output_lang=output_lang,
|
|
176
|
+
user_prompt=user_prompt,
|
|
177
|
+
temperature=temperature,
|
|
178
|
+
logprobs=logprobs,
|
|
179
|
+
top_logprobs=top_logprobs,
|
|
180
|
+
# Internal parameters
|
|
181
|
+
prompt_file="text_to_question.yaml",
|
|
182
|
+
output_model=OutputModels.StrOutput,
|
|
183
|
+
resp_format="parse",
|
|
184
|
+
mode=None,
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
async def merge_questions(
|
|
188
|
+
self,
|
|
189
|
+
text: list[str],
|
|
190
|
+
with_analysis: bool = False,
|
|
191
|
+
output_lang: str | None = None,
|
|
192
|
+
user_prompt: str | None = None,
|
|
193
|
+
temperature: float | None = 0.0,
|
|
194
|
+
logprobs: bool = False,
|
|
195
|
+
top_logprobs: int | None = None,
|
|
196
|
+
mode: Literal["default", "reason"] = "default",
|
|
197
|
+
) -> dict[str, str]:
|
|
198
|
+
"""
|
|
199
|
+
Merge multiple questions into a single unified question.
|
|
200
|
+
|
|
201
|
+
Returns:
|
|
202
|
+
{"result": <merged_question>} + ("logprobs" and "analysis" if enabled)
|
|
203
|
+
"""
|
|
204
|
+
text = ", ".join(text)
|
|
205
|
+
return await self.operator.run(
|
|
206
|
+
# User parameters
|
|
207
|
+
text=text,
|
|
208
|
+
with_analysis=with_analysis,
|
|
209
|
+
output_lang=output_lang,
|
|
210
|
+
user_prompt=user_prompt,
|
|
211
|
+
temperature=temperature,
|
|
212
|
+
logprobs=logprobs,
|
|
213
|
+
top_logprobs=top_logprobs,
|
|
214
|
+
# Internal parameters
|
|
215
|
+
prompt_file="merge_questions.yaml",
|
|
216
|
+
output_model=OutputModels.StrOutput,
|
|
217
|
+
resp_format="parse",
|
|
218
|
+
mode=mode,
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
async def rewrite(
|
|
222
|
+
self,
|
|
223
|
+
text: str,
|
|
224
|
+
with_analysis: bool = False,
|
|
225
|
+
output_lang: str | None = None,
|
|
226
|
+
user_prompt: str | None = None,
|
|
227
|
+
temperature: float | None = 0.0,
|
|
228
|
+
logprobs: bool = False,
|
|
229
|
+
top_logprobs: int | None = None,
|
|
230
|
+
mode: Literal["positive", "negative", "hard_negative"] = "positive",
|
|
231
|
+
) -> dict[str, str]:
|
|
232
|
+
"""
|
|
233
|
+
Rewrite a text with different modes.
|
|
234
|
+
|
|
235
|
+
Returns:
|
|
236
|
+
{"result": <rewritten_text>} + ("logprobs" and "analysis" if enabled)
|
|
237
|
+
"""
|
|
238
|
+
return await self.operator.run(
|
|
239
|
+
# User parameters
|
|
240
|
+
text=text,
|
|
241
|
+
with_analysis=with_analysis,
|
|
242
|
+
output_lang=output_lang,
|
|
243
|
+
user_prompt=user_prompt,
|
|
244
|
+
temperature=temperature,
|
|
245
|
+
logprobs=logprobs,
|
|
246
|
+
top_logprobs=top_logprobs,
|
|
247
|
+
# Internal parameters
|
|
248
|
+
prompt_file="rewrite.yaml",
|
|
249
|
+
output_model=OutputModels.StrOutput,
|
|
250
|
+
resp_format="parse",
|
|
251
|
+
mode=mode,
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
async def subject_to_question(
|
|
255
|
+
self,
|
|
256
|
+
text: str,
|
|
257
|
+
number_of_questions: int,
|
|
258
|
+
with_analysis: bool = False,
|
|
259
|
+
output_lang: str | None = None,
|
|
260
|
+
user_prompt: str | None = None,
|
|
261
|
+
temperature: float | None = 0.0,
|
|
262
|
+
logprobs: bool = False,
|
|
263
|
+
top_logprobs: int | None = None,
|
|
264
|
+
) -> dict[str, list[str]]:
|
|
265
|
+
"""
|
|
266
|
+
Generate a list of questions about a subject.
|
|
267
|
+
|
|
268
|
+
Returns:
|
|
269
|
+
{"result": [<question1>, <question2>, ...]} + ("logprobs" and "analysis" if enabled)
|
|
270
|
+
"""
|
|
271
|
+
return await self.operator.run(
|
|
272
|
+
# User parameters
|
|
273
|
+
text=text,
|
|
274
|
+
number_of_questions=number_of_questions,
|
|
275
|
+
with_analysis=with_analysis,
|
|
276
|
+
output_lang=output_lang,
|
|
277
|
+
user_prompt=user_prompt,
|
|
278
|
+
temperature=temperature,
|
|
279
|
+
logprobs=logprobs,
|
|
280
|
+
top_logprobs=top_logprobs,
|
|
281
|
+
# Internal parameters
|
|
282
|
+
prompt_file="subject_to_question.yaml",
|
|
283
|
+
output_model=OutputModels.ReasonListStrOutput,
|
|
284
|
+
resp_format="parse",
|
|
285
|
+
mode=None,
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
async def summarize(
|
|
289
|
+
self,
|
|
290
|
+
text: str,
|
|
291
|
+
with_analysis: bool = False,
|
|
292
|
+
output_lang: str | None = None,
|
|
293
|
+
user_prompt: str | None = None,
|
|
294
|
+
temperature: float | None = 0.0,
|
|
295
|
+
logprobs: bool = False,
|
|
296
|
+
top_logprobs: int | None = None,
|
|
297
|
+
) -> dict[str, str]:
|
|
298
|
+
"""
|
|
299
|
+
Summarize the given subject text.
|
|
300
|
+
|
|
301
|
+
Returns:
|
|
302
|
+
{"result": <summary>} + ("logprobs" and "analysis" if enabled)
|
|
303
|
+
"""
|
|
304
|
+
return await self.operator.run(
|
|
305
|
+
# User parameters
|
|
306
|
+
text=text,
|
|
307
|
+
with_analysis=with_analysis,
|
|
308
|
+
output_lang=output_lang,
|
|
309
|
+
user_prompt=user_prompt,
|
|
310
|
+
temperature=temperature,
|
|
311
|
+
logprobs=logprobs,
|
|
312
|
+
top_logprobs=top_logprobs,
|
|
313
|
+
# Internal parameters
|
|
314
|
+
prompt_file="summarize.yaml",
|
|
315
|
+
output_model=OutputModels.StrOutput,
|
|
316
|
+
resp_format="parse",
|
|
317
|
+
mode=None,
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
async def translate(
|
|
321
|
+
self,
|
|
322
|
+
text: str,
|
|
323
|
+
target_language: str,
|
|
324
|
+
with_analysis: bool = False,
|
|
325
|
+
user_prompt: str | None = None,
|
|
326
|
+
temperature: float | None = 0.0,
|
|
327
|
+
logprobs: bool = False,
|
|
328
|
+
top_logprobs: int | None = None,
|
|
329
|
+
) -> dict[str, str]:
|
|
330
|
+
"""
|
|
331
|
+
Translate text between languages.
|
|
332
|
+
|
|
333
|
+
Returns:
|
|
334
|
+
{"result": <translated_text>} + ("logprobs" and "analysis" if enabled)
|
|
335
|
+
"""
|
|
336
|
+
return await self.operator.run(
|
|
337
|
+
# User parameters
|
|
338
|
+
text=text,
|
|
339
|
+
target_language=target_language,
|
|
340
|
+
with_analysis=with_analysis,
|
|
341
|
+
user_prompt=user_prompt,
|
|
342
|
+
temperature=temperature,
|
|
343
|
+
logprobs=logprobs,
|
|
344
|
+
top_logprobs=top_logprobs,
|
|
345
|
+
# Internal parameters
|
|
346
|
+
prompt_file="translate.yaml",
|
|
347
|
+
output_model=OutputModels.StrOutput,
|
|
348
|
+
resp_format="parse",
|
|
349
|
+
mode=None,
|
|
350
|
+
output_lang=None,
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
async def run_custom(
|
|
354
|
+
self,
|
|
355
|
+
prompt: str,
|
|
356
|
+
output_model: Any,
|
|
357
|
+
output_lang: str | None = None,
|
|
358
|
+
temperature: float | None = None,
|
|
359
|
+
logprobs: bool | None = None,
|
|
360
|
+
top_logprobs: int | None = None,
|
|
361
|
+
) -> dict[str, Any]:
|
|
362
|
+
"""
|
|
363
|
+
Custom tool that can do almost anything!
|
|
364
|
+
|
|
365
|
+
Returns:
|
|
366
|
+
{"result": <Any>}
|
|
367
|
+
"""
|
|
368
|
+
return await self.operator.run(
|
|
369
|
+
# User paramaeters
|
|
370
|
+
text=prompt,
|
|
371
|
+
output_model=output_model,
|
|
372
|
+
output_model_str=output_model.model_json_schema(),
|
|
373
|
+
output_lang=output_lang,
|
|
374
|
+
temperature=temperature,
|
|
375
|
+
logprobs=logprobs,
|
|
376
|
+
top_logprobs=top_logprobs,
|
|
377
|
+
# Internal parameters
|
|
378
|
+
prompt_file="run_custom.yaml",
|
|
379
|
+
resp_format="parse",
|
|
380
|
+
user_prompt=None,
|
|
381
|
+
with_analysis=False,
|
|
382
|
+
mode=None,
|
|
383
|
+
)
|