Skip to content

Commit 29bf2f6

Browse files
Merge pull request #14 from Jonathan-Adly/add-uv
uv
2 parents 81ec7ac + 5f6dd22 commit 29bf2f6

File tree

8 files changed

+26
-12
lines changed

8 files changed

+26
-12
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.agent_run_venv/
1+
.venv/
22
__pycache__/
33
*.py[cod]
44
*$py.class

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,10 @@ print(result)
324324

325325
## Benchmarks
326326

327-
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.
327+
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.
328+
329+
![benchmarks](<https://pbs.twimg.com/media/GabL6e0XgAA9Two?format=png>)
328330

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

331332

332333
## Development

agentrun/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,17 @@ def __init__(
7676
and not self.validate_cached_dependencies()
7777
):
7878
raise ValueError("Some cached dependencies are not in the whitelist.")
79+
container = self.client.containers.get(self.container_name)
80+
command = f"pip install uv"
81+
exit_code, output = self.execute_command_in_container(
82+
container, command, timeout=120
83+
)
84+
if exit_code != 0:
85+
raise ValueError("Failed to install uv.")
7986

8087
if self.cached_dependencies:
8188
self.install_cached_dependencies()
82-
89+
8390
class CommandTimeout(Exception):
8491
"""Exception raised when a command execution times out."""
8592

@@ -293,7 +300,7 @@ def install_dependencies(self, container: Container, dependencies: list) -> str:
293300
return f"Dependency: {dep} is not in the whitelist."
294301
# if we are doing caching, we need to check if the dependencies are already installed
295302
if self.cached_dependencies:
296-
exec_log = container.exec_run(cmd="pip list", workdir="/code")
303+
exec_log = container.exec_run(cmd="uv pip list", workdir="/code")
297304
exit_code, output = exec_log.exit_code, exec_log.output.decode("utf-8")
298305
installed_packages = output.splitlines()
299306
installed_packages = [
@@ -305,7 +312,7 @@ def install_dependencies(self, container: Container, dependencies: list) -> str:
305312
for dep in dependencies:
306313
if dep.lower() in installed_packages:
307314
continue
308-
command = f"pip install --user {dep}"
315+
command = f"uv pip install {dep} --system"
309316
exit_code, output = self.execute_command_in_container(
310317
container, command, timeout=120
311318
)
@@ -326,7 +333,7 @@ def uninstall_dependencies(self, container: Container, dependencies: list) -> st
326333
# do not uninstall dependencies that are cached_dependencies
327334
if dep in self.cached_dependencies:
328335
continue
329-
command = f"pip uninstall -y {dep}"
336+
command = f"uv pip uninstall -y {dep}"
330337
exit_code, output = self.execute_command_in_container(
331338
container, command, timeout=120
332339
)

docs/assets/benchmarkv2.5.png

105 KB
Loading

docs/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,10 @@ print(result)
324324

325325
## Benchmarks
326326

327-
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.
327+
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.
328+
329+
![benchmarks](<https://pbs.twimg.com/media/GabL6e0XgAA9Two?format=png>)
328330

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

331332

332333
## Development

docs/release_notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## V0.2.5(10-21-2024)
2+
- Added uv as the dependency manager
3+
- improved performance and execution time through uv
4+
15
## V0.2.3(04-20-2024)
26
- Added llama-3 example
37
- Cleaned up API dependencies

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "agentrun"
3-
version = "0.2.4"
3+
version = "0.2.5"
44
description = "The easiest way to run AI or user generated python code safely in a docker container"
55
readme = "README.md"
66
requires-python = ">=3.10"

tests/test_agentrun.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,10 @@ def test_dependency_benchmark(benchmark, docker_container):
297297
result = benchmark(
298298
execute_code_in_container_benchmark,
299299
runner=runner,
300-
code="import numpy as np\nprint(np.array([1, 2, 3]))",
300+
# use requests
301+
code="import requests\nprint(requests.get('https://example.com').status_code)",
301302
)
302-
assert result == "[1 2 3]\n"
303+
assert result == "200\n"
303304

304305

305306
def test_exception_benchmark(benchmark, docker_container):

0 commit comments

Comments
 (0)