swarmauri_tool_textlength 0.6.0.dev154__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.
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.3
2
+ Name: swarmauri_tool_textlength
3
+ Version: 0.6.0.dev154
4
+ Summary: Text Length Tool for Swarmauri
5
+ License: Apache-2.0
6
+ Author: Jacob Stewart
7
+ Author-email: jacob@swarmauri.com
8
+ Requires-Python: >=3.10,<3.13
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Requires-Dist: nltk (>=3.9.1,<4.0.0)
15
+ Requires-Dist: swarmauri_base (>=0.6.0.dev154,<0.7.0)
16
+ Requires-Dist: swarmauri_core (>=0.6.0.dev154,<0.7.0)
17
+ Project-URL: Repository, http://github.com/swarmauri/swarmauri-sdk
18
+ Description-Content-Type: text/markdown
19
+
20
+ # Swarmauri Example Community Package
@@ -0,0 +1 @@
1
+ # Swarmauri Example Community Package
@@ -0,0 +1,57 @@
1
+ [tool.poetry]
2
+ name = "swarmauri_tool_textlength"
3
+ version = "0.6.0.dev154"
4
+ description = "Text Length Tool for Swarmauri"
5
+ authors = ["Jacob Stewart <jacob@swarmauri.com>"]
6
+ license = "Apache-2.0"
7
+ readme = "README.md"
8
+ repository = "http://github.com/swarmauri/swarmauri-sdk"
9
+ classifiers = [
10
+ "License :: OSI Approved :: Apache Software License",
11
+ "Programming Language :: Python :: 3.10",
12
+ "Programming Language :: Python :: 3.11",
13
+ "Programming Language :: Python :: 3.12"
14
+ ]
15
+
16
+ [tool.poetry.dependencies]
17
+ python = ">=3.10,<3.13"
18
+
19
+ # Swarmauri
20
+ swarmauri_core = {version = "^0.6.0.dev154"}
21
+ swarmauri_base = {version = "^0.6.0.dev154"}
22
+
23
+ # Dependencies
24
+ nltk = "^3.9.1"
25
+
26
+
27
+ [tool.poetry.group.dev.dependencies]
28
+ flake8 = "^7.0"
29
+ pytest = "^8.0"
30
+ pytest-asyncio = ">=0.24.0"
31
+ pytest-xdist = "^3.6.1"
32
+ pytest-json-report = "^1.5.0"
33
+ python-dotenv = "*"
34
+ requests = "^2.32.3"
35
+
36
+ [build-system]
37
+ requires = ["poetry-core>=1.0.0"]
38
+ build-backend = "poetry.core.masonry.api"
39
+
40
+ [tool.pytest.ini_options]
41
+ norecursedirs = ["combined", "scripts"]
42
+
43
+ markers = [
44
+ "test: standard test",
45
+ "unit: Unit tests",
46
+ "integration: Integration tests",
47
+ "acceptance: Acceptance tests",
48
+ "experimental: Experimental tests"
49
+ ]
50
+ log_cli = true
51
+ log_cli_level = "INFO"
52
+ log_cli_format = "%(asctime)s [%(levelname)s] %(message)s"
53
+ log_cli_date_format = "%Y-%m-%d %H:%M:%S"
54
+ asyncio_default_fixture_loop_scope = "function"
55
+
56
+ [tool.poetry.plugins."swarmauri.tools"]
57
+ TextLengthTool = "swarmauri_tool_textlength:TextLengthTool"
@@ -0,0 +1,108 @@
1
+ from swarmauri_core.ComponentBase import ComponentBase
2
+ from swarmauri_core.typing import SubclassUnion
3
+ from typing import List, Literal, Dict
4
+ from pydantic import Field
5
+ from swarmauri._base.tools.ToolBase import ToolBase
6
+ from swarmauri_standard.tools.Parameter import Parameter
7
+ import nltk
8
+ from nltk.tokenize import sent_tokenize, word_tokenize
9
+
10
+ # Download required NLTK data once during module load
11
+ nltk.download("punkt", quiet=True)
12
+
13
+ @ComponentBase.register_type(ToolBase, "TextLengthTool")
14
+ class TextLengthTool(ToolBase):
15
+ version: str = "0.1.dev1"
16
+ parameters: List[Parameter] = Field(
17
+ default_factory=lambda: [
18
+ Parameter(
19
+ name="text",
20
+ type="string",
21
+ description="The text to analyze for length.",
22
+ required=True,
23
+ )
24
+ ]
25
+ )
26
+ name: str = "TextLengthTool"
27
+ description: str = "Calculates the length of the provided text in terms of characters, words, and sentences."
28
+ type: Literal["TextLengthTool"] = "TextLengthTool"
29
+
30
+ def __call__(self, text: str) -> Dict[str, int]:
31
+ """
32
+ Calculates the length of the provided text in terms of characters, words, and sentences.
33
+
34
+ Parameters:
35
+ text (str): The text to analyze.
36
+
37
+ Returns:
38
+ dict: A dictionary containing the number of characters, words, and sentences.
39
+ """
40
+ return self.calculate_text_length(text)
41
+
42
+ def calculate_text_length(self, text: str) -> Dict[str, int]:
43
+ """
44
+ Calculate the length of the text in characters, words, and sentences.
45
+
46
+ Parameters:
47
+ text (str): The text to analyze.
48
+
49
+ Returns:
50
+ dict: A dictionary containing:
51
+ - 'num_characters': Number of characters in the text.
52
+ - 'num_words': Number of words in the text.
53
+ - 'num_sentences': Number of sentences in the text.
54
+ """
55
+ num_characters = self.count_characters(text)
56
+ num_words = self.count_words(text)
57
+ num_sentences = self.count_sentences(text)
58
+
59
+ return {
60
+ "num_characters": num_characters,
61
+ "num_words": num_words,
62
+ "num_sentences": num_sentences,
63
+ }
64
+
65
+ def count_characters(self, text: str) -> int:
66
+ """
67
+ Count the number of characters in the text, excluding spaces.
68
+
69
+ Parameters:
70
+ text (str): The text to analyze.
71
+
72
+ Returns:
73
+ int: The number of characters in the text.
74
+ """
75
+ return len(text.replace(" ", ""))
76
+
77
+ def count_words(self, text: str) -> int:
78
+ """
79
+ Count the number of words in the text.
80
+
81
+ Parameters:
82
+ text (str): The text to analyze.
83
+
84
+ Returns:
85
+ int: The number of words in the text.
86
+ """
87
+ words = word_tokenize(text)
88
+ return len(words)
89
+
90
+ def count_sentences(self, text: str) -> int:
91
+ """
92
+ Count the number of sentences in the text.
93
+
94
+ Parameters:
95
+ text (str): The text to analyze.
96
+
97
+ Returns:
98
+ int: The number of sentences in the text.
99
+ """
100
+ sentences = sent_tokenize(text)
101
+ return len(sentences)
102
+
103
+
104
+ SubclassUnion.update(
105
+ baseclass=ToolBase,
106
+ type_name="TextLengthTool",
107
+ obj=TextLengthTool,
108
+ )
@@ -0,0 +1,14 @@
1
+ from .TextLengthTool import TextLengthTool
2
+
3
+ __version__ = "0.6.0.dev26"
4
+ __long_desc__ = """
5
+
6
+ # Swarmauri Example Plugin
7
+
8
+ This repository includes an example of a Swarmauri Plugin.
9
+
10
+ Visit us at: https://swarmauri.com
11
+ Follow us at: https://github.com/swarmauri
12
+ Star us at: https://github.com/swarmauri/swarmauri-sdk
13
+
14
+ """