Add parameter schema and defaults to ToolResource model and schemas. Implement runtime tool resolution in assistants and tools routers, ensuring proper handling of tool parameters. Update tests to validate new functionality and ensure correct integration of parameter handling in the API.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
import json
|
||||
from typing import Any, Dict, List
|
||||
|
||||
import pytest
|
||||
@@ -143,6 +144,64 @@ def test_pipeline_assigns_default_client_executor_for_system_string_tools(monkey
|
||||
assert pipeline._tool_executor(tool_call) == "client"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pipeline_applies_default_args_to_tool_call(monkeypatch):
|
||||
pipeline, _events = _build_pipeline(
|
||||
monkeypatch,
|
||||
[
|
||||
[
|
||||
LLMStreamEvent(
|
||||
type="tool_call",
|
||||
tool_call={
|
||||
"id": "call_defaults",
|
||||
"type": "function",
|
||||
"function": {"name": "weather", "arguments": "{}"},
|
||||
},
|
||||
),
|
||||
LLMStreamEvent(type="done"),
|
||||
],
|
||||
[LLMStreamEvent(type="done")],
|
||||
],
|
||||
)
|
||||
pipeline.apply_runtime_overrides(
|
||||
{
|
||||
"tools": [
|
||||
{
|
||||
"type": "function",
|
||||
"executor": "server",
|
||||
"defaultArgs": {"city": "Hangzhou", "unit": "c"},
|
||||
"function": {
|
||||
"name": "weather",
|
||||
"description": "Get weather",
|
||||
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}},
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
captured: Dict[str, Any] = {}
|
||||
|
||||
async def _server_exec(call: Dict[str, Any]) -> Dict[str, Any]:
|
||||
captured["call"] = call
|
||||
return {
|
||||
"tool_call_id": str(call.get("id") or ""),
|
||||
"name": "weather",
|
||||
"output": {"ok": True},
|
||||
"status": {"code": 200, "message": "ok"},
|
||||
}
|
||||
|
||||
monkeypatch.setattr(pipeline, "_server_tool_executor", _server_exec)
|
||||
await pipeline._handle_turn("weather?")
|
||||
|
||||
sent_call = captured.get("call")
|
||||
assert isinstance(sent_call, dict)
|
||||
args_raw = sent_call.get("function", {}).get("arguments")
|
||||
args = json.loads(args_raw) if isinstance(args_raw, str) else {}
|
||||
assert args.get("city") == "Hangzhou"
|
||||
assert args.get("unit") == "c"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ws_message_parses_tool_call_results():
|
||||
msg = parse_client_message(
|
||||
|
||||
Reference in New Issue
Block a user