Use OpenAI SDK types for tool params in adapters and tests
These are TypedDicts (plain dicts at runtime), so no behavioral change — just more descriptive type hints for readers. Use ToolParam instead of FunctionToolParam for the Responses adapter to reflect that custom non-function tools are supported. Use ChatCompletionToolParam instead of Any for the completions adapter return type. Update tests to use typed params in expected values.
This commit is contained in:
@@ -96,7 +96,7 @@ class OpenAILLMAdapter(BaseLLMAdapter[OpenAILLMInvocationParams]):
|
||||
"tool_choice": context.tool_choice,
|
||||
}
|
||||
|
||||
def to_provider_tools_format(self, tools_schema: ToolsSchema) -> List[Any]:
|
||||
def to_provider_tools_format(self, tools_schema: ToolsSchema) -> List[ChatCompletionToolParam]:
|
||||
"""Convert function schemas to OpenAI's function-calling format.
|
||||
|
||||
Args:
|
||||
|
||||
@@ -10,7 +10,7 @@ import copy
|
||||
from typing import Any, Dict, List, Optional, TypedDict
|
||||
|
||||
from openai._types import NotGiven as OpenAINotGiven
|
||||
from openai.types.responses import FunctionToolParam, ResponseInputItemParam
|
||||
from openai.types.responses import FunctionToolParam, ResponseInputItemParam, ToolParam
|
||||
|
||||
from pipecat.adapters.base_llm_adapter import BaseLLMAdapter
|
||||
from pipecat.adapters.schemas.tools_schema import AdapterType, ToolsSchema
|
||||
@@ -25,7 +25,7 @@ class OpenAIResponsesLLMInvocationParams(TypedDict, total=False):
|
||||
"""Context-based parameters for invoking OpenAI Responses API."""
|
||||
|
||||
input: List[ResponseInputItemParam]
|
||||
tools: List[FunctionToolParam] | OpenAINotGiven
|
||||
tools: List[ToolParam] | OpenAINotGiven
|
||||
instructions: str
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ class OpenAIResponsesLLMAdapter(BaseLLMAdapter[OpenAIResponsesLLMInvocationParam
|
||||
|
||||
return params
|
||||
|
||||
def to_provider_tools_format(self, tools_schema: ToolsSchema) -> List[Any]:
|
||||
def to_provider_tools_format(self, tools_schema: ToolsSchema) -> List[ToolParam]:
|
||||
"""Convert function schemas to Responses API function tool format.
|
||||
|
||||
Args:
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
import unittest
|
||||
|
||||
from openai.types.chat import ChatCompletionToolParam
|
||||
from openai.types.responses.function_tool_param import FunctionToolParam
|
||||
from openai.types.responses.tool_search_tool_param import ToolSearchToolParam
|
||||
|
||||
from pipecat.adapters.schemas.function_schema import FunctionSchema
|
||||
from pipecat.adapters.schemas.tools_schema import AdapterType, ToolsSchema
|
||||
@@ -213,11 +215,11 @@ class TestFunctionAdapters(unittest.TestCase):
|
||||
"""Test OpenAI Responses adapter appends custom tools."""
|
||||
tool_search = {"type": "tool_search"}
|
||||
expected = [
|
||||
{
|
||||
"type": "function",
|
||||
"name": "get_weather",
|
||||
"description": "Get the weather in a given location",
|
||||
"parameters": {
|
||||
FunctionToolParam(
|
||||
type="function",
|
||||
name="get_weather",
|
||||
description="Get the weather in a given location",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"location": {
|
||||
@@ -232,9 +234,9 @@ class TestFunctionAdapters(unittest.TestCase):
|
||||
},
|
||||
"required": ["location", "format"],
|
||||
},
|
||||
"strict": None,
|
||||
},
|
||||
tool_search,
|
||||
strict=None,
|
||||
),
|
||||
ToolSearchToolParam(type="tool_search"),
|
||||
]
|
||||
tools_def = self.tools_def
|
||||
tools_def.custom_tools = {AdapterType.OPENAI: [tool_search]}
|
||||
|
||||
Reference in New Issue
Block a user