Skip to content
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
4 changes: 0 additions & 4 deletions jupyter_ai_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from .extension import jupyter_server_extension_tools

__all__ = ["jupyter_server_extension_tools"]

__version__ = "0.1.2"


Expand Down
241 changes: 0 additions & 241 deletions jupyter_ai_tools/extension.py

This file was deleted.

1 change: 1 addition & 0 deletions jupyter_ai_tools/toolkits/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Toolkits for Jupyter"""
47 changes: 47 additions & 0 deletions jupyter_ai_tools/toolkits/code_execution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Tools that provide code execution features"""

import asyncio
import shlex
from typing import Optional

from jupyter_ai.tools.models import Tool, Toolkit


async def bash(command: str, timeout: Optional[int] = None) -> str:
"""Executes a bash command and returns the result

Args:
command: The bash command to execute
timeout: Optional timeout in seconds

Returns:
The command output (stdout and stderr combined)
"""

proc = await asyncio.create_subprocess_exec(
*shlex.split(command),
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)

try:
stdout, stderr = await asyncio.wait_for(proc.communicate(), timeout)
output = stdout.decode("utf-8")
error = stderr.decode("utf-8")

if proc.returncode != 0:
if error:
return f"Error: {error}"
return f"Command failed with exit code {proc.returncode}"

return output if output else "Command executed successfully with no output."
except asyncio.TimeoutError:
proc.kill()
return f"Command timed out after {timeout} seconds"


toolkit = Toolkit(
name="code_execution_toolkit",
description="Tools to execute code in different environments.",
)
toolkit.add_tool(Tool(callable=bash, execute=True))
Loading