add terminal demo
Browse files- owl/run_terminal.py +116 -0
- owl/run_terminal_zh.py +116 -0
owl/run_terminal.py
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
from dotenv import load_dotenv
|
15 |
+
|
16 |
+
from camel.models import ModelFactory
|
17 |
+
from camel.toolkits import (
|
18 |
+
SearchToolkit,
|
19 |
+
WebToolkit,
|
20 |
+
FileWriteToolkit,
|
21 |
+
TerminalToolkit
|
22 |
+
)
|
23 |
+
from camel.types import ModelPlatformType, ModelType
|
24 |
+
from camel.logger import set_log_level
|
25 |
+
|
26 |
+
from utils import OwlRolePlaying, run_society
|
27 |
+
|
28 |
+
load_dotenv()
|
29 |
+
set_log_level(level="DEBUG")
|
30 |
+
|
31 |
+
|
32 |
+
def construct_society(question: str) -> OwlRolePlaying:
|
33 |
+
r"""Construct a society of agents based on the given question.
|
34 |
+
|
35 |
+
Args:
|
36 |
+
question (str): The task or question to be addressed by the society.
|
37 |
+
|
38 |
+
Returns:
|
39 |
+
OwlRolePlaying: A configured society of agents ready to address the
|
40 |
+
question.
|
41 |
+
"""
|
42 |
+
|
43 |
+
# Create models for different components
|
44 |
+
models = {
|
45 |
+
"user": ModelFactory.create(
|
46 |
+
model_platform=ModelPlatformType.OPENAI,
|
47 |
+
model_type=ModelType.GPT_4O,
|
48 |
+
model_config_dict={"temperature": 0},
|
49 |
+
),
|
50 |
+
"assistant": ModelFactory.create(
|
51 |
+
model_platform=ModelPlatformType.OPENAI,
|
52 |
+
model_type=ModelType.GPT_4O,
|
53 |
+
model_config_dict={"temperature": 0},
|
54 |
+
),
|
55 |
+
"web": ModelFactory.create(
|
56 |
+
model_platform=ModelPlatformType.OPENAI,
|
57 |
+
model_type=ModelType.GPT_4O,
|
58 |
+
model_config_dict={"temperature": 0},
|
59 |
+
),
|
60 |
+
"planning": ModelFactory.create(
|
61 |
+
model_platform=ModelPlatformType.OPENAI,
|
62 |
+
model_type=ModelType.GPT_4O,
|
63 |
+
model_config_dict={"temperature": 0},
|
64 |
+
),
|
65 |
+
}
|
66 |
+
|
67 |
+
# Configure toolkits
|
68 |
+
tools = [
|
69 |
+
*WebToolkit(
|
70 |
+
headless=False, # Set to True for headless mode (e.g., on remote servers)
|
71 |
+
web_agent_model=models["web"],
|
72 |
+
planning_agent_model=models["planning"],
|
73 |
+
).get_tools(),
|
74 |
+
SearchToolkit().search_duckduckgo,
|
75 |
+
SearchToolkit().search_wiki,
|
76 |
+
*FileWriteToolkit(output_dir="./").get_tools(),
|
77 |
+
*TerminalToolkit().get_tools(),
|
78 |
+
]
|
79 |
+
|
80 |
+
# Configure agent roles and parameters
|
81 |
+
user_agent_kwargs = {"model": models["user"]}
|
82 |
+
assistant_agent_kwargs = {"model": models["assistant"], "tools": tools}
|
83 |
+
|
84 |
+
# Configure task parameters
|
85 |
+
task_kwargs = {
|
86 |
+
"task_prompt": question,
|
87 |
+
"with_task_specify": False,
|
88 |
+
}
|
89 |
+
|
90 |
+
# Create and return the society
|
91 |
+
society = OwlRolePlaying(
|
92 |
+
**task_kwargs,
|
93 |
+
user_role_name="user",
|
94 |
+
user_agent_kwargs=user_agent_kwargs,
|
95 |
+
assistant_role_name="assistant",
|
96 |
+
assistant_agent_kwargs=assistant_agent_kwargs,
|
97 |
+
)
|
98 |
+
|
99 |
+
return society
|
100 |
+
|
101 |
+
|
102 |
+
def main():
|
103 |
+
r"""Main function to run the OWL system with an example question."""
|
104 |
+
# Example research question
|
105 |
+
question = "Open Google Search, summarize the number of GitHub stars, forks, etc., of the camel framework of camel-ai, and write the numbers into a Python file using the plot package, save it locally, and execute the Python file with the local terminal to display the graph for me."
|
106 |
+
|
107 |
+
# Construct and run the society
|
108 |
+
society = construct_society(question)
|
109 |
+
answer, chat_history, token_count = run_society(society)
|
110 |
+
|
111 |
+
# Output the result
|
112 |
+
print(f"\033[94mAnswer: {answer}\nChat History: {chat_history}\ntoken_count:{token_count}\033[0m")
|
113 |
+
|
114 |
+
|
115 |
+
if __name__ == "__main__":
|
116 |
+
main()
|
owl/run_terminal_zh.py
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
from dotenv import load_dotenv
|
15 |
+
|
16 |
+
from camel.models import ModelFactory
|
17 |
+
from camel.toolkits import (
|
18 |
+
SearchToolkit,
|
19 |
+
WebToolkit,
|
20 |
+
FileWriteToolkit,
|
21 |
+
TerminalToolkit
|
22 |
+
)
|
23 |
+
from camel.types import ModelPlatformType, ModelType
|
24 |
+
from camel.logger import set_log_level
|
25 |
+
|
26 |
+
from utils import OwlRolePlaying, run_society
|
27 |
+
|
28 |
+
load_dotenv()
|
29 |
+
set_log_level(level="DEBUG")
|
30 |
+
|
31 |
+
|
32 |
+
def construct_society(question: str) -> OwlRolePlaying:
|
33 |
+
r"""Construct a society of agents based on the given question.
|
34 |
+
|
35 |
+
Args:
|
36 |
+
question (str): The task or question to be addressed by the society.
|
37 |
+
|
38 |
+
Returns:
|
39 |
+
OwlRolePlaying: A configured society of agents ready to address the
|
40 |
+
question.
|
41 |
+
"""
|
42 |
+
|
43 |
+
# Create models for different components
|
44 |
+
models = {
|
45 |
+
"user": ModelFactory.create(
|
46 |
+
model_platform=ModelPlatformType.OPENAI,
|
47 |
+
model_type=ModelType.GPT_4O,
|
48 |
+
model_config_dict={"temperature": 0},
|
49 |
+
),
|
50 |
+
"assistant": ModelFactory.create(
|
51 |
+
model_platform=ModelPlatformType.OPENAI,
|
52 |
+
model_type=ModelType.GPT_4O,
|
53 |
+
model_config_dict={"temperature": 0},
|
54 |
+
),
|
55 |
+
"web": ModelFactory.create(
|
56 |
+
model_platform=ModelPlatformType.OPENAI,
|
57 |
+
model_type=ModelType.GPT_4O,
|
58 |
+
model_config_dict={"temperature": 0},
|
59 |
+
),
|
60 |
+
"planning": ModelFactory.create(
|
61 |
+
model_platform=ModelPlatformType.OPENAI,
|
62 |
+
model_type=ModelType.GPT_4O,
|
63 |
+
model_config_dict={"temperature": 0},
|
64 |
+
),
|
65 |
+
}
|
66 |
+
|
67 |
+
# Configure toolkits
|
68 |
+
tools = [
|
69 |
+
*WebToolkit(
|
70 |
+
headless=False, # Set to True for headless mode (e.g., on remote servers)
|
71 |
+
web_agent_model=models["web"],
|
72 |
+
planning_agent_model=models["planning"],
|
73 |
+
).get_tools(),
|
74 |
+
SearchToolkit().search_duckduckgo,
|
75 |
+
SearchToolkit().search_wiki,
|
76 |
+
*FileWriteToolkit(output_dir="./").get_tools(),
|
77 |
+
*TerminalToolkit().get_tools(),
|
78 |
+
]
|
79 |
+
|
80 |
+
# Configure agent roles and parameters
|
81 |
+
user_agent_kwargs = {"model": models["user"]}
|
82 |
+
assistant_agent_kwargs = {"model": models["assistant"], "tools": tools}
|
83 |
+
|
84 |
+
# Configure task parameters
|
85 |
+
task_kwargs = {
|
86 |
+
"task_prompt": question,
|
87 |
+
"with_task_specify": False,
|
88 |
+
}
|
89 |
+
|
90 |
+
# Create and return the society
|
91 |
+
society = OwlRolePlaying(
|
92 |
+
**task_kwargs,
|
93 |
+
user_role_name="user",
|
94 |
+
user_agent_kwargs=user_agent_kwargs,
|
95 |
+
assistant_role_name="assistant",
|
96 |
+
assistant_agent_kwargs=assistant_agent_kwargs,
|
97 |
+
)
|
98 |
+
|
99 |
+
return society
|
100 |
+
|
101 |
+
|
102 |
+
def main():
|
103 |
+
r"""Main function to run the OWL system with an example question."""
|
104 |
+
# Example research question
|
105 |
+
question = "打开谷歌搜索,总结一下camel-ai的camel框架的github star、fork数目等,并把数字用plot包写成python文件保存到本地,用本地终端执行python文件显示图出来给我"
|
106 |
+
|
107 |
+
# Construct and run the society
|
108 |
+
society = construct_society(question)
|
109 |
+
answer, chat_history, token_count = run_society(society)
|
110 |
+
|
111 |
+
# Output the result
|
112 |
+
print(f"\033[94mAnswer: {answer}\nChat History: {chat_history}\ntoken_count:{token_count}\033[0m")
|
113 |
+
|
114 |
+
|
115 |
+
if __name__ == "__main__":
|
116 |
+
main()
|