Skip to content

Commit c5f4b2f

Browse files
committed
support gemini 2.5 pro and add example
1 parent 6fe3ce7 commit c5f4b2f

File tree

8 files changed

+162
-6
lines changed

8 files changed

+162
-6
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ Our vision is to revolutionize how AI agents collaborate to solve real-world tas
126126
</p>
127127
</div>
128128

129+
- **[2025.03.26]**: Supported Gemini 2.5 Pro, added example run code
129130
- **[2025.03.21]**: Integrated OpenRouter model platform, fix bug with Gemini tool calling
130131
- **[2025.03.20]**: Accept header in MCP Toolkit, support automatic playwright installation
131132
- **[2025.03.16]**: Support Bing search, Baidu search
@@ -383,6 +384,9 @@ python examples/run_deepseek_zh.py
383384
# Run with other OpenAI-compatible models
384385
python examples/run_openai_compatible_model.py
385386

387+
# Run with Gemini model
388+
python examples/run_gemini.py
389+
386390
# Run with Azure OpenAI
387391
python examples/run_azure_openai.py
388392

README_zh.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
</p>
127127
</div>
128128

129+
- **[2025.03.26]**: 支持Gemini 2.5 Pro模型,添加示例运行代码
129130
- **[2025.03.21]**: 集成OpenRouter模型平台,修复Gemini工具调用的bug
130131
- **[2025.03.20]**: 在MCP工具包中添加Accept头部,支持自动安装playwright
131132
- **[2025.03.16]**: 支持必应搜索、百度搜索
@@ -379,6 +380,9 @@ python examples/run_qwen_zh.py
379380
# 使用 Deepseek 模型运行
380381
python examples/run_deepseek_zh.py
381382

383+
# 使用 Gemini 模型运行
384+
python examples/run_gemini.py
385+
382386
# 使用其他 OpenAI 兼容模型运行
383387
python examples/run_openai_compatible_model.py
384388

examples/run_gemini.py

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14+
import sys
15+
import pathlib
16+
from dotenv import load_dotenv
17+
from camel.models import ModelFactory
18+
from camel.toolkits import (
19+
AudioAnalysisToolkit,
20+
CodeExecutionToolkit,
21+
ExcelToolkit,
22+
ImageAnalysisToolkit,
23+
SearchToolkit,
24+
VideoAnalysisToolkit,
25+
BrowserToolkit,
26+
FileWriteToolkit,
27+
)
28+
from camel.types import ModelPlatformType, ModelType
29+
from camel.logger import set_log_level
30+
from camel.societies import RolePlaying
31+
32+
from owl.utils import run_society, DocumentProcessingToolkit
33+
34+
base_dir = pathlib.Path(__file__).parent.parent
35+
env_path = base_dir / "owl" / ".env"
36+
load_dotenv(dotenv_path=str(env_path))
37+
38+
set_log_level(level="DEBUG")
39+
40+
41+
def construct_society(question: str) -> RolePlaying:
42+
r"""Construct a society of agents based on the given question.
43+
44+
Args:
45+
question (str): The task or question to be addressed by the society.
46+
47+
Returns:
48+
RolePlaying: A configured society of agents ready to address the question.
49+
"""
50+
51+
# Create models for different components
52+
models = {
53+
"user": ModelFactory.create(
54+
model_platform=ModelPlatformType.GEMINI,
55+
model_type=ModelType.GEMINI_2_5_PRO_EXP,
56+
model_config_dict={"temperature": 0},
57+
),
58+
"assistant": ModelFactory.create(
59+
model_platform=ModelPlatformType.GEMINI,
60+
model_type=ModelType.GEMINI_2_5_PRO_EXP,
61+
model_config_dict={"temperature": 0},
62+
),
63+
"browsing": ModelFactory.create(
64+
model_platform=ModelPlatformType.GEMINI,
65+
model_type=ModelType.GEMINI_2_5_PRO_EXP,
66+
model_config_dict={"temperature": 0},
67+
),
68+
"planning": ModelFactory.create(
69+
model_platform=ModelPlatformType.GEMINI,
70+
model_type=ModelType.GEMINI_2_5_PRO_EXP,
71+
model_config_dict={"temperature": 0},
72+
),
73+
"video": ModelFactory.create(
74+
model_platform=ModelPlatformType.GEMINI,
75+
model_type=ModelType.GEMINI_2_5_PRO_EXP,
76+
model_config_dict={"temperature": 0},
77+
),
78+
"image": ModelFactory.create(
79+
model_platform=ModelPlatformType.GEMINI,
80+
model_type=ModelType.GEMINI_2_5_PRO_EXP,
81+
model_config_dict={"temperature": 0},
82+
),
83+
"document": ModelFactory.create(
84+
model_platform=ModelPlatformType.GEMINI,
85+
model_type=ModelType.GEMINI_2_5_PRO_EXP,
86+
model_config_dict={"temperature": 0},
87+
),
88+
}
89+
90+
# Configure toolkits
91+
tools = [
92+
*BrowserToolkit(
93+
headless=False, # Set to True for headless mode (e.g., on remote servers)
94+
web_agent_model=models["browsing"],
95+
planning_agent_model=models["planning"],
96+
).get_tools(),
97+
*CodeExecutionToolkit(sandbox="subprocess", verbose=True).get_tools(),
98+
*ImageAnalysisToolkit(model=models["image"]).get_tools(),
99+
SearchToolkit().search_duckduckgo,
100+
SearchToolkit().search_google, # Comment this out if you don't have google search
101+
SearchToolkit().search_wiki,
102+
*ExcelToolkit().get_tools(),
103+
*DocumentProcessingToolkit(model=models["document"]).get_tools(),
104+
*FileWriteToolkit(output_dir="./").get_tools(),
105+
]
106+
107+
# Configure agent roles and parameters
108+
user_agent_kwargs = {"model": models["user"]}
109+
assistant_agent_kwargs = {"model": models["assistant"], "tools": tools}
110+
111+
# Configure task parameters
112+
task_kwargs = {
113+
"task_prompt": question,
114+
"with_task_specify": False,
115+
}
116+
117+
# Create and return the society
118+
society = RolePlaying(
119+
**task_kwargs,
120+
user_role_name="user",
121+
user_agent_kwargs=user_agent_kwargs,
122+
assistant_role_name="assistant",
123+
assistant_agent_kwargs=assistant_agent_kwargs,
124+
)
125+
126+
return society
127+
128+
129+
def main():
130+
r"""Main function to run the OWL system with an example question."""
131+
# Default research question
132+
default_task = "Navigate to Amazon.com and identify one product that is attractive to coders. Please provide me with the product name and price. No need to verify your answer."
133+
134+
# Override default task if command line argument is provided
135+
task = sys.argv[1] if len(sys.argv) > 1 else default_task
136+
137+
# Construct and run the society
138+
society = construct_society(task)
139+
answer, chat_history, token_count = run_society(society)
140+
141+
# Output the result
142+
print(f"\033[94mAnswer: {answer}\033[0m")
143+
144+
145+
if __name__ == "__main__":
146+
main()

owl/webapp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ def process_message(role, content):
244244
MODULE_DESCRIPTIONS = {
245245
"run": "Default mode: Using OpenAI model's default agent collaboration mode, suitable for most tasks.",
246246
"run_mini": "Using OpenAI model with minimal configuration to process tasks",
247+
"run_gemini": "Using Gemini model to process tasks",
247248
"run_deepseek_zh": "Using deepseek model to process Chinese tasks",
248249
"run_openai_compatible_model": "Using openai compatible model to process tasks",
249250
"run_ollama": "Using local ollama model to process tasks",

owl/webapp_zh.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ def process_message(role, content):
244244
MODULE_DESCRIPTIONS = {
245245
"run": "默认模式:使用OpenAI模型的默认的智能体协作模式,适合大多数任务。",
246246
"run_mini": "使用使用OpenAI模型最小化配置处理任务",
247+
"run_gemini": "使用 Gemini模型处理任务",
247248
"run_deepseek_zh": "使用deepseek模型处理中文任务",
248249
"run_openai_compatible_model": "使用openai兼容模型处理任务",
249250
"run_ollama": "使用本地ollama模型处理任务",

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ keywords = [
2121
"learning-systems"
2222
]
2323
dependencies = [
24-
"camel-ai[all]==0.2.36",
24+
"camel-ai[all]==0.2.37",
2525
"chunkr-ai>=0.0.41",
2626
"docx2markdown>=0.1.1",
2727
"gradio>=3.50.2",

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
camel-ai[all]==0.2.36
1+
camel-ai[all]==0.2.37
22
chunkr-ai>=0.0.41
33
docx2markdown>=0.1.1
44
gradio>=3.50.2

uv.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)