Skip to content

Commit cdd5ea7

Browse files
committed
update docker build
1 parent 86e2366 commit cdd5ea7

File tree

3 files changed

+49
-20
lines changed

3 files changed

+49
-20
lines changed

examples/benchmarks/gaia.py

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,39 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14+
"""
15+
GAIA Benchmark Example
16+
17+
Prerequisites:
18+
1. Docker Desktop installed and running
19+
2. Build the Docker image (one-time setup):
20+
cd examples/runtimes/ubuntu_docker_runtime
21+
./manage_camel_docker.sh build
22+
23+
3. Set environment variables in .env:
24+
- OPENAI_API_KEY (or other API keys)
25+
26+
4. Clean up stale containers if needed:
27+
docker stop $(docker ps -q) && docker rm $(docker ps -aq)
28+
"""
1429

30+
from dotenv import load_dotenv
1531

1632
from camel.agents import ChatAgent
1733
from camel.benchmarks import DefaultGAIARetriever, GAIABenchmark
34+
from camel.configs import ChatGPTConfig
35+
from camel.embeddings import AzureEmbedding
1836
from camel.models import ModelFactory
19-
from camel.runtimes import RemoteHttpRuntime
37+
from camel.runtimes import DockerRuntime
2038
from camel.toolkits import CodeExecutionToolkit
2139
from camel.types import ModelPlatformType, ModelType, StorageType
2240

41+
load_dotenv()
42+
2343
retriever = DefaultGAIARetriever(
24-
vector_storage_local_path="local_data2/", storage_type=StorageType.QDRANT
44+
vector_storage_local_path="local_data2/",
45+
storage_type=StorageType.QDRANT,
46+
embedding_model=AzureEmbedding(),
2547
)
2648

2749
benchmark = GAIABenchmark(
@@ -36,9 +58,12 @@
3658

3759

3860
toolkit = CodeExecutionToolkit(verbose=True)
39-
runtime = RemoteHttpRuntime("localhost").add(
61+
runtime = DockerRuntime(
62+
"my-camel", port=0
63+
).add( # port=0 uses random available port
4064
toolkit.get_tools(),
4165
"camel.toolkits.CodeExecutionToolkit",
66+
dict(verbose=True),
4267
)
4368

4469
task_prompt = """
@@ -57,23 +82,27 @@
5782
a string.
5883
""".strip()
5984

60-
tools = runtime.get_tools()
61-
6285
model = ModelFactory.create(
6386
model_platform=ModelPlatformType.DEFAULT,
6487
model_type=ModelType.DEFAULT,
88+
model_config_dict=ChatGPTConfig().as_dict(),
6589
)
6690

91+
# use context manager to auto-cleanup container on exit
92+
with runtime as r:
93+
r.wait()
94+
print("Docker runtime is ready.")
6795

68-
agent = ChatAgent(
69-
task_prompt,
70-
model,
71-
tools=tools,
72-
)
96+
tools = r.get_tools()
97+
agent = ChatAgent(
98+
task_prompt,
99+
model,
100+
tools=tools,
101+
)
73102

74-
result = benchmark.run(agent, "valid", level="all", subset=3)
75-
print("correct:", result["correct"])
76-
print("total:", result["total"])
103+
result = benchmark.run(agent, "valid", level="all", subset=10)
104+
print("correct:", result["correct"])
105+
print("total:", result["total"])
77106

78107
# ruff: noqa: E501
79108
"""

examples/runtimes/ubuntu_docker_runtime/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ RUN pip3 install -e ".[all]"
2424

2525
# Copy API service file
2626
RUN mkdir -p /home
27-
COPY camel/runtime/api.py /home/api.py
27+
COPY camel/runtimes/api.py /home/api.py
2828

2929
# Set Python path and other environment variables
3030
ENV PYTHONPATH=/app/camel

examples/runtimes/ubuntu_docker_runtime/manage_camel_docker.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ build_image() {
3535
cp -r "$CAMEL_ROOT" "$TEMP_DIR/camel_source"
3636

3737
# Ensure API file exists
38-
if [ ! -f "$CAMEL_ROOT/camel/runtime/api.py" ]; then
39-
echo "Error: API file not found at $CAMEL_ROOT/camel/runtime/api.py"
38+
if [ ! -f "$CAMEL_ROOT/camel/runtimes/api.py" ]; then
39+
echo "Error: API file not found at $CAMEL_ROOT/camel/runtimes/api.py"
4040
exit 1
4141
fi
42-
42+
4343
# Copy API file to a known location
4444
mkdir -p "$TEMP_DIR/api"
45-
cp "$CAMEL_ROOT/camel/runtime/api.py" "$TEMP_DIR/api/"
46-
45+
cp "$CAMEL_ROOT/camel/runtimes/api.py" "$TEMP_DIR/api/"
46+
4747
# Modify Dockerfile COPY commands - fix the sed command
4848
sed -i '' 's|COPY ../../../|COPY camel_source/|g' "$TEMP_DIR/Dockerfile"
49-
sed -i '' 's|COPY camel/runtime/api.py|COPY api/api.py|g' "$TEMP_DIR/Dockerfile"
49+
sed -i '' 's|COPY camel/runtimes/api.py|COPY api/api.py|g' "$TEMP_DIR/Dockerfile"
5050

5151
# Build in temporary directory
5252
(cd "$TEMP_DIR" && docker build -t ${FULL_NAME} .)

0 commit comments

Comments
 (0)