swarmauri_tool_sentimentanalysis 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,19 @@
1
+ Metadata-Version: 2.3
2
+ Name: swarmauri_tool_sentimentanalysis
3
+ Version: 0.6.0.dev154
4
+ Summary: Sentiment Analysis 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
+ Project-URL: Repository, http://github.com/swarmauri/swarmauri-sdk
17
+ Description-Content-Type: text/markdown
18
+
19
+ # Swarmauri Example Community Package
@@ -0,0 +1 @@
1
+ # Swarmauri Example Community Package
@@ -0,0 +1,54 @@
1
+ [tool.poetry]
2
+ name = "swarmauri_tool_sentimentanalysis"
3
+ version = "0.6.0.dev154"
4
+ description = "Sentiment Analysis 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
+
24
+ [tool.poetry.group.dev.dependencies]
25
+ flake8 = "^7.0"
26
+ pytest = "^8.0"
27
+ pytest-asyncio = ">=0.24.0"
28
+ pytest-xdist = "^3.6.1"
29
+ pytest-json-report = "^1.5.0"
30
+ python-dotenv = "*"
31
+ requests = "^2.32.3"
32
+
33
+ [build-system]
34
+ requires = ["poetry-core>=1.0.0"]
35
+ build-backend = "poetry.core.masonry.api"
36
+
37
+ [tool.pytest.ini_options]
38
+ norecursedirs = ["combined", "scripts"]
39
+
40
+ markers = [
41
+ "test: standard test",
42
+ "unit: Unit tests",
43
+ "integration: Integration tests",
44
+ "acceptance: Acceptance tests",
45
+ "experimental: Experimental tests"
46
+ ]
47
+ log_cli = true
48
+ log_cli_level = "INFO"
49
+ log_cli_format = "%(asctime)s [%(levelname)s] %(message)s"
50
+ log_cli_date_format = "%Y-%m-%d %H:%M:%S"
51
+ asyncio_default_fixture_loop_scope = "function"
52
+
53
+ [tool.poetry.plugins."swarmauri.tools"]
54
+ SentimentAnalysisTool = "swarmauri_tool_sentimentanalysis.SentimentAnalysisTool:SentimentAnalysisTool"
@@ -0,0 +1,56 @@
1
+ from transformers import pipeline
2
+ from transformers import logging as hf_logging
3
+ from typing import List, Literal, Dict
4
+ from swarmauri.tools.base.ToolBase import ToolBase
5
+ from swarmauri.tools.concrete.Parameter import Parameter
6
+ from swarmauri_core.ComponentBase import ComponentBase
7
+ from pydantic import Field
8
+
9
+ hf_logging.set_verbosity_error()
10
+
11
+ @ComponentBase.register_type(ToolBase, "SentimentAnalysisTool")
12
+ class SentimentAnalysisTool(ToolBase):
13
+ """
14
+ A tool for analyzing the sentiment of the given text using Hugging Face's transformers.
15
+ """
16
+
17
+ version: str = "1.0.0"
18
+ parameters: List[Parameter] = Field(
19
+ default_factory=lambda: [
20
+ Parameter(
21
+ name="text",
22
+ type="string",
23
+ description="The text for sentiment analysis",
24
+ required=True,
25
+ )
26
+ ]
27
+ )
28
+
29
+ name: str = "SentimentAnalysisTool"
30
+ description: str = "Analyzes the sentiment of the given text."
31
+ type: Literal["SentimentAnalysisTool"] = "SentimentAnalysisTool"
32
+
33
+ def __call__(self, text: str) -> Dict[str, str]:
34
+ """
35
+ Performs sentiment analysis on the given text.
36
+
37
+ Args:
38
+ text (str): The text to analyze.
39
+
40
+ Returns:
41
+ Dict[str, str]: A dictionary containing the sentiment analysis result.
42
+ The dictionary has a single key-value pair, where the key is "sentiment"
43
+ and the value is the sentiment label.
44
+ Raises:
45
+ RuntimeError: If sentiment analysis fails.
46
+ """
47
+ analyzer = None
48
+ try:
49
+ analyzer = pipeline("sentiment-analysis")
50
+ result = analyzer(text)
51
+ return {"sentiment": result[0]["label"]}
52
+ except Exception as e:
53
+ raise RuntimeError(f"Sentiment analysis failed: {str(e)}")
54
+ finally:
55
+ if analyzer is not None:
56
+ del analyzer
@@ -0,0 +1,12 @@
1
+ from .SentimentAnalysisTool import SentimentAnalysisTool
2
+
3
+ __version__ = "0.6.0.dev26"
4
+ __long_desc__ = """
5
+
6
+ # Swarmauri SentimentAnalysis 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
+ """