Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Simplify Tool setting #891

Merged
merged 8 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions camel/agents/chat_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ def __init__(
tool.get_function_name(): tool.func for tool in all_tools
}

# If the user hasn't configured tools in `BaseModelBackend`,
# the tools set from `ChatAgent` will be used.
WHALEEYE marked this conversation as resolved.
Show resolved Hide resolved
# This design simplifies the interface while retaining tool-running
# capabilities for `BaseModelBackend`.
if all_tools and not self.model_backend.model_config_dict['tools']:
tool_schema_list = [
tool.get_openai_tool_schema() for tool in all_tools
]
self.model_backend.model_config_dict['tools'] = tool_schema_list

self.model_config_dict = self.model_backend.model_config_dict

self.model_token_limit = token_limit or self.model_backend.token_limit
Expand Down
2 changes: 0 additions & 2 deletions docs/tutorials_and_cookbooks/agents_with_tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ model=ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_3_5_TURBO,
model_config_dict=ChatGPTConfig(
tools=tool_list,
temperature=0.0,
).as_dict(),
)
Expand All @@ -92,7 +91,6 @@ assistant_sys_msg = BaseMessage.make_assistant_message(

# Set the config parameter for the model
assistant_model_config = ChatGPTConfig(
tools=tool_list,
temperature=0.0,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Set models for user agent and assistant agent, give tool to the assistant
assistant_agent_model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_3_5_TURBO,
model_config_dict=ChatGPTConfig(tools=tools).as_dict(),
model_config_dict=ChatGPTConfig().as_dict(),
)

user_agent_model = ModelFactory.create(
Expand Down
1 change: 0 additions & 1 deletion examples/function_call/code_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
# set up LLM model
assistant_model_config = ChatGPTConfig(
temperature=0.0,
tools=tools,
)

model = ModelFactory.create(
Expand Down
5 changes: 1 addition & 4 deletions examples/function_call/github_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def write_weekly_pr_summary(repo_name, model=None):
of an open source project {repo_name} on the project's blog.
""",
)
assistant_model_config_dict = ChatGPTConfig(
tools=[OpenAIFunction(toolkit.retrieve_pull_requests)], temperature=0.0
).as_dict()
assistant_model_config_dict = ChatGPTConfig(temperature=0.0).as_dict()

assistant_model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
Expand Down Expand Up @@ -114,7 +112,6 @@ def solve_issue(
specializes on data structures and algorithms tasks.""",
)
assistant_model_config_dict = ChatGPTConfig(
tools=toolkit.get_tools(),
temperature=0.0,
).as_dict()

Expand Down
3 changes: 1 addition & 2 deletions examples/function_call/openapi_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
# Set model config
tools = OpenAPIToolkit().get_tools()
model_config_dict = ChatGPTConfig(
tools=tools,
temperature=0.0,
).as_dict()

Expand All @@ -40,7 +39,7 @@
camel_agent = ChatAgent(
system_message=sys_msg,
model=model,
tools=OpenAPIToolkit().get_tools(),
tools=tools,
)
camel_agent.reset()

Expand Down
1 change: 0 additions & 1 deletion examples/function_call/role_playing_with_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def main(
*SearchToolkit().get_tools(),
]
assistant_model_config = ChatGPTConfig(
tools=tools_list,
temperature=0.0,
)

Expand Down
1 change: 0 additions & 1 deletion examples/models/role_playing_with_mistral.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def main(
*SearchToolkit().get_tools(),
]
assistant_model_config = MistralConfig(
tools=tools_list,
temperature=0.2,
)

Expand Down
8 changes: 4 additions & 4 deletions examples/models/samba_model_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
url="https://sambaverse.sambanova.ai/api/predict",
)

sambacloud_api_model = ModelFactory.create(
samba_cloud_api_model = ModelFactory.create(
model_platform=ModelPlatformType.SAMBA,
model_type="Meta-Llama-3.1-405B-Instruct",
model_config_dict=SambaCloudAPIConfig(max_tokens=800).as_dict(),
Expand Down Expand Up @@ -68,8 +68,8 @@
system_message=sys_msg, model=sambaverse_api_model
)

camel_agent_sambacloud_api = ChatAgent(
system_message=sys_msg, model=sambacloud_api_model
camel_agent_samba_cloud_api = ChatAgent(
system_message=sys_msg, model=samba_cloud_api_model
)

# Get response information
Expand Down Expand Up @@ -103,7 +103,7 @@
'''

# Get response information
response = camel_agent_sambacloud_api.step(user_msg)
response = camel_agent_samba_cloud_api.step(user_msg)
print(response.msgs[0].content)
'''
===============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
*SearchToolkit().get_tools(),
]
assistant_model_config = ChatGPTConfig(
tools=tools_list,
temperature=0.0,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
*SearchToolkit().get_tools(),
]
assistant_model_config = ChatGPTConfig(
tools=tools_list,
temperature=0.0,
)

Expand Down
2 changes: 1 addition & 1 deletion examples/vision/image_crafting.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def main():
content="Draw a picture of a camel.",
)

model_config = ChatGPTConfig(tools=DalleToolkit().get_tools())
model_config = ChatGPTConfig()

model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
Expand Down
2 changes: 1 addition & 1 deletion examples/vision/multi_condition_image_crafting.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def main(image_paths: list[str]) -> list[str]:
content=sys_msg,
)

model_config = ChatGPTConfig(tools=DalleToolkit().get_tools())
model_config = ChatGPTConfig()

model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
Expand Down
2 changes: 1 addition & 1 deletion examples/vision/multi_turn_image_refining.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(
def init_agents(self):
r"""Initialize artist and critic agents with their system messages."""

model_config = ChatGPTConfig(tools=DalleToolkit().get_tools())
model_config = ChatGPTConfig()

model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
Expand Down
1 change: 0 additions & 1 deletion examples/workforce/multiple_single_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def main():
]
# configure the model of tool_agent
model_config_dict = ChatGPTConfig(
tools=tools_list,
temperature=0.0,
).as_dict()

Expand Down
1 change: 0 additions & 1 deletion examples/workforce/role_playing_with_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def main():
]
user_model_config = ChatGPTConfig(temperature=0.0)
assistant_model_config = ChatGPTConfig(
tools=tools_list,
temperature=0.0,
)
model_platform = ModelPlatformType.OPENAI
Expand Down
8 changes: 4 additions & 4 deletions test/agents/test_chat_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def test_function_enabled():
meta_dict=None,
content="You are a help assistant.",
)
model_config = ChatGPTConfig(tools=MathToolkit().get_tools())
model_config = ChatGPTConfig()
model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_4O_MINI,
Expand All @@ -446,7 +446,7 @@ def test_tool_calling_sync():
meta_dict=None,
content="You are a help assistant.",
)
model_config = ChatGPTConfig(tools=MathToolkit().get_tools())
model_config = ChatGPTConfig()
model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_4O_MINI,
Expand Down Expand Up @@ -492,7 +492,7 @@ async def test_tool_calling_math_async():
content="You are a help assistant.",
)
math_funcs = sync_funcs_to_async(MathToolkit().get_tools())
model_config = ChatGPTConfig(tools=[*math_funcs])
model_config = ChatGPTConfig()
model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_4O_MINI,
Expand Down Expand Up @@ -548,7 +548,7 @@ async def async_sleep(second: int) -> int:
await asyncio.sleep(second)
return second

model_config = ChatGPTConfig(tools=[OpenAIFunction(async_sleep)])
model_config = ChatGPTConfig()

model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
Expand Down
2 changes: 1 addition & 1 deletion test/agents/test_role_playing.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_role_playing_step(
@pytest.mark.model_backend
def test_role_playing_with_function():
tools = MathToolkit().get_tools()
assistant_model_config = ChatGPTConfig(tools=tools)
assistant_model_config = ChatGPTConfig()
model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_4O_MINI,
Expand Down
Loading