Commit
·
4057aa4
1
Parent(s):
07f79b9
env template update and format fix
Browse files
community_usecase/cooking-assistant/run_gpt4o.py
CHANGED
@@ -1,3 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import logging
|
3 |
import json
|
@@ -13,8 +26,8 @@ from camel.toolkits import (
|
|
13 |
from camel.societies import RolePlaying
|
14 |
from camel.logger import set_log_level, get_logger
|
15 |
|
16 |
-
|
17 |
-
from owl.utils import run_society
|
18 |
import pathlib
|
19 |
|
20 |
base_dir = pathlib.Path(__file__).parent.parent
|
@@ -117,16 +130,26 @@ def analyze_chat_history(chat_history):
|
|
117 |
"message_index": i,
|
118 |
}
|
119 |
tool_calls.append(tool_info)
|
120 |
-
print(
|
121 |
-
|
|
|
|
|
|
|
|
|
122 |
|
123 |
elif message.get("role") == "tool" and "tool_call_id" in message:
|
124 |
for tool_call in tool_calls:
|
125 |
if tool_call.get("call_id") == message.get("tool_call_id"):
|
126 |
result = message.get("content", "")
|
127 |
-
result_summary =
|
128 |
-
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
print(f"Total tool calls found: {len(tool_calls)}")
|
132 |
logger.info(f"Total tool calls found: {len(tool_calls)}")
|
@@ -150,4 +173,4 @@ def run_cooking_companion():
|
|
150 |
|
151 |
|
152 |
if __name__ == "__main__":
|
153 |
-
run_cooking_companion()
|
|
|
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 os
|
15 |
import logging
|
16 |
import json
|
|
|
26 |
from camel.societies import RolePlaying
|
27 |
from camel.logger import set_log_level, get_logger
|
28 |
|
29 |
+
|
30 |
+
from owl.utils import run_society
|
31 |
import pathlib
|
32 |
|
33 |
base_dir = pathlib.Path(__file__).parent.parent
|
|
|
130 |
"message_index": i,
|
131 |
}
|
132 |
tool_calls.append(tool_info)
|
133 |
+
print(
|
134 |
+
f"Tool Call: {function.get('name')} Args: {function.get('arguments')}"
|
135 |
+
)
|
136 |
+
logger.info(
|
137 |
+
f"Tool Call: {function.get('name')} Args: {function.get('arguments')}"
|
138 |
+
)
|
139 |
|
140 |
elif message.get("role") == "tool" and "tool_call_id" in message:
|
141 |
for tool_call in tool_calls:
|
142 |
if tool_call.get("call_id") == message.get("tool_call_id"):
|
143 |
result = message.get("content", "")
|
144 |
+
result_summary = (
|
145 |
+
result[:100] + "..." if len(result) > 100 else result
|
146 |
+
)
|
147 |
+
print(
|
148 |
+
f"Tool Result: {tool_call.get('name')} Return: {result_summary}"
|
149 |
+
)
|
150 |
+
logger.info(
|
151 |
+
f"Tool Result: {tool_call.get('name')} Return: {result_summary}"
|
152 |
+
)
|
153 |
|
154 |
print(f"Total tool calls found: {len(tool_calls)}")
|
155 |
logger.info(f"Total tool calls found: {len(tool_calls)}")
|
|
|
173 |
|
174 |
|
175 |
if __name__ == "__main__":
|
176 |
+
run_cooking_companion()
|
community_usecase/learning-assistant/run_gpt4o.py
CHANGED
@@ -1,3 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import logging
|
3 |
import json
|
@@ -81,11 +94,10 @@ def construct_learning_society(task: str) -> RolePlaying:
|
|
81 |
user_agent_kwargs = {
|
82 |
"model": models["user"],
|
83 |
}
|
84 |
-
|
85 |
assistant_agent_kwargs = {
|
86 |
"model": models["assistant"],
|
87 |
"tools": tools,
|
88 |
-
|
89 |
}
|
90 |
|
91 |
task_kwargs = {
|
@@ -122,16 +134,26 @@ def analyze_chat_history(chat_history):
|
|
122 |
"message_index": i,
|
123 |
}
|
124 |
tool_calls.append(tool_info)
|
125 |
-
print(
|
126 |
-
|
|
|
|
|
|
|
|
|
127 |
|
128 |
elif message.get("role") == "tool" and "tool_call_id" in message:
|
129 |
for tool_call in tool_calls:
|
130 |
if tool_call.get("call_id") == message.get("tool_call_id"):
|
131 |
result = message.get("content", "")
|
132 |
-
result_summary =
|
133 |
-
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
print(f"Total tool calls found: {len(tool_calls)}")
|
137 |
logger.info(f"Total tool calls found: {len(tool_calls)}")
|
@@ -146,7 +168,7 @@ def analyze_chat_history(chat_history):
|
|
146 |
|
147 |
def run_learning_companion(task: str = None):
|
148 |
"""Run the learning companion with the given task.
|
149 |
-
|
150 |
Args:
|
151 |
task (str, optional): The learning task description. Defaults to an example task.
|
152 |
"""
|
@@ -155,15 +177,17 @@ def run_learning_companion(task: str = None):
|
|
155 |
I've also taken a basic statistics course.
|
156 |
I have about 10 hours per week to dedicate to learning. Devise a roadmap for me .
|
157 |
"""
|
158 |
-
|
159 |
society = construct_learning_society(task)
|
160 |
-
|
161 |
from owl.utils import run_society
|
162 |
-
|
|
|
163 |
|
164 |
# Record tool usage history
|
165 |
analyze_chat_history(chat_history)
|
166 |
print(f"\033[94mAnswer: {answer}\033[0m")
|
167 |
|
|
|
168 |
if __name__ == "__main__":
|
169 |
-
run_learning_companion()
|
|
|
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 os
|
15 |
import logging
|
16 |
import json
|
|
|
94 |
user_agent_kwargs = {
|
95 |
"model": models["user"],
|
96 |
}
|
97 |
+
|
98 |
assistant_agent_kwargs = {
|
99 |
"model": models["assistant"],
|
100 |
"tools": tools,
|
|
|
101 |
}
|
102 |
|
103 |
task_kwargs = {
|
|
|
134 |
"message_index": i,
|
135 |
}
|
136 |
tool_calls.append(tool_info)
|
137 |
+
print(
|
138 |
+
f"Tool Call: {function.get('name')} Args: {function.get('arguments')}"
|
139 |
+
)
|
140 |
+
logger.info(
|
141 |
+
f"Tool Call: {function.get('name')} Args: {function.get('arguments')}"
|
142 |
+
)
|
143 |
|
144 |
elif message.get("role") == "tool" and "tool_call_id" in message:
|
145 |
for tool_call in tool_calls:
|
146 |
if tool_call.get("call_id") == message.get("tool_call_id"):
|
147 |
result = message.get("content", "")
|
148 |
+
result_summary = (
|
149 |
+
result[:100] + "..." if len(result) > 100 else result
|
150 |
+
)
|
151 |
+
print(
|
152 |
+
f"Tool Result: {tool_call.get('name')} Return: {result_summary}"
|
153 |
+
)
|
154 |
+
logger.info(
|
155 |
+
f"Tool Result: {tool_call.get('name')} Return: {result_summary}"
|
156 |
+
)
|
157 |
|
158 |
print(f"Total tool calls found: {len(tool_calls)}")
|
159 |
logger.info(f"Total tool calls found: {len(tool_calls)}")
|
|
|
168 |
|
169 |
def run_learning_companion(task: str = None):
|
170 |
"""Run the learning companion with the given task.
|
171 |
+
|
172 |
Args:
|
173 |
task (str, optional): The learning task description. Defaults to an example task.
|
174 |
"""
|
|
|
177 |
I've also taken a basic statistics course.
|
178 |
I have about 10 hours per week to dedicate to learning. Devise a roadmap for me .
|
179 |
"""
|
180 |
+
|
181 |
society = construct_learning_society(task)
|
182 |
+
|
183 |
from owl.utils import run_society
|
184 |
+
|
185 |
+
answer, chat_history, token_count = run_society(society, round_limit=5)
|
186 |
|
187 |
# Record tool usage history
|
188 |
analyze_chat_history(chat_history)
|
189 |
print(f"\033[94mAnswer: {answer}\033[0m")
|
190 |
|
191 |
+
|
192 |
if __name__ == "__main__":
|
193 |
+
run_learning_companion()
|
owl/.env_template
CHANGED
@@ -7,9 +7,18 @@
|
|
7 |
OPENAI_API_KEY='Your_Key'
|
8 |
# OPENAI_API_BASE_URL=""
|
9 |
|
10 |
-
|
11 |
-
#
|
12 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# Azure OpenAI API
|
15 |
# AZURE_OPENAI_BASE_URL=""
|
@@ -17,13 +26,6 @@ OPENAI_API_KEY='Your_Key'
|
|
17 |
# AZURE_OPENAI_API_KEY=""
|
18 |
# AZURE_DEPLOYMENT_NAME=""
|
19 |
|
20 |
-
|
21 |
-
# Qwen API (https://help.aliyun.com/zh/model-studio/developer-reference/get-api-key)
|
22 |
-
QWEN_API_KEY='Your_Key'
|
23 |
-
|
24 |
-
# DeepSeek API (https://platform.deepseek.com/api_keys)
|
25 |
-
DEEPSEEK_API_KEY='Your_Key'
|
26 |
-
|
27 |
#===========================================
|
28 |
# Tools & Services API
|
29 |
#===========================================
|
|
|
7 |
OPENAI_API_KEY='Your_Key'
|
8 |
# OPENAI_API_BASE_URL=""
|
9 |
|
10 |
+
|
11 |
+
# Qwen API (https://help.aliyun.com/zh/model-studio/developer-reference/get-api-key)
|
12 |
+
# QWEN_API_KEY='Your_Key'
|
13 |
+
# QWEN_API_BASE_URL=""
|
14 |
+
|
15 |
+
# DeepSeek API (https://platform.deepseek.com/api_keys)
|
16 |
+
# DEEPSEEK_API_KEY='Your_Key'
|
17 |
+
# DEEPSEEK_API_BASE_URL=""
|
18 |
+
|
19 |
+
# GROQ API (https://console.groq.com/)
|
20 |
+
# GROQ_API_KEY='Your_Key'
|
21 |
+
# GROQ_API_BASE_URL=""
|
22 |
|
23 |
# Azure OpenAI API
|
24 |
# AZURE_OPENAI_BASE_URL=""
|
|
|
26 |
# AZURE_OPENAI_API_KEY=""
|
27 |
# AZURE_DEPLOYMENT_NAME=""
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
#===========================================
|
30 |
# Tools & Services API
|
31 |
#===========================================
|