env template update and format fix

This commit is contained in:
Wendong
2025-03-21 16:54:55 +08:00
parent 86e03a1c9f
commit 34d075ac65
3 changed files with 79 additions and 30 deletions

View File

@@ -1,3 +1,16 @@
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
import os
import logging
import json
@@ -13,8 +26,8 @@ from camel.toolkits import (
from camel.societies import RolePlaying
from camel.logger import set_log_level, get_logger
from owl.utils import run_society
from owl.utils import run_society
import pathlib
base_dir = pathlib.Path(__file__).parent.parent
@@ -117,16 +130,26 @@ def analyze_chat_history(chat_history):
"message_index": i,
}
tool_calls.append(tool_info)
print(f"Tool Call: {function.get('name')} Args: {function.get('arguments')}")
logger.info(f"Tool Call: {function.get('name')} Args: {function.get('arguments')}")
print(
f"Tool Call: {function.get('name')} Args: {function.get('arguments')}"
)
logger.info(
f"Tool Call: {function.get('name')} Args: {function.get('arguments')}"
)
elif message.get("role") == "tool" and "tool_call_id" in message:
for tool_call in tool_calls:
if tool_call.get("call_id") == message.get("tool_call_id"):
result = message.get("content", "")
result_summary = result[:100] + "..." if len(result) > 100 else result
print(f"Tool Result: {tool_call.get('name')} Return: {result_summary}")
logger.info(f"Tool Result: {tool_call.get('name')} Return: {result_summary}")
result_summary = (
result[:100] + "..." if len(result) > 100 else result
)
print(
f"Tool Result: {tool_call.get('name')} Return: {result_summary}"
)
logger.info(
f"Tool Result: {tool_call.get('name')} Return: {result_summary}"
)
print(f"Total tool calls found: {len(tool_calls)}")
logger.info(f"Total tool calls found: {len(tool_calls)}")
@@ -150,4 +173,4 @@ def run_cooking_companion():
if __name__ == "__main__":
run_cooking_companion()
run_cooking_companion()

View File

@@ -1,3 +1,16 @@
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
import os
import logging
import json
@@ -81,11 +94,10 @@ def construct_learning_society(task: str) -> RolePlaying:
user_agent_kwargs = {
"model": models["user"],
}
assistant_agent_kwargs = {
"model": models["assistant"],
"tools": tools,
}
task_kwargs = {
@@ -122,16 +134,26 @@ def analyze_chat_history(chat_history):
"message_index": i,
}
tool_calls.append(tool_info)
print(f"Tool Call: {function.get('name')} Args: {function.get('arguments')}")
logger.info(f"Tool Call: {function.get('name')} Args: {function.get('arguments')}")
print(
f"Tool Call: {function.get('name')} Args: {function.get('arguments')}"
)
logger.info(
f"Tool Call: {function.get('name')} Args: {function.get('arguments')}"
)
elif message.get("role") == "tool" and "tool_call_id" in message:
for tool_call in tool_calls:
if tool_call.get("call_id") == message.get("tool_call_id"):
result = message.get("content", "")
result_summary = result[:100] + "..." if len(result) > 100 else result
print(f"Tool Result: {tool_call.get('name')} Return: {result_summary}")
logger.info(f"Tool Result: {tool_call.get('name')} Return: {result_summary}")
result_summary = (
result[:100] + "..." if len(result) > 100 else result
)
print(
f"Tool Result: {tool_call.get('name')} Return: {result_summary}"
)
logger.info(
f"Tool Result: {tool_call.get('name')} Return: {result_summary}"
)
print(f"Total tool calls found: {len(tool_calls)}")
logger.info(f"Total tool calls found: {len(tool_calls)}")
@@ -146,7 +168,7 @@ def analyze_chat_history(chat_history):
def run_learning_companion(task: str = None):
"""Run the learning companion with the given task.
Args:
task (str, optional): The learning task description. Defaults to an example task.
"""
@@ -155,15 +177,17 @@ def run_learning_companion(task: str = None):
I've also taken a basic statistics course.
I have about 10 hours per week to dedicate to learning. Devise a roadmap for me .
"""
society = construct_learning_society(task)
from owl.utils import run_society
answer, chat_history, token_count = run_society(society, round_limit = 5)
answer, chat_history, token_count = run_society(society, round_limit=5)
# Record tool usage history
analyze_chat_history(chat_history)
print(f"\033[94mAnswer: {answer}\033[0m")
if __name__ == "__main__":
run_learning_companion()
run_learning_companion()

View File

@@ -7,9 +7,18 @@
OPENAI_API_KEY='Your_Key'
# OPENAI_API_BASE_URL=""
# When using GROQ remember to set OPENAI_API_BASE_URL to https://api.groq.com/openai/v1 to use the groq model according to https://console.groq.com/docs/openai
# and set OPENAI_API_KEY equal to GROQ_API_KEY
# GROQ_API_KEY=""
# Qwen API (https://help.aliyun.com/zh/model-studio/developer-reference/get-api-key)
# QWEN_API_KEY='Your_Key'
# QWEN_API_BASE_URL=""
# DeepSeek API (https://platform.deepseek.com/api_keys)
# DEEPSEEK_API_KEY='Your_Key'
# DEEPSEEK_API_BASE_URL=""
# GROQ API (https://console.groq.com/)
# GROQ_API_KEY='Your_Key'
# GROQ_API_BASE_URL=""
# Azure OpenAI API
# AZURE_OPENAI_BASE_URL=""
@@ -17,13 +26,6 @@ OPENAI_API_KEY='Your_Key'
# AZURE_OPENAI_API_KEY=""
# AZURE_DEPLOYMENT_NAME=""
# Qwen API (https://help.aliyun.com/zh/model-studio/developer-reference/get-api-key)
QWEN_API_KEY='Your_Key'
# DeepSeek API (https://platform.deepseek.com/api_keys)
DEEPSEEK_API_KEY='Your_Key'
#===========================================
# Tools & Services API
#===========================================