Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug fixes #1190

Merged
merged 2 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def agenerate_image(self, prompt: str, **kwargs) -> bytes:
loop = asyncio.get_event_loop()
return await loop.run_in_executor(None, self.generate_image, prompt, **kwargs)

def batch(self, prompts: List[str], **kwargs) -> List[bytes]:
def batch_generate(self, prompts: List[str], **kwargs) -> List[bytes]:
"""
Generates images for a batch of prompts.
Returns a list of image bytes.
Expand All @@ -67,7 +67,7 @@ def batch(self, prompts: List[str], **kwargs) -> List[bytes]:
image_bytes_list.append(image_bytes)
return image_bytes_list

async def abatch(
async def abatch_generate(
self, prompts: List[str], max_concurrent: int = 5, **kwargs
) -> List[bytes]:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_batch(lepton_ai_imggen_model):
"A tropical beach at sunset",
"A steaming cup of coffee on a wooden table",
]
result_image_bytes_list = lepton_ai_imggen_model.batch(prompts=prompts)
result_image_bytes_list = lepton_ai_imggen_model.batch_generate(prompts=prompts)
assert len(result_image_bytes_list) == len(prompts)
for image_bytes in result_image_bytes_list:
assert isinstance(image_bytes, bytes)
Expand All @@ -69,7 +69,7 @@ async def test_abatch(lepton_ai_imggen_model):
"A snowy mountain peak",
"A vintage car on a rural road",
]
result_image_bytes_list = await lepton_ai_imggen_model.abatch(prompts=prompts)
result_image_bytes_list = await lepton_ai_imggen_model.abatch_generate(prompts=prompts)
assert len(result_image_bytes_list) == len(prompts)
for image_bytes in result_image_bytes_list:
assert isinstance(image_bytes, bytes)
Expand Down
7 changes: 4 additions & 3 deletions pkgs/community/swarmauri_parser_pypdftk/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "swarmauri_parser_fitzpdf"
name = "swarmauri_parser_pypdftk"
version = "0.6.2.dev3"
description = "Fitz PDF Parser for Swarmauri."
description = "A parser for extracting text from PDFs using PyPDFTK."
license = "Apache-2.0"
readme = "README.md"
repository = "http://github.com/swarmauri/swarmauri-sdk"
Expand Down Expand Up @@ -45,7 +45,8 @@ log_cli_date_format = "%Y-%m-%d %H:%M:%S"
asyncio_default_fixture_loop_scope = "function"

[tool.project.entry-points."swarmauri.parsers"]
PyPDFTKParser = "swarmauri_parser_fitzpdf.PyPDFTKParser:PyPDFTKParser"
PyPDFTKParser = "swarmauri_parser_pypdftk.PyPDFTKParser:PyPDFTKParser"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest import mock

import pytest
from swarmauri_parser_pdf.PyPDFTKParser import PyPDFTKParser as Parser
from swarmauri_parser_pypdftk.PyPDFTKParser import PyPDFTKParser as Parser
from swarmauri_core.documents.IDocument import IDocument


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ classifiers = [
authors = [{ name = "Jacob Stewart", email = "[email protected]" }]
dependencies = [
"transformers>=4.45.0",
"tensorflow>=2.18.0",
"tensorflow>=2.16.1",
"tf-keras==2.16.0",
"swarmauri_core",
"swarmauri_base",
"swarmauri_standard",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
"""

import logging
from typing import List, Dict, Any, Literal
from typing import Any, Dict, List, Literal

from pydantic import Field
from swarmauri_standard.tools.Parameter import Parameter
from swarmauri_base.tools.ToolBase import ToolBase
from swarmauri_base.ComponentBase import ComponentBase
from swarmauri_base.tools.ToolBase import ToolBase

from swarmauri_standard.tools.Parameter import Parameter

logger = logging.getLogger(__name__)


@ComponentBase.register_type(ToolBase, "JupyterClearOutputTool")
class JupyterClearOutputTool(ToolBase):
"""
Expand All @@ -36,7 +39,7 @@ class JupyterClearOutputTool(ToolBase):
default_factory=lambda: [
Parameter(
name="notebook_data",
type="object",
input_type="object",
description="A dictionary that represents the Jupyter Notebook to clear outputs from.",
required=True,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def test_parameters_structure() -> None:
assert param.name == "notebook_data", (
"Parameter name does not match expected value."
)
assert param.type == "object", "Parameter type does not match expected value."
assert param.input_type == "object", "Parameter type does not match expected value."
assert param.required, "Parameter should be required."
assert "A dictionary that represents" in param.description, (
"Parameter description is missing or incomplete."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ class JupyterDisplayTool(ToolBase):
default_factory=lambda: [
Parameter(
name="data",
type="string",
input_type="string",
description="The data to be displayed. Accepts text, HTML, image paths, or LaTeX content.",
required=True,
),
Parameter(
name="data_format",
type="string",
input_type="string",
description="The format of the data ('auto', 'text', 'html', 'image', or 'latex').",
required=False,
default="auto",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class JupyterDisplayHTMLTool(ToolBase):
default_factory=lambda: [
Parameter(
name="html_content",
type="string",
input_type="string",
description="The HTML content to display within the Jupyter Notebook cell.",
required=True,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ class JupyterExecuteAndConvertTool(ToolBase):
default_factory=lambda: [
Parameter(
name="notebook_path",
type="string",
input_type="string",
description="Path of the Jupyter notebook file to execute.",
required=True,
),
Parameter(
name="output_format",
type="string",
input_type="string",
description="The format to which the executed notebook should be converted (e.g., 'html', 'pdf').",
required=True,
enum=["html", "pdf"],
),
Parameter(
name="execution_timeout",
type="number",
input_type="number",
description="Timeout (in seconds) for notebook execution.",
required=False,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ class JupyterExecuteNotebookWithParametersTool(ToolBase):
default_factory=lambda: [
Parameter(
name="notebook_path",
type="string",
input_type="string",
description="The path to the Jupyter Notebook file to execute.",
required=True,
),
Parameter(
name="output_notebook_path",
type="string",
input_type="string",
description="The path where the output notebook will be saved.",
required=True,
),
Parameter(
name="params",
type="object",
input_type="object",
description="A dictionary of parameters to inject into the notebook.",
required=False,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@ class JupyterExportHTMLTool(ToolBase):
default_factory=lambda: [
Parameter(
name="notebook_json",
type="string",
input_type="string",
description="A JSON string representation of the Jupyter Notebook to be exported.",
required=True,
),
Parameter(
name="template_file",
type="string",
input_type="string",
description="Path to an optional nbconvert-compatible template file for custom HTML formatting.",
required=False,
),
Parameter(
name="extra_css",
type="string",
input_type="string",
description="Inline CSS to embed into the generated HTML. Inserted within <style> tags in the document head.",
required=False,
),
Parameter(
name="extra_js",
type="string",
input_type="string",
description="Inline JavaScript to embed into the generated HTML. Inserted within <script> tags in the document head.",
required=False,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ class JupyterExportPythonTool(ToolBase):
default_factory=lambda: [
Parameter(
name="notebook",
type="object",
input_type="object",
description="The NotebookNode object representing the Jupyter Notebook to export.",
required=True,
),
Parameter(
name="template_file",
type="string",
input_type="string",
description="Optional custom template path for exporting the notebook to a Python script.",
required=False,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ class JupyterReadNotebookTool(ToolBase):
default_factory=lambda: [
Parameter(
name="notebook_file_path",
type="string",
input_type="string",
description="The file path to the Jupyter notebook.",
required=True,
),
Parameter(
name="as_version",
type="integer",
input_type="integer",
description="nbformat version to parse the notebook with (e.g., 4).",
required=False,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ class JupyterShutdownKernelTool(ToolBase):
default_factory=lambda: [
Parameter(
name="kernel_id",
type="string",
input_type="string",
description="Unique identifier or name of the kernel to be shut down.",
required=True,
),
Parameter(
name="shutdown_timeout",
type="integer",
input_type="integer",
description="Maximum time in seconds to wait for the kernel to shut down cleanly.",
required=False,
default=5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ class JupyterWriteNotebookTool(ToolBase):
default_factory=lambda: [
Parameter(
name="notebook_data",
type="object",
input_type="object",
description="The notebook content as a dictionary/NotebookNode structure.",
required=True,
),
Parameter(
name="output_file",
type="string",
input_type="string",
description="Path to the output file where the notebook JSON will be written.",
required=True,
),
Parameter(
name="encoding",
type="string",
input_type="string",
description="File encoding to use when writing the notebook JSON.",
required=False,
default="utf-8",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# standard/tools/concrete/PsutilTool.py
from typing import Any, Callable, Dict, List, Literal

import psutil
from typing import Dict, Any, Literal, List, Callable
from swarmauri_base.ComponentBase import ComponentBase
from pydantic import Field
from swarmauri_base.ComponentBase import ComponentBase
from swarmauri_base.tools.ToolBase import ToolBase

from swarmauri_standard.tools.Parameter import Parameter


@ComponentBase.register_type(ToolBase, "PsutilTool")
class PsutilTool(ToolBase):
type: Literal["PsutilTool"] = "PsutilTool"
Expand Down Expand Up @@ -59,33 +62,61 @@ def get_all_disk_values(self) -> Dict[str, Any]:
}

def get_all_network_values(self) -> Dict[str, Any]:
return {
result = {
"network_io_counters": psutil.net_io_counters()._asdict(),
"network_connections": [
conn._asdict() for conn in psutil.net_connections()
],
"network_interfaces": {
iface: [addr._asdict() for addr in addrs]
for iface, addrs in psutil.net_if_addrs().items()
},
}

# Handle permission errors when getting network connections
try:
result["network_connections"] = [
conn._asdict() for conn in psutil.net_connections()
]
except (psutil.AccessDenied, PermissionError):
result["network_connections"] = (
"Permission denied - run with elevated privileges to access"
)

return result

def get_all_sensors_values(self) -> Dict[str, Any]:
battery = psutil.sensors_battery()
temperatures = psutil.sensors_temperatures()
fans = psutil.sensors_fans()
result = {}

return {
"battery": battery._asdict() if battery else None,
"temperatures": {
name: [temp._asdict() for temp in temps]
for name, temps in (temperatures or {}).items()
},
"fan_speeds": {
name: [fan._asdict() for fan in fans]
for name, fans in (fans or {}).items()
},
}
# Handle battery information
battery = psutil.sensors_battery()
result["battery"] = battery._asdict() if battery else None

# Handle temperatures - may not be available on all platforms
try:
if hasattr(psutil, "sensors_temperatures"):
temperatures = psutil.sensors_temperatures()
result["temperatures"] = {
name: [temp._asdict() for temp in temps]
for name, temps in (temperatures or {}).items()
}
else:
result["temperatures"] = "Not available on this platform"
except (AttributeError, NotImplementedError):
result["temperatures"] = "Not available on this platform"

# Handle fans - may not be available on all platforms
try:
if hasattr(psutil, "sensors_fans"):
fans = psutil.sensors_fans()
result["fan_speeds"] = {
name: [fan._asdict() for fan in fans]
for name, fans in (fans or {}).items()
}
else:
result["fan_speeds"] = "Not available on this platform"
except (AttributeError, NotImplementedError):
result["fan_speeds"] = "Not available on this platform"

# Fix the indentation - this was inside the exception block before
return result

def __call__(self, info_type: str) -> Dict[str, Any]:
"""
Expand Down
Loading
Loading