mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-04 12:07:34 +00:00
fixes
This commit is contained in:
parent
139320e19f
commit
a78f981dbb
7 changed files with 91 additions and 199 deletions
|
@ -48,14 +48,16 @@ class Tool(Resource):
|
|||
:param type: Type of resource, always 'tool'
|
||||
:param toolgroup_id: ID of the tool group this tool belongs to
|
||||
:param description: Human-readable description of what the tool does
|
||||
:param parameters: List of parameters this tool accepts
|
||||
:param input_schema: JSON Schema for the tool's input parameters
|
||||
:param output_schema: JSON Schema for the tool's output
|
||||
:param metadata: (Optional) Additional metadata about the tool
|
||||
"""
|
||||
|
||||
type: Literal[ResourceType.tool] = ResourceType.tool
|
||||
toolgroup_id: str
|
||||
description: str
|
||||
parameters: list[ToolParameter]
|
||||
input_schema: dict[str, Any] | None = None
|
||||
output_schema: dict[str, Any] | None = None
|
||||
metadata: dict[str, Any] | None = None
|
||||
|
||||
|
||||
|
|
|
@ -83,7 +83,8 @@ class ToolGroupsRoutingTable(CommonRoutingTableImpl, ToolGroups):
|
|||
identifier=t.name,
|
||||
toolgroup_id=toolgroup.identifier,
|
||||
description=t.description or "",
|
||||
parameters=t.parameters or [],
|
||||
input_schema=t.input_schema,
|
||||
output_schema=t.output_schema,
|
||||
metadata=t.metadata,
|
||||
provider_id=toolgroup.provider_id,
|
||||
)
|
||||
|
|
|
@ -65,35 +65,10 @@ def convert_tooldef_to_chat_tool(tool_def):
|
|||
from llama_stack.models.llama.datatypes import ToolDefinition
|
||||
from llama_stack.providers.utils.inference.openai_compat import convert_tooldef_to_openai_tool
|
||||
|
||||
# Build JSON Schema from tool parameters
|
||||
properties = {}
|
||||
required = []
|
||||
|
||||
for param in tool_def.parameters:
|
||||
param_schema = {
|
||||
"type": param.parameter_type,
|
||||
"description": param.description,
|
||||
}
|
||||
if param.default is not None:
|
||||
param_schema["default"] = param.default
|
||||
if param.items is not None:
|
||||
param_schema["items"] = param.items
|
||||
|
||||
properties[param.name] = param_schema
|
||||
|
||||
if param.required:
|
||||
required.append(param.name)
|
||||
|
||||
input_schema = {
|
||||
"type": "object",
|
||||
"properties": properties,
|
||||
"required": required,
|
||||
}
|
||||
|
||||
internal_tool_def = ToolDefinition(
|
||||
tool_name=tool_def.name,
|
||||
description=tool_def.description,
|
||||
input_schema=input_schema,
|
||||
input_schema=tool_def.input_schema,
|
||||
)
|
||||
return convert_tooldef_to_openai_tool(internal_tool_def)
|
||||
|
||||
|
@ -546,33 +521,10 @@ class StreamingResponseOrchestrator:
|
|||
from llama_stack.providers.utils.inference.openai_compat import convert_tooldef_to_openai_tool
|
||||
|
||||
def make_openai_tool(tool_name: str, tool: Tool) -> ChatCompletionToolParam:
|
||||
# Build JSON Schema from tool parameters
|
||||
properties = {}
|
||||
required = []
|
||||
|
||||
for param in tool.parameters:
|
||||
param_schema = {
|
||||
"type": param.parameter_type,
|
||||
"description": param.description,
|
||||
}
|
||||
if param.default is not None:
|
||||
param_schema["default"] = param.default
|
||||
|
||||
properties[param.name] = param_schema
|
||||
|
||||
if param.required:
|
||||
required.append(param.name)
|
||||
|
||||
input_schema = {
|
||||
"type": "object",
|
||||
"properties": properties,
|
||||
"required": required,
|
||||
}
|
||||
|
||||
tool_def = ToolDefinition(
|
||||
tool_name=tool_name,
|
||||
description=tool.description,
|
||||
input_schema=input_schema,
|
||||
input_schema=tool.input_schema,
|
||||
)
|
||||
return convert_tooldef_to_openai_tool(tool_def)
|
||||
|
||||
|
@ -659,16 +611,11 @@ class StreamingResponseOrchestrator:
|
|||
MCPListToolsTool(
|
||||
name=t.name,
|
||||
description=t.description,
|
||||
input_schema={
|
||||
input_schema=t.input_schema
|
||||
or {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
p.name: {
|
||||
"type": p.parameter_type,
|
||||
"description": p.description,
|
||||
}
|
||||
for p in t.parameters
|
||||
},
|
||||
"required": [p.name for p in t.parameters if p.required],
|
||||
"properties": {},
|
||||
"required": [],
|
||||
},
|
||||
)
|
||||
)
|
||||
|
|
|
@ -68,9 +68,7 @@ public class FunctionTagCustomToolGenerator {
|
|||
{
|
||||
"name": "{{t.tool_name}}",
|
||||
"description": "{{t.description}}",
|
||||
"parameters": {
|
||||
"type": "dict",
|
||||
"properties": { {{t.parameters}} }
|
||||
"input_schema": { {{t.input_schema}} }
|
||||
}
|
||||
|
||||
{{/let}}
|
||||
|
|
|
@ -110,18 +110,6 @@ def _convert_to_vllm_tools_in_request(tools: list[ToolDefinition]) -> list[dict]
|
|||
compat_tools = []
|
||||
|
||||
for tool in tools:
|
||||
properties = {}
|
||||
compat_required = []
|
||||
if tool.parameters:
|
||||
for tool_key, tool_param in tool.parameters.items():
|
||||
properties[tool_key] = {"type": tool_param.param_type}
|
||||
if tool_param.description:
|
||||
properties[tool_key]["description"] = tool_param.description
|
||||
if tool_param.default:
|
||||
properties[tool_key]["default"] = tool_param.default
|
||||
if tool_param.required:
|
||||
compat_required.append(tool_key)
|
||||
|
||||
# The tool.tool_name can be a str or a BuiltinTool enum. If
|
||||
# it's the latter, convert to a string.
|
||||
tool_name = tool.tool_name
|
||||
|
@ -133,10 +121,11 @@ def _convert_to_vllm_tools_in_request(tools: list[ToolDefinition]) -> list[dict]
|
|||
"function": {
|
||||
"name": tool_name,
|
||||
"description": tool.description,
|
||||
"parameters": {
|
||||
"parameters": tool.input_schema
|
||||
or {
|
||||
"type": "object",
|
||||
"properties": properties,
|
||||
"required": compat_required,
|
||||
"properties": {},
|
||||
"required": [],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue