mirror of
https://github.com/camel-ai/owl.git
synced 2026-03-22 05:57:17 +08:00
env template update and format fix
This commit is contained in:
@@ -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 os
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
@@ -13,8 +26,8 @@ from camel.toolkits import (
|
|||||||
from camel.societies import RolePlaying
|
from camel.societies import RolePlaying
|
||||||
from camel.logger import set_log_level, get_logger
|
from camel.logger import set_log_level, get_logger
|
||||||
|
|
||||||
|
|
||||||
from owl.utils import run_society
|
from owl.utils import run_society
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
base_dir = pathlib.Path(__file__).parent.parent
|
base_dir = pathlib.Path(__file__).parent.parent
|
||||||
@@ -117,16 +130,26 @@ def analyze_chat_history(chat_history):
|
|||||||
"message_index": i,
|
"message_index": i,
|
||||||
}
|
}
|
||||||
tool_calls.append(tool_info)
|
tool_calls.append(tool_info)
|
||||||
print(f"Tool Call: {function.get('name')} Args: {function.get('arguments')}")
|
print(
|
||||||
logger.info(f"Tool Call: {function.get('name')} Args: {function.get('arguments')}")
|
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:
|
elif message.get("role") == "tool" and "tool_call_id" in message:
|
||||||
for tool_call in tool_calls:
|
for tool_call in tool_calls:
|
||||||
if tool_call.get("call_id") == message.get("tool_call_id"):
|
if tool_call.get("call_id") == message.get("tool_call_id"):
|
||||||
result = message.get("content", "")
|
result = message.get("content", "")
|
||||||
result_summary = result[:100] + "..." if len(result) > 100 else result
|
result_summary = (
|
||||||
print(f"Tool Result: {tool_call.get('name')} Return: {result_summary}")
|
result[:100] + "..." if len(result) > 100 else result
|
||||||
logger.info(f"Tool Result: {tool_call.get('name')} Return: {result_summary}")
|
)
|
||||||
|
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)}")
|
print(f"Total tool calls found: {len(tool_calls)}")
|
||||||
logger.info(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__":
|
if __name__ == "__main__":
|
||||||
run_cooking_companion()
|
run_cooking_companion()
|
||||||
|
|||||||
@@ -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 os
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
@@ -81,11 +94,10 @@ def construct_learning_society(task: str) -> RolePlaying:
|
|||||||
user_agent_kwargs = {
|
user_agent_kwargs = {
|
||||||
"model": models["user"],
|
"model": models["user"],
|
||||||
}
|
}
|
||||||
|
|
||||||
assistant_agent_kwargs = {
|
assistant_agent_kwargs = {
|
||||||
"model": models["assistant"],
|
"model": models["assistant"],
|
||||||
"tools": tools,
|
"tools": tools,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task_kwargs = {
|
task_kwargs = {
|
||||||
@@ -122,16 +134,26 @@ def analyze_chat_history(chat_history):
|
|||||||
"message_index": i,
|
"message_index": i,
|
||||||
}
|
}
|
||||||
tool_calls.append(tool_info)
|
tool_calls.append(tool_info)
|
||||||
print(f"Tool Call: {function.get('name')} Args: {function.get('arguments')}")
|
print(
|
||||||
logger.info(f"Tool Call: {function.get('name')} Args: {function.get('arguments')}")
|
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:
|
elif message.get("role") == "tool" and "tool_call_id" in message:
|
||||||
for tool_call in tool_calls:
|
for tool_call in tool_calls:
|
||||||
if tool_call.get("call_id") == message.get("tool_call_id"):
|
if tool_call.get("call_id") == message.get("tool_call_id"):
|
||||||
result = message.get("content", "")
|
result = message.get("content", "")
|
||||||
result_summary = result[:100] + "..." if len(result) > 100 else result
|
result_summary = (
|
||||||
print(f"Tool Result: {tool_call.get('name')} Return: {result_summary}")
|
result[:100] + "..." if len(result) > 100 else result
|
||||||
logger.info(f"Tool Result: {tool_call.get('name')} Return: {result_summary}")
|
)
|
||||||
|
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)}")
|
print(f"Total tool calls found: {len(tool_calls)}")
|
||||||
logger.info(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):
|
def run_learning_companion(task: str = None):
|
||||||
"""Run the learning companion with the given task.
|
"""Run the learning companion with the given task.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
task (str, optional): The learning task description. Defaults to an example task.
|
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've also taken a basic statistics course.
|
||||||
I have about 10 hours per week to dedicate to learning. Devise a roadmap for me .
|
I have about 10 hours per week to dedicate to learning. Devise a roadmap for me .
|
||||||
"""
|
"""
|
||||||
|
|
||||||
society = construct_learning_society(task)
|
society = construct_learning_society(task)
|
||||||
|
|
||||||
from owl.utils import run_society
|
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
|
# Record tool usage history
|
||||||
analyze_chat_history(chat_history)
|
analyze_chat_history(chat_history)
|
||||||
print(f"\033[94mAnswer: {answer}\033[0m")
|
print(f"\033[94mAnswer: {answer}\033[0m")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
run_learning_companion()
|
run_learning_companion()
|
||||||
|
|||||||
@@ -7,9 +7,18 @@
|
|||||||
OPENAI_API_KEY='Your_Key'
|
OPENAI_API_KEY='Your_Key'
|
||||||
# OPENAI_API_BASE_URL=""
|
# 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
|
# Qwen API (https://help.aliyun.com/zh/model-studio/developer-reference/get-api-key)
|
||||||
# GROQ_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 API
|
||||||
# AZURE_OPENAI_BASE_URL=""
|
# AZURE_OPENAI_BASE_URL=""
|
||||||
@@ -17,13 +26,6 @@ OPENAI_API_KEY='Your_Key'
|
|||||||
# AZURE_OPENAI_API_KEY=""
|
# AZURE_OPENAI_API_KEY=""
|
||||||
# AZURE_DEPLOYMENT_NAME=""
|
# 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
|
# Tools & Services API
|
||||||
#===========================================
|
#===========================================
|
||||||
|
|||||||
Reference in New Issue
Block a user