Skip to content

Commit eced057

Browse files
author
Olivier Chafik
committed
agent: ensure DATA_DIR exists
skip-checks:true
1 parent d72bd65 commit eced057

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

examples/agent/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ The agent can use tools written in Python, or (soon) exposed under OpenAPI endpo
108108
so we provide a script to run them in a Docker-sandboxed environment, exposed as an OpenAPI server:
109109

110110
```bash
111-
PORT=9999 examples/openai/run_sandboxed_tools.sh \
111+
# With limactl, the default sandbox location ~/.llama.cpp/sandbox won't be writable
112+
# (see https://github.com/lima-vm/lima/discussions/393)
113+
# export DATA_DIR=/tmp/lima/llama.cpp/sandbox
114+
PORT=9999 examples/agent/run_sandboxed_tools.sh \
112115
examples/agent/tools/unsafe_python_tools.py &
113116

114117
python -m examples.agent \
@@ -127,11 +130,11 @@ so we provide a script to run them in a Docker-sandboxed environment, exposed as
127130

128131
</details>
129132

130-
- [fastify.py](./fastify.py) turns a python module into an OpenAPI endpoint using FastAPI
133+
- [fastify.py](./fastify.py) turns a python module into an [OpenAPI](https://www.openapis.org/) endpoint using [FastAPI](https://fastapi.tiangolo.com/)
131134

132135
- [run_sandboxed_tools.sh](./run_sandboxed_tools.sh) builds and runs a Docker environment with fastify inside it, and exposes its port locally
133136

134-
- Beyond just "tools", output format can be constrained using JSON schemas or Pydantic types
137+
- Beyond just "tools", output format can be constrained using [JSON schemas](https://json-schema.org/) or [Pydantic](https://docs.pydantic.dev/latest/) types
135138

136139
```bash
137140
python -m examples.agent \

examples/agent/fastify.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
This is useful in combination w/ the examples/agent/run_sandboxed_tools.sh
55
'''
6+
import os
67
import fastapi, uvicorn
78
import typer
89
from typing import Type, List
@@ -37,6 +38,7 @@ def main(files: List[str], host: str = '0.0.0.0', port: int = 8000):
3738
for f in files:
3839
bind_functions(app, load_module(f))
3940

41+
print(f'INFO: CWD = {os.getcwd()}')
4042
uvicorn.run(app, host=host, port=port)
4143

4244
if __name__ == '__main__':

examples/agent/run_sandboxed_tools.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ BUILD_DIR=$(mktemp -d)
2020
DATA_DIR="${DATA_DIR:-$HOME/.llama.cpp/sandbox}"
2121
SCRIPT_DIR=$( cd "$(dirname "$0")" ; pwd )
2222

23+
mkdir -p "$DATA_DIR"
24+
2325
REQUIREMENTS_FILE="${REQUIREMENTS_FILE:-}"
2426
if [[ -z "$REQUIREMENTS_FILE" && -f "$script_folder/requirements.txt" ]]; then
2527
REQUIREMENTS_FILE="$script_folder/requirements.txt"
@@ -69,6 +71,6 @@ set -x
6971
docker run \
7072
"$@" \
7173
--mount "type=bind,source=$( realpath "$script_folder" ),target=/src,readonly" \
72-
--mount "type=bind,source=$( realpath "$DATA_DIR" ),target=/data" \
74+
--mount "type=bind,source=$DATA_DIR,target=/data" \
7375
-p "$PORT:$PORT" \
7476
-it "$LLAMA_IMAGE_NAME"

0 commit comments

Comments
 (0)