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

added tool's name and description to tool_io_schema command #53

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all 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
added tool's name and description to tool_io_schema command
KahanMajmudar committed Oct 15, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit c3ef65a3ac0a6243d1c990cc442f16b627cf7f08
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -232,6 +232,12 @@ mechx tool-io-schema "6-prediction-offline" --chain-config gnosis
```
You will see an output like this:
```bash
Tool Details:
+---------------------------+-----------------------------------------------+
| Tool Name | Tool Description |
+===========================+===============================================+
| OpenAI Prediction Offline | Makes a prediction using OpenAI GPT-3.5 Turbo |
+---------------------------+-----------------------------------------------+
Input Schema:
+-------------+----------------------------------+
| Field | Value |
27 changes: 22 additions & 5 deletions mech_client/cli.py
Original file line number Diff line number Diff line change
@@ -231,18 +231,35 @@ def tool_description(tool_id: str, chain_config: str) -> None:
@click.argument("tool_id")
@click.option("--chain-config", default="gnosis", help="Chain configuration to use.")
def tool_io_schema(tool_id: str, chain_config: str) -> None:
"""Fetch and display the input/output schema for a specific tool."""
"""Fetch and display the tool's name and description along with the input/output schema for a specific tool."""
try:
io_schema = get_tool_io_schema(tool_id, chain_config)
result = get_tool_io_schema(tool_id, chain_config)

name = result["name"]
description = result["description"]
# Prepare data for tabulation
input_schema = [(key, io_schema["input"][key]) for key in io_schema["input"]]
input_schema = [(key, result["input"][key]) for key in result["input"]]

# Handling nested output schema
output_schema = []
if "properties" in io_schema["output"]["schema"]:
for key, value in io_schema["output"]["schema"]["properties"].items():
if "properties" in result["output"]["schema"]:
for key, value in result["output"]["schema"]["properties"].items():
output_schema.append((key, value["type"], value.get("description", "")))

# Display tool details in tabulated format
click.echo("Tool Details:")
click.echo(
tabulate(
[
[
name,
description,
]
],
headers=["Tool Name", "Tool Description"],
tablefmt="grid",
)
)
# Display schemas in tabulated format
click.echo("Input Schema:")
click.echo(tabulate(input_schema, headers=["Field", "Value"], tablefmt="grid"))
6 changes: 4 additions & 2 deletions mech_client/mech_tool_management.py
Original file line number Diff line number Diff line change
@@ -170,11 +170,11 @@ def get_tool_io_schema(
unique_identifier: str, chain_config: str = "gnosis"
) -> Dict[str, Any]:
"""
Fetch the input and output schema of a specific tool based on a unique identifier.
Fetch the input and output schema along with tool name and description of a specific tool based on a unique identifier.
:param unique_identifier: The unique identifier for the tool.
:param chain_config: The chain configuration to use.
:return: Dictionary containing input and output schemas.
:return: Dictionary containing name, description, input and output schemas.
"""
parts = unique_identifier.split("-")
agent_id = int(parts[0])
@@ -196,6 +196,8 @@ def get_tool_io_schema(
tool_info = tool_metadata.get(tool_name, {})
if isinstance(tool_info, dict):
return {
"name": tool_info.get("name", {}),
"description": tool_info.get("description", {}),
"input": tool_info.get("input", {}),
"output": tool_info.get("output", {}),
}