hamtaa-texttools 0.1.44__tar.gz → 1.0.0__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.0/LICENSE +21 -0
- hamtaa_texttools-1.0.0/PKG-INFO +129 -0
- hamtaa_texttools-1.0.0/README.md +95 -0
- hamtaa_texttools-1.0.0/hamtaa_texttools.egg-info/PKG-INFO +129 -0
- hamtaa_texttools-1.0.0/hamtaa_texttools.egg-info/SOURCES.txt +21 -0
- {hamtaa_texttools-0.1.44 → hamtaa_texttools-1.0.0}/hamtaa_texttools.egg-info/dependency_links.txt +0 -0
- hamtaa_texttools-1.0.0/hamtaa_texttools.egg-info/requires.txt +2 -0
- {hamtaa_texttools-0.1.44 → hamtaa_texttools-1.0.0}/hamtaa_texttools.egg-info/top_level.txt +0 -0
- hamtaa_texttools-1.0.0/pyproject.toml +26 -0
- {hamtaa_texttools-0.1.44 → hamtaa_texttools-1.0.0}/setup.cfg +0 -0
- hamtaa_texttools-1.0.0/tests/test_tools.py +65 -0
- hamtaa_texttools-1.0.0/texttools/__init__.py +9 -0
- hamtaa_texttools-1.0.0/texttools/formatters/base_formatter.py +33 -0
- hamtaa_texttools-1.0.0/texttools/formatters/user_merge_formatter/user_merge_formatter.py +47 -0
- hamtaa_texttools-1.0.0/texttools/tools/__init__.py +3 -0
- hamtaa_texttools-1.0.0/texttools/tools/operator.py +236 -0
- hamtaa_texttools-1.0.0/texttools/tools/output_models.py +54 -0
- hamtaa_texttools-1.0.0/texttools/tools/prompt_loader.py +84 -0
- hamtaa_texttools-1.0.0/texttools/tools/the_tool.py +291 -0
- hamtaa_texttools-1.0.0/texttools/utils/__init__.py +4 -0
- {hamtaa_texttools-0.1.44/texttools → hamtaa_texttools-1.0.0/texttools/utils}/batch_manager/__init__.py +2 -0
- {hamtaa_texttools-0.1.44/texttools → hamtaa_texttools-1.0.0/texttools/utils}/batch_manager/batch_manager.py +11 -12
- {hamtaa_texttools-0.1.44/texttools → hamtaa_texttools-1.0.0/texttools/utils}/batch_manager/batch_runner.py +20 -15
- hamtaa_texttools-0.1.44/PKG-INFO +0 -60
- hamtaa_texttools-0.1.44/README.md +0 -50
- hamtaa_texttools-0.1.44/hamtaa_texttools.egg-info/PKG-INFO +0 -60
- hamtaa_texttools-0.1.44/hamtaa_texttools.egg-info/SOURCES.txt +0 -65
- hamtaa_texttools-0.1.44/hamtaa_texttools.egg-info/requires.txt +0 -2
- hamtaa_texttools-0.1.44/pyproject.toml +0 -24
- hamtaa_texttools-0.1.44/setup.py +0 -4
- hamtaa_texttools-0.1.44/tests/test_vllm_output.py +0 -79
- hamtaa_texttools-0.1.44/texttools/__init__.py +0 -26
- hamtaa_texttools-0.1.44/texttools/base/__init__.py +0 -3
- hamtaa_texttools-0.1.44/texttools/base/base_categorizer.py +0 -40
- hamtaa_texttools-0.1.44/texttools/base/base_keyword_extractor.py +0 -35
- hamtaa_texttools-0.1.44/texttools/base/base_ner_extractor.py +0 -61
- hamtaa_texttools-0.1.44/texttools/base/base_question_detector.py +0 -35
- hamtaa_texttools-0.1.44/texttools/base/base_question_generator.py +0 -99
- hamtaa_texttools-0.1.44/texttools/base/base_question_merger.py +0 -59
- hamtaa_texttools-0.1.44/texttools/base/base_question_rewriter.py +0 -61
- hamtaa_texttools-0.1.44/texttools/base/base_router.py +0 -33
- hamtaa_texttools-0.1.44/texttools/base/base_summarizer.py +0 -55
- hamtaa_texttools-0.1.44/texttools/base/base_task_performer.py +0 -53
- hamtaa_texttools-0.1.44/texttools/base/base_translator.py +0 -38
- hamtaa_texttools-0.1.44/texttools/formatter/__init__.py +0 -1
- hamtaa_texttools-0.1.44/texttools/formatter/base.py +0 -26
- hamtaa_texttools-0.1.44/texttools/formatter/gemma3_formatter.py +0 -54
- hamtaa_texttools-0.1.44/texttools/handlers/__init__.py +0 -6
- hamtaa_texttools-0.1.44/texttools/handlers/categorizer/__init__.py +0 -6
- hamtaa_texttools-0.1.44/texttools/handlers/categorizer/categorizer.py +0 -61
- hamtaa_texttools-0.1.44/texttools/handlers/handlers.py +0 -88
- hamtaa_texttools-0.1.44/texttools/tools/__init__.py +0 -33
- hamtaa_texttools-0.1.44/texttools/tools/categorizer/__init__.py +0 -2
- hamtaa_texttools-0.1.44/texttools/tools/categorizer/encoder_model/__init__.py +0 -1
- hamtaa_texttools-0.1.44/texttools/tools/categorizer/encoder_model/encoder_vectorizer.py +0 -51
- hamtaa_texttools-0.1.44/texttools/tools/categorizer/llm/__init__.py +0 -2
- hamtaa_texttools-0.1.44/texttools/tools/categorizer/llm/gemma_categorizer.py +0 -169
- hamtaa_texttools-0.1.44/texttools/tools/categorizer/llm/openai_categorizer.py +0 -80
- hamtaa_texttools-0.1.44/texttools/tools/keyword_extractor/__init__.py +0 -1
- hamtaa_texttools-0.1.44/texttools/tools/keyword_extractor/gemma_extractor.py +0 -138
- hamtaa_texttools-0.1.44/texttools/tools/merger/__init__.py +0 -2
- hamtaa_texttools-0.1.44/texttools/tools/merger/gemma_question_merger.py +0 -214
- hamtaa_texttools-0.1.44/texttools/tools/ner/__init__.py +0 -1
- hamtaa_texttools-0.1.44/texttools/tools/ner/gemma_ner_extractor.py +0 -157
- hamtaa_texttools-0.1.44/texttools/tools/question_detector/__init__.py +0 -2
- hamtaa_texttools-0.1.44/texttools/tools/question_detector/gemma_detector.py +0 -114
- hamtaa_texttools-0.1.44/texttools/tools/question_detector/llm_detector.py +0 -112
- hamtaa_texttools-0.1.44/texttools/tools/question_generator/__init__.py +0 -1
- hamtaa_texttools-0.1.44/texttools/tools/question_generator/gemma_question_generator.py +0 -198
- hamtaa_texttools-0.1.44/texttools/tools/reranker/__init__.py +0 -3
- hamtaa_texttools-0.1.44/texttools/tools/reranker/reranker.py +0 -137
- hamtaa_texttools-0.1.44/texttools/tools/reranker/scorer.py +0 -216
- hamtaa_texttools-0.1.44/texttools/tools/reranker/sorter.py +0 -278
- hamtaa_texttools-0.1.44/texttools/tools/rewriter/__init__.py +0 -2
- hamtaa_texttools-0.1.44/texttools/tools/rewriter/gemma_question_rewriter.py +0 -213
- hamtaa_texttools-0.1.44/texttools/tools/router/__init__.py +0 -0
- hamtaa_texttools-0.1.44/texttools/tools/router/gemma_router.py +0 -169
- hamtaa_texttools-0.1.44/texttools/tools/subject_to_question/__init__.py +0 -1
- hamtaa_texttools-0.1.44/texttools/tools/subject_to_question/gemma_question_generator.py +0 -224
- hamtaa_texttools-0.1.44/texttools/tools/summarizer/__init__.py +0 -2
- hamtaa_texttools-0.1.44/texttools/tools/summarizer/gemma_summarizer.py +0 -140
- hamtaa_texttools-0.1.44/texttools/tools/summarizer/llm_summerizer.py +0 -108
- hamtaa_texttools-0.1.44/texttools/tools/translator/__init__.py +0 -1
- hamtaa_texttools-0.1.44/texttools/tools/translator/gemma_translator.py +0 -202
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Hamtaa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hamtaa-texttools
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: TextTools is a high-level NLP toolkit built on top of modern LLMs.
|
|
5
|
+
Author-email: Tohidi <the.mohammad.tohidi@gmail.com>, Montazer <montazerh82@gmail.com>, Givechi <mohamad.m.givechi@gmail.com>, MoosaviNejad <erfanmoosavi84@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Hamtaa
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
Keywords: nlp,llm,text-processing,openai
|
|
28
|
+
Requires-Python: >=3.8
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Requires-Dist: openai==1.97.1
|
|
32
|
+
Requires-Dist: PyYAML>=6.0
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# TextTools
|
|
36
|
+
|
|
37
|
+
## 📌 Overview
|
|
38
|
+
|
|
39
|
+
**TextTools** is a high-level **NLP toolkit** built on top of modern **LLMs**.
|
|
40
|
+
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.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## ✨ Features
|
|
45
|
+
|
|
46
|
+
TextTools provides a rich collection of high-level NLP utilities built on top of LLMs.
|
|
47
|
+
Each tool is designed to work out-of-the-box with structured outputs (JSON / Pydantic).
|
|
48
|
+
|
|
49
|
+
- **Categorizer** → Zero-finetuning text categorization for fast, scalable classification.
|
|
50
|
+
- **Keyword Extractor** → Identify the most important keywords in a text.
|
|
51
|
+
- **Question Merger** → Merge the provided questions, preserving all the main points
|
|
52
|
+
- **NER (Named Entity Recognition) Extractor** → Extract people, places, organizations, and other entities.
|
|
53
|
+
- **Question Detector** → Determine whether a text is a question or not.
|
|
54
|
+
- **Question Generator From Text** → Generate high-quality, context-relevant questions from provided text.
|
|
55
|
+
- **Question Generator From Subject** → Generate high-quality, context-relevant questions from a subject.
|
|
56
|
+
- **Rewriter** → Rewrite text while preserving meaning or without it.
|
|
57
|
+
- **Summarizer** → Condense long passages into clear, structured summaries.
|
|
58
|
+
- **Translator** → Translate text across multiple languages, with support for custom rules.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 🔍 `with_analysis` Mode
|
|
63
|
+
|
|
64
|
+
The `with_analysis=True` flag enhances the tool's output by providing a detailed reasoning chain behind its result. This is valuable for debugging, improving prompts, or understanding model behavior.
|
|
65
|
+
|
|
66
|
+
**Please be aware:** This feature works by making an additional LLM API call for each tool invocation, which will **effectively double your token usage** for that operation.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## 🚀 Installation
|
|
71
|
+
|
|
72
|
+
Install the latest release via PyPI:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install -U hamta-texttools
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## ⚡ Quick Start
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from openai import OpenAI
|
|
84
|
+
|
|
85
|
+
from texttools import TheTool
|
|
86
|
+
|
|
87
|
+
# Create your OpenAI client
|
|
88
|
+
client = OpenAI(base_url = "your_url", API_KEY = "your_api_key")
|
|
89
|
+
|
|
90
|
+
# Specify the model
|
|
91
|
+
model = "gpt-4o-mini"
|
|
92
|
+
|
|
93
|
+
# Create an instance of TheTool
|
|
94
|
+
# ⚠️ Note: Enabling `with_analysis=True` provides deeper insights but incurs additional LLM calls and token usage.
|
|
95
|
+
the_tool = TheTool(client = client, model = model, with_analysis = True)
|
|
96
|
+
|
|
97
|
+
# Example: Question Detection
|
|
98
|
+
print(the_tool.detect_question("Is this project open source?")["result"])
|
|
99
|
+
# Output: True
|
|
100
|
+
|
|
101
|
+
# Example: Translation
|
|
102
|
+
print(the_tool.translate("سلام، حالت چطوره؟")["result"])
|
|
103
|
+
# Output: "Hi! How are you?"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## 📚 Use Cases
|
|
109
|
+
|
|
110
|
+
Use **TextTools** when you need to:
|
|
111
|
+
|
|
112
|
+
- 🔍 **Classify** large datasets quickly without model training
|
|
113
|
+
- 🌍 **Translate** and process multilingual corpora with ease
|
|
114
|
+
- 🧩 **Integrate** LLMs into production pipelines (structured outputs)
|
|
115
|
+
- 📊 **Analyze** large text collections using embeddings and categorization
|
|
116
|
+
- ⚙️ **Automate** common text-processing tasks without reinventing the wheel
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## 🤝 Contributing
|
|
121
|
+
|
|
122
|
+
Contributions are welcome!
|
|
123
|
+
Feel free to **open issues, suggest new features, or submit pull requests**.
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# TextTools
|
|
2
|
+
|
|
3
|
+
## 📌 Overview
|
|
4
|
+
|
|
5
|
+
**TextTools** is a high-level **NLP toolkit** built on top of modern **LLMs**.
|
|
6
|
+
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.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## ✨ Features
|
|
11
|
+
|
|
12
|
+
TextTools provides a rich collection of high-level NLP utilities built on top of LLMs.
|
|
13
|
+
Each tool is designed to work out-of-the-box with structured outputs (JSON / Pydantic).
|
|
14
|
+
|
|
15
|
+
- **Categorizer** → Zero-finetuning text categorization for fast, scalable classification.
|
|
16
|
+
- **Keyword Extractor** → Identify the most important keywords in a text.
|
|
17
|
+
- **Question Merger** → Merge the provided questions, preserving all the main points
|
|
18
|
+
- **NER (Named Entity Recognition) Extractor** → Extract people, places, organizations, and other entities.
|
|
19
|
+
- **Question Detector** → Determine whether a text is a question or not.
|
|
20
|
+
- **Question Generator From Text** → Generate high-quality, context-relevant questions from provided text.
|
|
21
|
+
- **Question Generator From Subject** → Generate high-quality, context-relevant questions from a subject.
|
|
22
|
+
- **Rewriter** → Rewrite text while preserving meaning or without it.
|
|
23
|
+
- **Summarizer** → Condense long passages into clear, structured summaries.
|
|
24
|
+
- **Translator** → Translate text across multiple languages, with support for custom rules.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 🔍 `with_analysis` Mode
|
|
29
|
+
|
|
30
|
+
The `with_analysis=True` flag enhances the tool's output by providing a detailed reasoning chain behind its result. This is valuable for debugging, improving prompts, or understanding model behavior.
|
|
31
|
+
|
|
32
|
+
**Please be aware:** This feature works by making an additional LLM API call for each tool invocation, which will **effectively double your token usage** for that operation.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 🚀 Installation
|
|
37
|
+
|
|
38
|
+
Install the latest release via PyPI:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install -U hamta-texttools
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## ⚡ Quick Start
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from openai import OpenAI
|
|
50
|
+
|
|
51
|
+
from texttools import TheTool
|
|
52
|
+
|
|
53
|
+
# Create your OpenAI client
|
|
54
|
+
client = OpenAI(base_url = "your_url", API_KEY = "your_api_key")
|
|
55
|
+
|
|
56
|
+
# Specify the model
|
|
57
|
+
model = "gpt-4o-mini"
|
|
58
|
+
|
|
59
|
+
# Create an instance of TheTool
|
|
60
|
+
# ⚠️ Note: Enabling `with_analysis=True` provides deeper insights but incurs additional LLM calls and token usage.
|
|
61
|
+
the_tool = TheTool(client = client, model = model, with_analysis = True)
|
|
62
|
+
|
|
63
|
+
# Example: Question Detection
|
|
64
|
+
print(the_tool.detect_question("Is this project open source?")["result"])
|
|
65
|
+
# Output: True
|
|
66
|
+
|
|
67
|
+
# Example: Translation
|
|
68
|
+
print(the_tool.translate("سلام، حالت چطوره؟")["result"])
|
|
69
|
+
# Output: "Hi! How are you?"
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 📚 Use Cases
|
|
75
|
+
|
|
76
|
+
Use **TextTools** when you need to:
|
|
77
|
+
|
|
78
|
+
- 🔍 **Classify** large datasets quickly without model training
|
|
79
|
+
- 🌍 **Translate** and process multilingual corpora with ease
|
|
80
|
+
- 🧩 **Integrate** LLMs into production pipelines (structured outputs)
|
|
81
|
+
- 📊 **Analyze** large text collections using embeddings and categorization
|
|
82
|
+
- ⚙️ **Automate** common text-processing tasks without reinventing the wheel
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 🤝 Contributing
|
|
87
|
+
|
|
88
|
+
Contributions are welcome!
|
|
89
|
+
Feel free to **open issues, suggest new features, or submit pull requests**.
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hamtaa-texttools
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: TextTools is a high-level NLP toolkit built on top of modern LLMs.
|
|
5
|
+
Author-email: Tohidi <the.mohammad.tohidi@gmail.com>, Montazer <montazerh82@gmail.com>, Givechi <mohamad.m.givechi@gmail.com>, MoosaviNejad <erfanmoosavi84@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Hamtaa
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
Keywords: nlp,llm,text-processing,openai
|
|
28
|
+
Requires-Python: >=3.8
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Requires-Dist: openai==1.97.1
|
|
32
|
+
Requires-Dist: PyYAML>=6.0
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# TextTools
|
|
36
|
+
|
|
37
|
+
## 📌 Overview
|
|
38
|
+
|
|
39
|
+
**TextTools** is a high-level **NLP toolkit** built on top of modern **LLMs**.
|
|
40
|
+
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.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## ✨ Features
|
|
45
|
+
|
|
46
|
+
TextTools provides a rich collection of high-level NLP utilities built on top of LLMs.
|
|
47
|
+
Each tool is designed to work out-of-the-box with structured outputs (JSON / Pydantic).
|
|
48
|
+
|
|
49
|
+
- **Categorizer** → Zero-finetuning text categorization for fast, scalable classification.
|
|
50
|
+
- **Keyword Extractor** → Identify the most important keywords in a text.
|
|
51
|
+
- **Question Merger** → Merge the provided questions, preserving all the main points
|
|
52
|
+
- **NER (Named Entity Recognition) Extractor** → Extract people, places, organizations, and other entities.
|
|
53
|
+
- **Question Detector** → Determine whether a text is a question or not.
|
|
54
|
+
- **Question Generator From Text** → Generate high-quality, context-relevant questions from provided text.
|
|
55
|
+
- **Question Generator From Subject** → Generate high-quality, context-relevant questions from a subject.
|
|
56
|
+
- **Rewriter** → Rewrite text while preserving meaning or without it.
|
|
57
|
+
- **Summarizer** → Condense long passages into clear, structured summaries.
|
|
58
|
+
- **Translator** → Translate text across multiple languages, with support for custom rules.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 🔍 `with_analysis` Mode
|
|
63
|
+
|
|
64
|
+
The `with_analysis=True` flag enhances the tool's output by providing a detailed reasoning chain behind its result. This is valuable for debugging, improving prompts, or understanding model behavior.
|
|
65
|
+
|
|
66
|
+
**Please be aware:** This feature works by making an additional LLM API call for each tool invocation, which will **effectively double your token usage** for that operation.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## 🚀 Installation
|
|
71
|
+
|
|
72
|
+
Install the latest release via PyPI:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install -U hamta-texttools
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## ⚡ Quick Start
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from openai import OpenAI
|
|
84
|
+
|
|
85
|
+
from texttools import TheTool
|
|
86
|
+
|
|
87
|
+
# Create your OpenAI client
|
|
88
|
+
client = OpenAI(base_url = "your_url", API_KEY = "your_api_key")
|
|
89
|
+
|
|
90
|
+
# Specify the model
|
|
91
|
+
model = "gpt-4o-mini"
|
|
92
|
+
|
|
93
|
+
# Create an instance of TheTool
|
|
94
|
+
# ⚠️ Note: Enabling `with_analysis=True` provides deeper insights but incurs additional LLM calls and token usage.
|
|
95
|
+
the_tool = TheTool(client = client, model = model, with_analysis = True)
|
|
96
|
+
|
|
97
|
+
# Example: Question Detection
|
|
98
|
+
print(the_tool.detect_question("Is this project open source?")["result"])
|
|
99
|
+
# Output: True
|
|
100
|
+
|
|
101
|
+
# Example: Translation
|
|
102
|
+
print(the_tool.translate("سلام، حالت چطوره؟")["result"])
|
|
103
|
+
# Output: "Hi! How are you?"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## 📚 Use Cases
|
|
109
|
+
|
|
110
|
+
Use **TextTools** when you need to:
|
|
111
|
+
|
|
112
|
+
- 🔍 **Classify** large datasets quickly without model training
|
|
113
|
+
- 🌍 **Translate** and process multilingual corpora with ease
|
|
114
|
+
- 🧩 **Integrate** LLMs into production pipelines (structured outputs)
|
|
115
|
+
- 📊 **Analyze** large text collections using embeddings and categorization
|
|
116
|
+
- ⚙️ **Automate** common text-processing tasks without reinventing the wheel
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## 🤝 Contributing
|
|
121
|
+
|
|
122
|
+
Contributions are welcome!
|
|
123
|
+
Feel free to **open issues, suggest new features, or submit pull requests**.
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
hamtaa_texttools.egg-info/PKG-INFO
|
|
5
|
+
hamtaa_texttools.egg-info/SOURCES.txt
|
|
6
|
+
hamtaa_texttools.egg-info/dependency_links.txt
|
|
7
|
+
hamtaa_texttools.egg-info/requires.txt
|
|
8
|
+
hamtaa_texttools.egg-info/top_level.txt
|
|
9
|
+
tests/test_tools.py
|
|
10
|
+
texttools/__init__.py
|
|
11
|
+
texttools/formatters/base_formatter.py
|
|
12
|
+
texttools/formatters/user_merge_formatter/user_merge_formatter.py
|
|
13
|
+
texttools/tools/__init__.py
|
|
14
|
+
texttools/tools/operator.py
|
|
15
|
+
texttools/tools/output_models.py
|
|
16
|
+
texttools/tools/prompt_loader.py
|
|
17
|
+
texttools/tools/the_tool.py
|
|
18
|
+
texttools/utils/__init__.py
|
|
19
|
+
texttools/utils/batch_manager/__init__.py
|
|
20
|
+
texttools/utils/batch_manager/batch_manager.py
|
|
21
|
+
texttools/utils/batch_manager/batch_runner.py
|
{hamtaa_texttools-0.1.44 → hamtaa_texttools-1.0.0}/hamtaa_texttools.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "hamtaa-texttools"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Tohidi", email = "the.mohammad.tohidi@gmail.com" },
|
|
10
|
+
{ name = "Montazer", email = "montazerh82@gmail.com" },
|
|
11
|
+
{ name = "Givechi", email = "mohamad.m.givechi@gmail.com" },
|
|
12
|
+
{ name = "MoosaviNejad", email = "erfanmoosavi84@gmail.com" },
|
|
13
|
+
]
|
|
14
|
+
description = "TextTools is a high-level NLP toolkit built on top of modern LLMs."
|
|
15
|
+
readme = "README.md"
|
|
16
|
+
license = {file = "LICENSE"}
|
|
17
|
+
requires-python = ">=3.8"
|
|
18
|
+
dependencies = [
|
|
19
|
+
"openai==1.97.1",
|
|
20
|
+
"PyYAML>=6.0"
|
|
21
|
+
]
|
|
22
|
+
keywords = ["nlp", "llm", "text-processing", "openai"]
|
|
23
|
+
|
|
24
|
+
[tool.setuptools.packages.find]
|
|
25
|
+
where = ["."]
|
|
26
|
+
include = ["texttools*"]
|
|
File without changes
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from dotenv import load_dotenv
|
|
4
|
+
from openai import OpenAI
|
|
5
|
+
|
|
6
|
+
from texttools import TheTool
|
|
7
|
+
|
|
8
|
+
# Load environment variables from .env
|
|
9
|
+
load_dotenv()
|
|
10
|
+
|
|
11
|
+
# Load API key from environment variable
|
|
12
|
+
API_KEY = os.getenv("OPENAI_API_KEY")
|
|
13
|
+
model = "google/gemma-3n-e4b-it"
|
|
14
|
+
|
|
15
|
+
# Create OpenAI client
|
|
16
|
+
client = OpenAI(base_url="https://openrouter.ai/api/v1", api_key=API_KEY)
|
|
17
|
+
|
|
18
|
+
# Create an instance of TheTool
|
|
19
|
+
t = TheTool(client=client, model=model)
|
|
20
|
+
|
|
21
|
+
# Categorizer
|
|
22
|
+
category = t.categorize("سلام حالت چطوره؟")
|
|
23
|
+
print(category)
|
|
24
|
+
|
|
25
|
+
# Keyword Extractor
|
|
26
|
+
keywords = t.extract_keywords("Tomorrow, we will be dead by the car crash")
|
|
27
|
+
print(keywords)
|
|
28
|
+
|
|
29
|
+
# NER Extractor
|
|
30
|
+
entities = t.extract_entities("We will be dead by the car crash")
|
|
31
|
+
print(entities)
|
|
32
|
+
|
|
33
|
+
# Question Detector
|
|
34
|
+
detection = t.detect_question("We will be dead by the car crash")
|
|
35
|
+
print(detection)
|
|
36
|
+
|
|
37
|
+
# Question from Answer Generator
|
|
38
|
+
question = t.generate_question_from_text("We will be dead by the car crash")
|
|
39
|
+
print(question)
|
|
40
|
+
|
|
41
|
+
# Question Merger
|
|
42
|
+
question = t.merge_questions(
|
|
43
|
+
["چرا ما انسان ها، موجوداتی اجتماعی هستیم؟", "چرا ما باید در کنار هم زندگی کنیم؟"],
|
|
44
|
+
mode="default_mode",
|
|
45
|
+
)
|
|
46
|
+
print(question)
|
|
47
|
+
|
|
48
|
+
# Question Rewriter
|
|
49
|
+
question = t.rewrite_question(
|
|
50
|
+
"چرا ما انسان ها، موجوداتی اجتماعی هستیم؟",
|
|
51
|
+
mode="same_meaning_different_wording_mode",
|
|
52
|
+
)
|
|
53
|
+
print(question)
|
|
54
|
+
|
|
55
|
+
# Question Generator from Subject
|
|
56
|
+
questions = t.generate_questions_from_subject("Friendship", 3)
|
|
57
|
+
print(questions)
|
|
58
|
+
|
|
59
|
+
# Summarizer
|
|
60
|
+
summary = t.summarize("Tomorrow, we will be dead by the car crash")
|
|
61
|
+
print(summary)
|
|
62
|
+
|
|
63
|
+
# Translator
|
|
64
|
+
translation = t.translate("سلام حالت چطوره؟", target_language="English")
|
|
65
|
+
print(translation)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class BaseFormatter(ABC):
|
|
6
|
+
"""
|
|
7
|
+
Adapter to convert a conversation into a specific LLM API's input format.
|
|
8
|
+
|
|
9
|
+
Concrete implementations transform standardized messages (e.g., list[dict]) into the
|
|
10
|
+
exact payload required by a provider (e.g., OpenAI's message list, a single string, etc.).
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
@abstractmethod
|
|
14
|
+
def format(
|
|
15
|
+
self,
|
|
16
|
+
messages: Any,
|
|
17
|
+
) -> Any:
|
|
18
|
+
"""
|
|
19
|
+
Transform the input messages into a provider-specific payload.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
messages: The input conversation. While often a list of dicts with
|
|
23
|
+
'role' and 'content' keys, the exact type and structure may vary
|
|
24
|
+
by implementation.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
A payload in the format expected by the target LLM API. This could be:
|
|
28
|
+
- A list of role-content dictionaries (e.g., for OpenAI)
|
|
29
|
+
- A single formatted string (e.g., for completion-style APIs)
|
|
30
|
+
- A complex dictionary with additional parameters
|
|
31
|
+
- Any other provider-specific data structure
|
|
32
|
+
"""
|
|
33
|
+
pass
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from texttools.formatters.base_formatter import BaseFormatter
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class UserMergeFormatter(BaseFormatter):
|
|
5
|
+
"""
|
|
6
|
+
Merges consecutive user messages into a single message, separated by newlines.
|
|
7
|
+
|
|
8
|
+
This is useful for condensing a multi-turn user input into a single coherent
|
|
9
|
+
message for the LLM. Assistant and system messages are left unchanged and
|
|
10
|
+
act as separators between user message groups.
|
|
11
|
+
|
|
12
|
+
Raises:
|
|
13
|
+
ValueError: If the input messages have invalid structure or roles.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def _validate_input(self, messages: list[dict[str, str]]):
|
|
17
|
+
valid_keys = {"role", "content"}
|
|
18
|
+
valid_roles = {"user", "assistant"}
|
|
19
|
+
|
|
20
|
+
for message in messages:
|
|
21
|
+
# Validate keys
|
|
22
|
+
if set(message.keys()) != valid_keys:
|
|
23
|
+
raise ValueError(
|
|
24
|
+
f"Message dict keys must be exactly {valid_keys}, got {set(message.keys())}"
|
|
25
|
+
)
|
|
26
|
+
# Validate roles
|
|
27
|
+
role = message["role"]
|
|
28
|
+
if role != "system" and role not in valid_roles:
|
|
29
|
+
raise ValueError(f"Unexpected role: {role}")
|
|
30
|
+
|
|
31
|
+
def format(self, messages: list[dict[str, str]]) -> list[dict[str, str]]:
|
|
32
|
+
self._validate_input(messages)
|
|
33
|
+
|
|
34
|
+
merged: list[dict[str, str]] = []
|
|
35
|
+
|
|
36
|
+
for message in messages:
|
|
37
|
+
role, content = message["role"], message["content"].strip()
|
|
38
|
+
|
|
39
|
+
# Merge with previous user turn
|
|
40
|
+
if merged and role == "user" and merged[-1]["role"] == "user":
|
|
41
|
+
merged[-1]["content"] += "\n" + content
|
|
42
|
+
|
|
43
|
+
# Otherwise, start a new turn
|
|
44
|
+
else:
|
|
45
|
+
merged.append({"role": role, "content": content})
|
|
46
|
+
|
|
47
|
+
return merged
|