Skip to content

Commit

Permalink
E2B tool
Browse files Browse the repository at this point in the history
  • Loading branch information
phact committed Jun 19, 2024
1 parent b727a8f commit 04dd9a6
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,7 @@ jobs:
PERPLEXITYAI_API_KEY: ${{ secrets.PERPLEXITYAI_API_KEY }}
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}

steps:
- name: Git checkout
Expand Down
3 changes: 1 addition & 2 deletions client/astra_assistants/astra_assistants_event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def run_tool(self, tool_call):
if tool_name in self.tools:
tool = self.tools[tool_name]
arguments = json.loads(tool_call.function.arguments)
query = arguments['query']
results = tool.search(query)
results = tool.call(arguments)
return results
else:
self.logger.error(f"Tool {tool_name} not found.")
Expand Down
3 changes: 2 additions & 1 deletion client/astra_assistants/tools/astra_data_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def __init__(self, db_url: str, collection_name, vectorize: bool = False, openai
self.openai_client = openai_client
self.embedding_model = embedding_model

def search(self, query):
def call(self, arguments):
query = arguments['arguments']
try:
if self.vectorize:
results = self.collection.find(
Expand Down
31 changes: 31 additions & 0 deletions client/astra_assistants/tools/e2b_code_interpreter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from e2b import Sandbox

from e2b_code_interpreter import CodeInterpreter

from astra_assistants.tools.tool_interface import ToolInterface


class E2BCodeInterpreter(ToolInterface):

def __init__(self):
print("initializing code interpreter")

running_sandboxes = Sandbox.list()
# Find the sandbox by metadata
for running_sandbox in running_sandboxes:
if running_sandbox.metadata.get("user_id", "") == 'uniqueID':
sandbox = Sandbox.reconnect(running_sandbox.sandbox_id)
sandbox.close()
else:
# Sandbox not found
pass
self.code_interpreter = CodeInterpreter()

print("initialized")

def call(self, arguments):
code = arguments['arguments']
exec = self.code_interpreter.notebook.exec_cell(
code,
)
return exec.text
4 changes: 2 additions & 2 deletions client/astra_assistants/tools/tool_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def search(self, query):
pass
class ToolInterface(ABC):
@abstractmethod
def search(self, query):
def call(self, query):
pass

def name(self):
Expand All @@ -17,7 +17,7 @@ def tool_choice_object(self):
return {"type": "function", "function": {"name": self.name()}}

def to_function(self):
search_sig = inspect.signature(self.search)
search_sig = inspect.signature(self.call)
parameters = {
name: {
"type": "string", # Assuming all parameters are strings for simplicity
Expand Down
162 changes: 161 additions & 1 deletion client/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pytest = "^8.0.2"

[tool.poetry.group.optional.dependencies]
astrapy = "^1.2.1"
e2b-code-interpreter = "^0.0.9"

[build-system]
requires = ["poetry-core"]
Expand Down
Loading

0 comments on commit 04dd9a6

Please sign in to comment.