Skip to content

Commit 82fb58d

Browse files
zhangxu0307ShilinHeliqul
authored
Xz/docker run (#218)
run taskweaver in a docker container --------- Co-authored-by: Shilin HE <[email protected]> Co-authored-by: Liqun Li <[email protected]> Co-authored-by: Liqun Li <[email protected]>
1 parent 99f1803 commit 82fb58d

19 files changed

+344
-13
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Unlike many agent frameworks that only track the chat history with LLMs in text,
2323

2424

2525
## 🆕 News
26+
- 📅2024-03-28: TaskWeaver now offers all-in-one Docker image, providing a convenient one-stop experience for users. Please check the [docker](https://microsoft.github.io/TaskWeaver/docs/usage/docker) for more details.🐳
2627
- 📅2024-03-27: TaskWeaver now switches to `container` mode by default for code execution. Please check the [code execution](https://microsoft.github.io/TaskWeaver/docs/advanced/code_execution) for more details.🐳
2728
- 📅2024-03-07: TaskWeaver now supports configuration of different LLMs for various components, such as the Planner and CodeInterpreter. Please check the [multi-llm](https://microsoft.github.io/TaskWeaver/docs/llms/multi-llm) for more details.🔗
2829
- 📅2024-03-04: TaskWeaver now supports a [container](https://microsoft.github.io/TaskWeaver/docs/advanced/code_execution) mode, which provides a more secure environment for code execution.🐳
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
FROM python:3.10-slim
2+
3+
RUN python3 -m pip install --upgrade pip
4+
5+
RUN apt-get update && \
6+
apt-get install -y git && \
7+
apt-get clean && \
8+
rm -rf /var/lib/apt/lists/*
9+
10+
WORKDIR /app
11+
RUN useradd -m taskweaver
12+
RUN chown taskweaver:taskweaver /app
13+
USER taskweaver
14+
15+
COPY --chown=taskweaver:taskweaver requirements.txt .
16+
RUN pip install --no-cache-dir --no-warn-script-location --user -r requirements.txt
17+
18+
RUN pip install --no-cache-dir --no-warn-script-location chainlit
19+
20+
# Define a build argument
21+
ARG WITH_WEB_SEARCH=true
22+
23+
# Copy the model downloader script
24+
COPY --chown=taskweaver:taskweaver docker/all_in_one_container/model_downloader.py .
25+
# Install the web search dependencies
26+
RUN if [ "$WITH_WEB_SEARCH" = "true" ]; then \
27+
pip install --no-cache-dir --no-warn-script-location "duckduckgo_search>=5.1.0" \
28+
"langchain>=0.1.4" \
29+
"langchain-community>=0.0.16" \
30+
"beautifulsoup4>=4.12.2" \
31+
"html2text>=2020.1.16" \
32+
"faiss-cpu>=1.8.0" \
33+
"sentence-transformers>=2.6.0"; \
34+
python model_downloader.py; \
35+
fi
36+
37+
COPY --chown=taskweaver:taskweaver taskweaver taskweaver
38+
COPY --chown=taskweaver:taskweaver project project
39+
COPY --chown=taskweaver:taskweaver docker/all_in_one_container/taskweaver_config.json project/taskweaver_config.json
40+
COPY --chown=taskweaver:taskweaver playground playground
41+
42+
ENV EXECUTION_SERVICE_KERNEL_MODE="local"
43+
44+
CMD ["sh", "-c", "python -m taskweaver -p ./project"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from sentence_transformers import SentenceTransformer
2+
3+
# Specify the model name
4+
model_name = "all-MiniLM-L6-v2"
5+
6+
# Download and cache the model
7+
model = SentenceTransformer(model_name)
8+
print(f"Downloaded and cached model {model_name}")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"session.roles": ["planner", "code_interpreter", "web_search"]}

docker/ces_container/Dockerfile

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Use the official Python 3.10 image as the base image
2+
FROM python:3.10-slim
3+
4+
WORKDIR /app
5+
6+
RUN useradd -m taskweaver
7+
8+
# Set the working directory to /app
9+
RUN chown taskweaver:taskweaver /app
10+
11+
USER taskweaver
12+
13+
# Copy the requrements file
14+
COPY --chown=taskweaver:taskweaver requirements.txt .
15+
RUN pip install --no-cache-dir --no-warn-script-location --user -r requirements.txt
16+
17+
# TODO: Install additional packages for plugins
18+
19+
# Copy the project code
20+
COPY --chown=taskweaver:taskweaver taskweaver/ces /app/taskweaver/ces
21+
COPY --chown=taskweaver:taskweaver taskweaver/plugin /app/taskweaver/plugin
22+
COPY --chown=taskweaver:taskweaver taskweaver/module /app/taskweaver/module
23+
COPY --chown=taskweaver:taskweaver taskweaver/__init__.py /app/taskweaver/__init__.py
24+
25+
ENV PYTHONPATH "${PYTHONPATH}:/app"
26+
27+
CMD ["python", "-m", "taskweaver.ces.kernel.launcher"]
28+
29+

scripts/build_all_in_one.ps1

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
param(
2+
[Parameter(Mandatory=$true)]
3+
[string]$WithWebSearch="false"
4+
)
5+
6+
$scriptDirectory = $PSScriptRoot
7+
Write-Host "The script directory is: $scriptDirectory"
8+
9+
$version = "0.1"
10+
$imageName = "taskweavercontainers/taskweaver-all-in-one"
11+
# generate the image name with the web search option
12+
13+
14+
if ($WithWebSearch -eq "true") {
15+
$imageFullName = "${imageName}:${version}-ws"
16+
$latestImageName = "${imageName}:latest-ws"
17+
Set-Content -Path "..\docker\all_in_one_container\taskweaver_config.json" -Value '{"session.roles": ["planner", "code_interpreter", "web_search"]}'
18+
} else {
19+
$imageFullName = "${imageName}:${version}"
20+
$latestImageName = "${imageName}:latest"
21+
Set-Content -Path "..\docker\all_in_one_container\taskweaver_config.json" -Value '{"session.roles": ["planner", "code_interpreter"]}'
22+
}
23+
24+
$taskweaverPath = Join-Path -Path $scriptDirectory -ChildPath "..\taskweaver"
25+
$dockerfilePath = Join-Path -Path $scriptDirectory -ChildPath "..\docker\all_in_one_container\Dockerfile"
26+
$contextPath = Join-Path -Path $scriptDirectory -ChildPath "..\"
27+
28+
if (Test-Path $taskweaverPath) {
29+
Write-Host "Found module files from $taskweaverPath"
30+
Write-Host "Dockerfile path: $dockerfilePath"
31+
Write-Host "Context path: $contextPath"
32+
} else {
33+
Write-Host "Local files not found."
34+
exit 1
35+
}
36+
37+
# Build the Docker image
38+
docker build --build-arg WITH_WEB_SEARCH=$WithWebSearch -t $imageFullName -f $dockerfilePath $contextPath
39+
40+
# Tag the image
41+
docker tag $imageFullName $latestImageName

scripts/build_all_in_one.sh

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
3+
# Usage: ./script.sh --with-web-search=true
4+
# Default value for with web search option
5+
WithWebSearch=false
6+
7+
for i in "$@"
8+
do
9+
case $i in
10+
--with-web-search=*)
11+
WithWebSearch="${i#*=}"
12+
shift # past argument=value
13+
;;
14+
*)
15+
# unknown option
16+
;;
17+
esac
18+
done
19+
20+
scriptDirectory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
21+
echo "The script directory is: $scriptDirectory"
22+
23+
version="0.1"
24+
imageName="taskweavercontainers/taskweaver-all-in-one"
25+
26+
# Generate the image name with the web search option
27+
if [ "$WithWebSearch" == "true" ]; then
28+
imageFullName="${imageName}:${version}-ws"
29+
latestImageName="${imageName}:latest-ws"
30+
echo '{"session.roles": ["planner", "code_interpreter", "web_search"]}' > "../docker/all_in_one_container/taskweaver_config.json"
31+
else
32+
imageFullName="${imageName}:${version}"
33+
latestImageName="${imageName}:latest"
34+
echo '{"session.roles": ["planner", "code_interpreter"]}' > "../docker/all_in_one_container/taskweaver_config.json"
35+
fi
36+
37+
taskweaverPath="$scriptDirectory/../taskweaver"
38+
dockerfilePath="$scriptDirectory/../docker/all_in_one_container/Dockerfile"
39+
contextPath="$scriptDirectory/../"
40+
41+
if [ -d "$taskweaverPath" ]; then
42+
echo "Found module files from $taskweaverPath"
43+
echo "Dockerfile path: $dockerfilePath"
44+
echo "Context path: $contextPath"
45+
else
46+
echo "Local files not found."
47+
exit 1
48+
fi
49+
50+
# Build the Docker image
51+
docker build --build-arg WITH_WEB_SEARCH="$WithWebSearch" -t "$imageFullName" -f "$dockerfilePath" "$contextPath"
52+
53+
# Tag the image
54+
docker tag "$imageFullName" "$latestImageName"

scripts/build.ps1 scripts/build_executor.ps1

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ $scriptDirectory = $PSScriptRoot
22
Write-Host "The script directory is: $scriptDirectory"
33

44
$version = "0.1"
5-
$imageName = "taskweavercontainers/taskweaver-executor:$version"
5+
$imageName = "taskweavercontainers/taskweaver-executor"
6+
$imageFullName = "${imageName}:${version}"
7+
68
$taskweaverPath = Join-Path -Path $scriptDirectory -ChildPath "..\taskweaver"
7-
$dockerfilePath = Join-Path -Path $scriptDirectory -ChildPath "..\ces_container\Dockerfile"
9+
$dockerfilePath = Join-Path -Path $scriptDirectory -ChildPath "..\docker\ces_container\Dockerfile"
810
$contextPath = Join-Path -Path $scriptDirectory -ChildPath "..\"
911

1012
if (Test-Path $taskweaverPath) {
@@ -17,7 +19,11 @@ if (Test-Path $taskweaverPath) {
1719
}
1820

1921
# Build the Docker image
20-
docker build -t $imageName -f $dockerfilePath $contextPath
22+
docker build -t $imageFullName -f $dockerfilePath $contextPath
23+
24+
# Tag the image
25+
docker tag $imageFullName "${imageName}:latest"
26+
```
2127

2228
# Tag the image
2329
docker tag $imageName taskweavercontainers/taskweaver-executor:latest

scripts/build.sh scripts/build_executor.sh

+12-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ scriptDirectory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
55
echo "The script directory is: $scriptDirectory"
66

77
version="0.1"
8-
imageName="taskweavercontainers/taskweaver-executor:$version"
8+
imageName="taskweavercontainers/taskweaver-executor"
9+
imageFullName="$imageName:$version"
10+
911
taskweaverPath="$scriptDirectory/../taskweaver"
10-
dockerfilePath="$scriptDirectory/../ces_container/Dockerfile"
12+
dockerfilePath="$scriptDirectory/../docker/ces_container/Dockerfile"
1113
contextPath="$scriptDirectory/../"
1214

1315
if [ -d "$taskweaverPath" ]; then
@@ -20,7 +22,14 @@ else
2022
fi
2123

2224
# Build the Docker image
25+
<<<<<<< HEAD:scripts/build_executor.sh
26+
docker build -t "$imageFullName" -f "$dockerfilePath" "$contextPath"
27+
28+
# Tag the image
29+
docker tag "$imageFullName" "$imageName:latest"
30+
=======
2331
docker build -t "$imageName" -f "$dockerfilePath" "$contextPath"
2432

2533
# Tag the image
26-
docker tag "$imageName" taskweavercontainers/taskweaver-executor:latest
34+
docker tag "$imageName" taskweavercontainers/taskweaver-executor:latest
35+
>>>>>>> 99f1803e9fa8d55c5c739b42baf35a2021d92db1:scripts/build.sh

taskweaver/ext_role/web_explorer/web_explorer.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ def __init__(
3636

3737
self.logger = logger
3838
self.config = config
39-
self.vision_planner: VisionPlanner = None
40-
self.driver: SeleniumDriver = None
39+
self.vision_planner = None
40+
self.driver = None
4141

4242
def initialize(self):
4343
try:
4444
from taskweaver.ext_role.web_explorer.driver import SeleniumDriver
4545
from taskweaver.ext_role.web_explorer.planner import VisionPlanner
46-
46+
4747
config = read_yaml(self.config.config_file_path)
4848
GPT4V_KEY = os.environ.get("GPT4V_KEY")
4949
GPT4V_ENDPOINT = os.environ.get("GPT4V_ENDPOINT")
File renamed without changes.
File renamed without changes.
File renamed without changes.

website/docs/advanced/code_execution.md

+44
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,53 @@ there are a few prerequisites:
3535
- A Docker image is built and available on the host machine for code execution.
3636
- The `execution_service.kernel_mode` parameter is set to `container` in the `taskweaver_config.json` file.
3737

38+
Once the code repository is cloned to your local machine, you can build the Docker image
39+
by running the following command in the root directory of the code repository:
40+
41+
```bash
42+
cd scripts
43+
44+
# based on your OS
45+
./build_executor.ps1 # for Windows
46+
./build_executor.sh # for Linux or macOS
47+
```
48+
49+
After the Docker image is built, you can run `docker images` to check if a Docker image
50+
named `executor_container` is available.
51+
If the prerequisite is met, you can now run TaskWeaver in the `container` mode.
52+
3853
After running TaskWeaver in the `container` mode, you can check if the container is running by running `docker ps`.
3954
You should see a container of image `taskweavercontainers/taskweaver-executor` running after executing some code.
4055

56+
## How to customize the Docker image for code execution
57+
58+
You may want to customize the Docker image for code execution to include additional packages or libraries, especially
59+
for your developed plugins. The current Docker image for code execution is `taskweavercontainers/taskweaver-executor`, which
60+
only includes the dependencies specified in the `TaskWeaver/requirements.txt` file. To customize the Docker image, you need to
61+
modify the `Dockerfile` at `TaskWeaver/docker/ces_container/Dockerfile` and rebuild the Docker image.
62+
63+
When you open the `Dockerfile`, you will see the following content, and you can add additional packages or libraries
64+
by adding the corresponding `RUN` command. In this example, we add the `sentence-transformers` package to the Docker image.
65+
66+
```Dockerfile
67+
FROM python:3.10-slim
68+
...
69+
# TODO: Install additional packages for plugins
70+
RUN pip install --no-cache-dir --no-warn-script-location --user sentence-transformers
71+
...
72+
```
73+
Then, you need to rebuild the Docker image by running the `build_executor.sh` script at `TaskWeaver/scripts/build_executor.sh`
74+
or `TaskWeaver/scripts/build.ps1` depending on your operating system.
75+
76+
```bash
77+
cd TaskWeaver/scripts
78+
./build_executor.sh
79+
# or ./build_executor.ps1 if you are using Windows
80+
```
81+
82+
If you have successfully rebuilt the Docker image, you can check the new image by running `docker images`.
83+
After building the Docker image, you need to restart the TaskWeaver agent to use the new Docker image.
84+
4185
## Limitations of the `container` Mode
4286

4387
The `container` mode is more secure than the `local` mode, but it also has some limitations:

website/docs/advanced/telemetry.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ to a [Prometheus](https://prometheus.io/) backend.
7373

7474
You can run the following command to set up the infrastructure:
7575
```bash
76-
cd /TaskWeaver/tracing_configure
76+
cd /TaskWeaver/tracing
7777
docker-compose up
7878
```
7979
You shall see a bunch of logs from the containers.

website/docs/configurations/overview.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,8 @@ The following table lists the parameters in the configuration file:
4242
> models later than 1106. If you are using an older version of OpenAI model, you need to set the `llm.response_format`
4343
> to `null`.
4444
45-
> 💡 Read [this](../advanced/compression.md) for more information for `planner.prompt_compression`
46-
> and `code_generator.prompt_compression`.
45+
> 💡 Read [this](../advanced/compression.md) for more information for `planner.prompt_compression` and `code_generator.prompt_compression`.
46+
47+
> 💡 We support to set configurations via environment variables. You need to transform the configuration key to uppercase and replace the dot with underscore.
48+
For example, `llm.model` should be set as `LLM_MODEL`, `llm.api_base` should be set as `LLM_API_BASE`, etc.
49+

0 commit comments

Comments
 (0)