swarmauri_tool_jupytergetshellmessage 0.10.1.dev3__tar.gz → 0.11.0.dev1__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.
- {swarmauri_tool_jupytergetshellmessage-0.10.1.dev3 → swarmauri_tool_jupytergetshellmessage-0.11.0.dev1}/PKG-INFO +5 -2
- {swarmauri_tool_jupytergetshellmessage-0.10.1.dev3 → swarmauri_tool_jupytergetshellmessage-0.11.0.dev1}/README.md +4 -1
- {swarmauri_tool_jupytergetshellmessage-0.10.1.dev3 → swarmauri_tool_jupytergetshellmessage-0.11.0.dev1}/pyproject.toml +2 -2
- {swarmauri_tool_jupytergetshellmessage-0.10.1.dev3 → swarmauri_tool_jupytergetshellmessage-0.11.0.dev1}/swarmauri_tool_jupytergetshellmessage/JupyterGetShellMessageTool.py +39 -17
- {swarmauri_tool_jupytergetshellmessage-0.10.1.dev3 → swarmauri_tool_jupytergetshellmessage-0.11.0.dev1}/swarmauri_tool_jupytergetshellmessage/install_kernel.py +7 -3
- {swarmauri_tool_jupytergetshellmessage-0.10.1.dev3 → swarmauri_tool_jupytergetshellmessage-0.11.0.dev1}/LICENSE +0 -0
- {swarmauri_tool_jupytergetshellmessage-0.10.1.dev3 → swarmauri_tool_jupytergetshellmessage-0.11.0.dev1}/swarmauri_tool_jupytergetshellmessage/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: swarmauri_tool_jupytergetshellmessage
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.0.dev1
|
|
4
4
|
Summary: A tool designed to retrieve shell messages from a running Jupyter kernel using jupyter_client, useful for debugging execution responses.
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
License-File: LICENSE
|
|
@@ -41,7 +41,8 @@ Description-Content-Type: text/markdown
|
|
|
41
41
|
<img src="https://img.shields.io/pypi/l/swarmauri_tool_jupytergetshellmessage" alt="PyPI - License"/></a>
|
|
42
42
|
<a href="https://pypi.org/project/swarmauri_tool_jupytergetshellmessage/">
|
|
43
43
|
<img src="https://img.shields.io/pypi/v/swarmauri_tool_jupytergetshellmessage?label=swarmauri_tool_jupytergetshellmessage&color=green" alt="PyPI - swarmauri_tool_jupytergetshellmessage"/></a>
|
|
44
|
-
|
|
44
|
+
<a href="https://discord.gg/N4UpBuQv8T">
|
|
45
|
+
<img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
|
|
45
46
|
|
|
46
47
|
# Swarmauri Tool Jupyter Get Shell Message
|
|
47
48
|
|
|
@@ -97,3 +98,5 @@ else:
|
|
|
97
98
|
|
|
98
99
|
If you want to contribute to swarmauri-sdk, read up on our [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/contributing.md) that will help you get started.
|
|
99
100
|
|
|
101
|
+
|
|
102
|
+
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
<img src="https://img.shields.io/pypi/l/swarmauri_tool_jupytergetshellmessage" alt="PyPI - License"/></a>
|
|
12
12
|
<a href="https://pypi.org/project/swarmauri_tool_jupytergetshellmessage/">
|
|
13
13
|
<img src="https://img.shields.io/pypi/v/swarmauri_tool_jupytergetshellmessage?label=swarmauri_tool_jupytergetshellmessage&color=green" alt="PyPI - swarmauri_tool_jupytergetshellmessage"/></a>
|
|
14
|
-
|
|
14
|
+
<a href="https://discord.gg/N4UpBuQv8T">
|
|
15
|
+
<img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
|
|
15
16
|
|
|
16
17
|
# Swarmauri Tool Jupyter Get Shell Message
|
|
17
18
|
|
|
@@ -66,3 +67,5 @@ else:
|
|
|
66
67
|
## Want to help?
|
|
67
68
|
|
|
68
69
|
If you want to contribute to swarmauri-sdk, read up on our [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/contributing.md) that will help you get started.
|
|
70
|
+
|
|
71
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "swarmauri_tool_jupytergetshellmessage"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.11.0.dev1"
|
|
4
4
|
description = "A tool designed to retrieve shell messages from a running Jupyter kernel using jupyter_client, useful for debugging execution responses."
|
|
5
5
|
license = "Apache-2.0"
|
|
6
6
|
readme = "README.md"
|
|
@@ -86,7 +86,7 @@ dev = [
|
|
|
86
86
|
"pytest-xdist>=3.6.1",
|
|
87
87
|
"pytest-json-report>=1.5.0",
|
|
88
88
|
"python-dotenv",
|
|
89
|
-
"
|
|
89
|
+
"httpx>=0.27",
|
|
90
90
|
"flake8>=7.0",
|
|
91
91
|
"pytest-timeout>=2.3.1",
|
|
92
92
|
"ruff>=0.9.9",
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
"""
|
|
2
2
|
JupyterGetShellMessageTool.py
|
|
3
|
-
This module defines the JupyterGetShellMessageTool, a component that retrieves
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
This module defines the JupyterGetShellMessageTool, a component that retrieves
|
|
4
|
+
messages
|
|
5
|
+
from the Jupyter kernel's shell channel. It leverages the ToolBase and
|
|
6
|
+
ComponentBase
|
|
7
|
+
classes from the swarmauri framework to integrate with the system's tool
|
|
8
|
+
architecture.
|
|
9
|
+
The JupyterGetShellMessageTool supports retrieving and parsing messages for
|
|
10
|
+
diagnostic
|
|
11
|
+
purposes. It includes timeout-based handling to avoid hanging during message
|
|
12
|
+
retrieval.
|
|
8
13
|
"""
|
|
9
14
|
|
|
10
15
|
from typing import ClassVar, Callable, Any, Dict, List, Literal
|
|
@@ -24,16 +29,20 @@ logger = logging.getLogger(__name__)
|
|
|
24
29
|
@ComponentBase.register_type(ToolBase, "JupyterGetShellMessageTool")
|
|
25
30
|
class JupyterGetShellMessageTool(ToolBase):
|
|
26
31
|
"""
|
|
27
|
-
JupyterGetShellMessageTool is a tool designed to retrieve messages from the
|
|
28
|
-
|
|
32
|
+
JupyterGetShellMessageTool is a tool designed to retrieve messages from the
|
|
33
|
+
kernel's shell channel.
|
|
34
|
+
It listens for shell messages within a specified timeout, logs them for
|
|
35
|
+
diagnostics, and returns
|
|
29
36
|
the structured messages.
|
|
30
37
|
|
|
31
38
|
Attributes:
|
|
32
39
|
version (str): The version of the JupyterGetShellMessageTool.
|
|
33
|
-
parameters (List[Parameter]): A list of parameters that configure
|
|
40
|
+
parameters (List[Parameter]): A list of parameters that configure
|
|
41
|
+
message retrieval.
|
|
34
42
|
name (str): The name of the tool.
|
|
35
43
|
description (str): A brief description of the tool's functionality.
|
|
36
|
-
type (Literal["JupyterGetShellMessageTool"]): The type identifier for
|
|
44
|
+
type (Literal["JupyterGetShellMessageTool"]): The type identifier for
|
|
45
|
+
the tool.
|
|
37
46
|
"""
|
|
38
47
|
|
|
39
48
|
version: str = "1.0.0"
|
|
@@ -42,13 +51,19 @@ class JupyterGetShellMessageTool(ToolBase):
|
|
|
42
51
|
Parameter(
|
|
43
52
|
name="timeout",
|
|
44
53
|
input_type="number",
|
|
45
|
-
description=
|
|
54
|
+
description=(
|
|
55
|
+
"The time in seconds to wait for shell messages before "
|
|
56
|
+
"giving "
|
|
57
|
+
"up."
|
|
58
|
+
),
|
|
46
59
|
required=False,
|
|
47
60
|
),
|
|
48
61
|
]
|
|
49
62
|
)
|
|
50
63
|
name: str = "JupyterGetShellMessageTool"
|
|
51
|
-
description: str =
|
|
64
|
+
description: str = (
|
|
65
|
+
"Retrieves messages from the Jupyter kernel's shell channel."
|
|
66
|
+
)
|
|
52
67
|
type: Literal["JupyterGetShellMessageTool"] = "JupyterGetShellMessageTool"
|
|
53
68
|
|
|
54
69
|
# Public class attributes for patching.
|
|
@@ -67,13 +82,16 @@ class JupyterGetShellMessageTool(ToolBase):
|
|
|
67
82
|
|
|
68
83
|
def __call__(self, timeout: float = 5.0) -> Dict[str, Any]:
|
|
69
84
|
"""
|
|
70
|
-
Retrieves messages from the Jupyter kernel's shell channel within the
|
|
85
|
+
Retrieves messages from the Jupyter kernel's shell channel within the
|
|
86
|
+
specified timeout.
|
|
71
87
|
Args:
|
|
72
|
-
timeout (float, optional): The number of seconds to wait for shell
|
|
88
|
+
timeout (float, optional): The number of seconds to wait for shell
|
|
89
|
+
messages
|
|
73
90
|
before timing out. Defaults to 5.0.
|
|
74
91
|
|
|
75
92
|
Returns:
|
|
76
|
-
Dict[str, Any]: A dictionary containing all retrieved shell
|
|
93
|
+
Dict[str, Any]: A dictionary containing all retrieved shell
|
|
94
|
+
messages or an error message.
|
|
77
95
|
|
|
78
96
|
Example:
|
|
79
97
|
>>> tool = JupyterGetShellMessageTool()
|
|
@@ -81,14 +99,16 @@ class JupyterGetShellMessageTool(ToolBase):
|
|
|
81
99
|
>>> print(result)
|
|
82
100
|
{
|
|
83
101
|
'messages': [
|
|
84
|
-
{'header': {...}, 'parent_header': {...}, 'metadata':
|
|
102
|
+
{'header': {...}, 'parent_header': {...}, 'metadata':
|
|
103
|
+
{...}, 'content': {...}, 'buffers': [...]},
|
|
85
104
|
...
|
|
86
105
|
]
|
|
87
106
|
}
|
|
88
107
|
"""
|
|
89
108
|
messages = []
|
|
90
109
|
try:
|
|
91
|
-
# Use the private attribute that now holds the patched
|
|
110
|
+
# Use the private attribute that now holds the patched
|
|
111
|
+
# find_connection_file.
|
|
92
112
|
connection_file = find_connection_file()
|
|
93
113
|
client = BlockingKernelClient(connection_file=connection_file)
|
|
94
114
|
client.load_connection_file()
|
|
@@ -110,7 +130,9 @@ class JupyterGetShellMessageTool(ToolBase):
|
|
|
110
130
|
|
|
111
131
|
if not retrieved_any_message:
|
|
112
132
|
return {
|
|
113
|
-
"error":
|
|
133
|
+
"error": (
|
|
134
|
+
f"No shell messages received within {timeout} seconds."
|
|
135
|
+
)
|
|
114
136
|
}
|
|
115
137
|
|
|
116
138
|
return {"messages": messages}
|
|
@@ -5,7 +5,9 @@ import subprocess
|
|
|
5
5
|
|
|
6
6
|
def is_kernel_available(kernel_name):
|
|
7
7
|
result = subprocess.run(
|
|
8
|
-
["jupyter", "kernelspec", "list", "--json"],
|
|
8
|
+
["jupyter", "kernelspec", "list", "--json"],
|
|
9
|
+
capture_output=True,
|
|
10
|
+
text=True,
|
|
9
11
|
)
|
|
10
12
|
kernels = json.loads(result.stdout).get("kernelspecs", {})
|
|
11
13
|
return kernel_name in kernels
|
|
@@ -15,7 +17,9 @@ def ensure_kernel(kernel_name, display_name=None):
|
|
|
15
17
|
"""Ensure the Jupyter kernel exists; if not, install it."""
|
|
16
18
|
# Get the list of existing kernels
|
|
17
19
|
result = subprocess.run(
|
|
18
|
-
["jupyter", "kernelspec", "list", "--json"],
|
|
20
|
+
["jupyter", "kernelspec", "list", "--json"],
|
|
21
|
+
capture_output=True,
|
|
22
|
+
text=True,
|
|
19
23
|
)
|
|
20
24
|
kernels = json.loads(result.stdout).get("kernelspecs", {})
|
|
21
25
|
|
|
@@ -54,7 +58,7 @@ def main():
|
|
|
54
58
|
|
|
55
59
|
if not is_kernel_available(required_kernel):
|
|
56
60
|
raise RuntimeError(
|
|
57
|
-
f"Kernel '{required_kernel}' is not available. Please install it with 'python -m ipykernel install --user --name {required_kernel}'"
|
|
61
|
+
f"Kernel '{required_kernel}' is not available. Please install it with 'python -m ipykernel install --user --name {required_kernel}'" # noqa: E501
|
|
58
62
|
)
|
|
59
63
|
|
|
60
64
|
km = KernelManager(kernel_name=required_kernel)
|
|
File without changes
|