swarmauri_tool_entityrecognition 0.6.0.dev154__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.
- swarmauri_tool_entityrecognition/EntityRecognitionTool.py +46 -0
- swarmauri_tool_entityrecognition/__init__.py +12 -0
- swarmauri_tool_entityrecognition-0.6.0.dev154.dist-info/METADATA +20 -0
- swarmauri_tool_entityrecognition-0.6.0.dev154.dist-info/RECORD +6 -0
- swarmauri_tool_entityrecognition-0.6.0.dev154.dist-info/WHEEL +4 -0
- swarmauri_tool_entityrecognition-0.6.0.dev154.dist-info/entry_points.txt +3 -0
|
@@ -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
|
+
"""
|
|
@@ -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,6 @@
|
|
|
1
|
+
swarmauri_tool_entityrecognition/__init__.py,sha256=jKjo0ZjS0btFR_k5TxCLTRRya9kDmwMH85NcSwTD3Ao,300
|
|
2
|
+
swarmauri_tool_entityrecognition/EntityRecognitionTool.py,sha256=YvfFXgVDMAKWjg1IZziWPn9FCBkrHAXiN9T5wHi2SBw,1660
|
|
3
|
+
swarmauri_tool_entityrecognition-0.6.0.dev154.dist-info/entry_points.txt,sha256=fHdTlf5pEqcqXm7zMORmZ02nlIGkUYnomIS59-YBV1w,118
|
|
4
|
+
swarmauri_tool_entityrecognition-0.6.0.dev154.dist-info/METADATA,sha256=ypkxRCfOU80UdFdhnofQy091t6vAuDHbeDmCuZOJF8Q,799
|
|
5
|
+
swarmauri_tool_entityrecognition-0.6.0.dev154.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
|
6
|
+
swarmauri_tool_entityrecognition-0.6.0.dev154.dist-info/RECORD,,
|