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

feat: Batch Mode API / Headless #139

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion computer-use-demo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ RUN apt-get update && \
sudo \
mutter \
x11vnc \
wmctrl \
# Python/pyenv reqs
build-essential \
libssl-dev \
Expand Down Expand Up @@ -85,7 +86,8 @@ RUN eval "$(pyenv init -)" && \
ENV PATH="$HOME/.pyenv/shims:$HOME/.pyenv/bin:$PATH"

RUN python -m pip install --upgrade pip==23.1.2 setuptools==58.0.4 wheel==0.40.0 && \
python -m pip config set global.disable-pip-version-check true
python -m pip config set global.disable-pip-version-check true && \
python -m pip install fastapi uvicorn
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be covered by the subsequent line, correct?


# only reinstall if requirements.txt changes
COPY --chown=$USERNAME:$USERNAME computer_use_demo/requirements.txt $HOME/computer_use_demo/requirements.txt
Expand Down
52 changes: 52 additions & 0 deletions computer-use-demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,58 @@ This example shows how to use the Google Cloud Application Default Credentials t

You can also set `GOOGLE_APPLICATION_CREDENTIALS` to use an arbitrary credential file, see the [Google Cloud Authentication documentation](https://cloud.google.com/docs/authentication/application-default-credentials#GAC) for more details.

### Batch Mode on Google Cloud Run

To run in Batch Mode on Google Cloud Run, you can use the following command:

```bash
docker build . -t computer-use-demo
gcloud auth application-default login
export VERTEX_REGION=%your_vertex_region%
export VERTEX_PROJECT_ID=%your_vertex_project_id%
docker run \
-e API_PROVIDER=vertex \
-e CLOUD_ML_REGION=$VERTEX_REGION \
-e ANTHROPIC_VERTEX_PROJECT_ID=$VERTEX_PROJECT_ID \
-e RUN_MODE=batch \
-v $HOME/.config/gcloud/application_default_credentials.json:/home/computeruse/.config/gcloud/application_default_credentials.json \
-p 5900:5900 \
-p 8501:8501 \
-p 6080:6080 \
-p 8080:8080 \
-p 8000:8000 \
-it computer-use-demo
```

To submit a task:

```bash
curl -X POST http://localhost:8000/tasks \
-H "Content-Type: application/json" \
-d '{
"prompt": "Open the Firefox browser and navigate to google.com"
}'
```

To check the status of a task:

```bash
curl http://localhost:8000/tasks | jq '.'
```

To get instance health:

```bash
curl http://localhost:8000/health
```

Notes:
- Set instance concurrency to 1 (this avoids having multiple tasks use the same VNC session)
- Set request timeout per instance to be 3600 seconds (1 hour)
- When running in Google Cloud Run, if the instance is currently processing a task, it will throw 503 errors on all parallel requests (this will cause Google Cloud Run to redirect the task to a different instance, if available)
- Batch Mode is NOT guaranteed to work correctly when run on any other equivalent to Google Cloud Run (e.g., AWS AppRunner) - further development is needed
- When Batch Mode is enabled port 8000 is active and Streamlit is NOT active on port 8080

### Accessing the demo app

Once the container is running, open your browser to [http://localhost:8080](http://localhost:8080) to access the combined interface that includes both the agent chat and desktop view.
Expand Down
Loading