Enabled manual setting of docker base url for code interpreter tool. Goal is to avoid the error: CodeInterpreterTool Error while fetching server API version:

This commit is contained in:
Hammam Abdelwahab
2024-12-15 10:34:07 +01:00
parent a49be2fc52
commit c26e962d17
2 changed files with 15 additions and 1 deletions

View File

@@ -38,3 +38,16 @@ Agent(
tools=[CodeInterpreterTool(user_dockerfile_path="<Dockerfile_path>")], tools=[CodeInterpreterTool(user_dockerfile_path="<Dockerfile_path>")],
) )
``` ```
If it is difficult to connect to docker daemon automatically (especially for macOS users), you can do this to setup docker host manually
```python
from crewai_tools import CodeInterpreterTool
Agent(
...
tools=[CodeInterpreterTool(user_docker_base_url="<Docker Host Base Url>",
user_dockerfile_path="<Dockerfile_path>")],
)
```

View File

@@ -28,6 +28,7 @@ class CodeInterpreterTool(BaseTool):
default_image_tag: str = "code-interpreter:latest" default_image_tag: str = "code-interpreter:latest"
code: Optional[str] = None code: Optional[str] = None
user_dockerfile_path: Optional[str] = None user_dockerfile_path: Optional[str] = None
user_docker_base_url: Optional[str] = None
unsafe_mode: bool = False unsafe_mode: bool = False
@staticmethod @staticmethod
@@ -39,7 +40,7 @@ class CodeInterpreterTool(BaseTool):
""" """
Verify if the Docker image is available. Optionally use a user-provided Dockerfile. Verify if the Docker image is available. Optionally use a user-provided Dockerfile.
""" """
client = docker.from_env() client = docker.from_env() if self.user_docker_base_url != None else docker.DockerClient(base_url=self.user_docker_base_url)
try: try:
client.images.get(self.default_image_tag) client.images.get(self.default_image_tag)