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

uv #14

Merged
merged 1 commit into from
Oct 21, 2024
Merged

uv #14

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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.agent_run_venv/
.venv/
__pycache__/
*.py[cod]
*$py.class
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,10 @@ print(result)

## Benchmarks

AgentRun Median execution time is <200ms without dependencies. Dependency installing is usually the bottleneck and depends on the size of package and if the package has many dependencies as well as caching.
AgentRun Median execution time is <200ms without dependencies and ~400ms with 1 "average" dependency like requests. Dependency installing is usually the bottleneck and depends on the size of package and if the package has many dependencies as well as caching.

![benchmarks](<https://pbs.twimg.com/media/GabL6e0XgAA9Two?format=png>)

![benchmarks](<https://pbs.twimg.com/media/GLTDKkLW0AA1jLe?format=png>)


## Development
Expand Down
15 changes: 11 additions & 4 deletions agentrun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,17 @@ def __init__(
and not self.validate_cached_dependencies()
):
raise ValueError("Some cached dependencies are not in the whitelist.")
container = self.client.containers.get(self.container_name)
command = f"pip install uv"
exit_code, output = self.execute_command_in_container(
container, command, timeout=120
)
if exit_code != 0:
raise ValueError("Failed to install uv.")

if self.cached_dependencies:
self.install_cached_dependencies()

class CommandTimeout(Exception):
"""Exception raised when a command execution times out."""

Expand Down Expand Up @@ -293,7 +300,7 @@ def install_dependencies(self, container: Container, dependencies: list) -> str:
return f"Dependency: {dep} is not in the whitelist."
# if we are doing caching, we need to check if the dependencies are already installed
if self.cached_dependencies:
exec_log = container.exec_run(cmd="pip list", workdir="/code")
exec_log = container.exec_run(cmd="uv pip list", workdir="/code")
exit_code, output = exec_log.exit_code, exec_log.output.decode("utf-8")
installed_packages = output.splitlines()
installed_packages = [
Expand All @@ -305,7 +312,7 @@ def install_dependencies(self, container: Container, dependencies: list) -> str:
for dep in dependencies:
if dep.lower() in installed_packages:
continue
command = f"pip install --user {dep}"
command = f"uv pip install {dep} --system"
exit_code, output = self.execute_command_in_container(
container, command, timeout=120
)
Expand All @@ -326,7 +333,7 @@ def uninstall_dependencies(self, container: Container, dependencies: list) -> st
# do not uninstall dependencies that are cached_dependencies
if dep in self.cached_dependencies:
continue
command = f"pip uninstall -y {dep}"
command = f"uv pip uninstall -y {dep}"
exit_code, output = self.execute_command_in_container(
container, command, timeout=120
)
Expand Down
Binary file added docs/assets/benchmarkv2.5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,10 @@ print(result)

## Benchmarks

AgentRun Median execution time is <200ms without dependencies. Dependency installing is usually the bottleneck and depends on the size of package and if the package has many dependencies as well as caching.
AgentRun Median execution time is <200ms without dependencies and ~400ms with 1 "average" dependency like requests. Dependency installing is usually the bottleneck and depends on the size of package and if the package has many dependencies as well as caching.

![benchmarks](<https://pbs.twimg.com/media/GabL6e0XgAA9Two?format=png>)

![benchmarks](<https://pbs.twimg.com/media/GLTDKkLW0AA1jLe?format=png>)


## Development
Expand Down
4 changes: 4 additions & 0 deletions docs/release_notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## V0.2.5(10-21-2024)
- Added uv as the dependency manager
- improved performance and execution time through uv

## V0.2.3(04-20-2024)
- Added llama-3 example
- Cleaned up API dependencies
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "agentrun"
version = "0.2.4"
version = "0.2.5"
description = "The easiest way to run AI or user generated python code safely in a docker container"
readme = "README.md"
requires-python = ">=3.10"
Expand Down
5 changes: 3 additions & 2 deletions tests/test_agentrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,10 @@ def test_dependency_benchmark(benchmark, docker_container):
result = benchmark(
execute_code_in_container_benchmark,
runner=runner,
code="import numpy as np\nprint(np.array([1, 2, 3]))",
# use requests
code="import requests\nprint(requests.get('https://example.com').status_code)",
)
assert result == "[1 2 3]\n"
assert result == "200\n"


def test_exception_benchmark(benchmark, docker_container):
Expand Down