swarmauri_tool_entityrecognition 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_entityrecognition
3
+ Version: 0.6.0.dev154
4
+ Summary: Swarmauri Community Entity Recognition Tool
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: swarmauri_base (>=0.6.0.dev154,<0.7.0)
15
+ Requires-Dist: swarmauri_core (>=0.6.0.dev154,<0.7.0)
16
+ Requires-Dist: transformers (>=4.45.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_entityrecognition"
3
+ version = "0.6.0.dev154"
4
+ description = "Swarmauri Community Entity Recognition Tool"
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
+ transformers = ">=4.45.0"
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
+ EntityRecognitionTool = "swarmauri_tool_entityrecognition.EntityRecognitionTool:EntityRecognitionTool"
@@ -0,0 +1,46 @@
1
+ import json
2
+ from typing import List, Literal, Dict, Optional, Callable
3
+ from swarmauri_core.ComponentBase import ComponentBase
4
+ from transformers import pipeline, logging as hf_logging
5
+ from swarmauri_base.tools.ToolBase import ToolBase
6
+ from swarmauri_standard.tools.Parameter import Parameter
7
+ from pydantic import Field
8
+
9
+ hf_logging.set_verbosity_error()
10
+
11
+
12
+ @ComponentBase.register_type(ToolBase, "EntityRecognitionTool")
13
+ class EntityRecognitionTool(ToolBase):
14
+ """
15
+ A tool that extracts named entities from text using a pre-trained NLP model.
16
+ """
17
+
18
+ name: str = "EntityRecognitionTool"
19
+ description: str = "Extracts named entities from text"
20
+ parameters: List[Parameter] = Field(
21
+ default_factory=lambda: [
22
+ Parameter(
23
+ name="text",
24
+ type="string",
25
+ description="The text for entity recognition",
26
+ required=True,
27
+ )
28
+ ]
29
+ )
30
+ type: Literal["EntityRecognitionTool"] = "EntityRecognitionTool"
31
+ nlp: Optional[Callable] = None
32
+
33
+ def __call__(self, text: str) -> Dict[str, str]:
34
+ try:
35
+ self.nlp = pipeline("ner")
36
+ entities = self.nlp(text)
37
+ organized_entities = {}
38
+ for entity in entities:
39
+ if entity["entity"] not in organized_entities:
40
+ organized_entities[entity["entity"]] = []
41
+ organized_entities[entity["entity"]].append(entity["word"])
42
+ return {"entities": json.dumps(organized_entities)}
43
+ except Exception as e:
44
+ raise e
45
+ finally:
46
+ del self.nlp
@@ -0,0 +1,12 @@
1
+ from .EntityRecognitionTool import EntityRecognitionTool
2
+
3
+ __version__ = "0.6.0.dev26"
4
+ __long_desc__ = """
5
+
6
+ # Swarmauri EntityRecognition Tool Plugin
7
+
8
+ Visit us at: https://swarmauri.com
9
+ Follow us at: https://github.com/swarmauri
10
+ Star us at: https://github.com/swarmauri/swarmauri-sdk
11
+
12
+ """