Refactoring the 14 series examples to use the unified format for function calling.

This commit is contained in:
Filipi Fuchter
2025-03-06 10:35:26 -03:00
parent 2d114b15f9
commit 2df77430aa
15 changed files with 295 additions and 385 deletions

View File

@@ -11,7 +11,8 @@ import sys
import aiohttp import aiohttp
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
from openai.types.chat import ChatCompletionToolParam from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema
from runner import configure from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
@@ -65,15 +66,10 @@ async def main():
# sent to the same callback with an additional function_name parameter. # sent to the same callback with an additional function_name parameter.
llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather) llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather)
tools = [ weather_function = FunctionSchema(
ChatCompletionToolParam( name="get_current_weather",
type="function", description="Get the current weather",
function={ properties={
"name": "get_current_weather",
"description": "Get the current weather",
"parameters": {
"type": "object",
"properties": {
"location": { "location": {
"type": "string", "type": "string",
"description": "The city and state, e.g. San Francisco, CA", "description": "The city and state, e.g. San Francisco, CA",
@@ -81,14 +77,13 @@ async def main():
"format": { "format": {
"type": "string", "type": "string",
"enum": ["celsius", "fahrenheit"], "enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use. Infer this from the users location.", "description": "The temperature unit to use. Infer this from the user's location.",
},
},
"required": ["location", "format"],
}, },
}, },
required=["location", "format"],
) )
] tools = ToolsSchema(standard_tools=[weather_function])
messages = [ messages = [
{ {
"role": "system", "role": "system",

View File

@@ -11,6 +11,9 @@ import sys
import aiohttp import aiohttp
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema
from runner import configure from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
@@ -59,22 +62,18 @@ async def main():
) )
llm.register_function("get_weather", get_weather) llm.register_function("get_weather", get_weather)
tools = [ weather_function = FunctionSchema(
{ name="get_weather",
"name": "get_weather", description="Get the current weather",
"description": "Get the current weather in a given location", properties={
"input_schema": {
"type": "object",
"properties": {
"location": { "location": {
"type": "string", "type": "string",
"description": "The city and state, e.g. San Francisco, CA", "description": "The city and state, e.g. San Francisco, CA",
}
}, },
"required": ["location"],
}, },
} required=["location"],
] )
tools = ToolsSchema(standard_tools=[weather_function])
# todo: test with very short initial user message # todo: test with very short initial user message

View File

@@ -11,6 +11,9 @@ import sys
import aiohttp import aiohttp
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema
from runner import configure from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
@@ -72,36 +75,29 @@ async def main():
llm.register_function("get_weather", get_weather) llm.register_function("get_weather", get_weather)
llm.register_function("get_image", get_image) llm.register_function("get_image", get_image)
tools = [ weather_function = FunctionSchema(
{ name="get_weather",
"name": "get_weather", description="Get the current weather",
"description": "Get the current weather in a given location", properties={
"input_schema": {
"type": "object",
"properties": {
"location": { "location": {
"type": "string", "type": "string",
"description": "The city and state, e.g. San Francisco, CA", "description": "The city and state, e.g. San Francisco, CA",
}
},
"required": ["location"],
}, },
}, },
{ required=["location"],
"name": "get_image", )
"description": "Get an image from the video stream.", get_image_function = FunctionSchema(
"input_schema": { name="get_image",
"type": "object", description="Get an image from the video stream.",
"properties": { properties= {
"question": { "question": {
"type": "string", "type": "string",
"description": "The question that the user is asking about the image.", "description": "The question that the user is asking about the image.",
} }
}, },
"required": ["question"], required=["question"],
}, )
}, tools = ToolsSchema(standard_tools=[weather_function, get_image_function])
]
# todo: test with very short initial user message # todo: test with very short initial user message

View File

@@ -11,7 +11,8 @@ import sys
import aiohttp import aiohttp
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
from openai.types.chat import ChatCompletionToolParam from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema
from runner import configure from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
@@ -69,15 +70,10 @@ async def main():
# sent to the same callback with an additional function_name parameter. # sent to the same callback with an additional function_name parameter.
llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather) llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather)
tools = [ weather_function = FunctionSchema(
ChatCompletionToolParam( name="get_current_weather",
type="function", description="Get the current weather",
function={ properties={
"name": "get_current_weather",
"description": "Get the current weather",
"parameters": {
"type": "object",
"properties": {
"location": { "location": {
"type": "string", "type": "string",
"description": "The city and state, e.g. San Francisco, CA", "description": "The city and state, e.g. San Francisco, CA",
@@ -85,14 +81,12 @@ async def main():
"format": { "format": {
"type": "string", "type": "string",
"enum": ["celsius", "fahrenheit"], "enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use. Infer this from the users location.", "description": "The temperature unit to use. Infer this from the user's location.",
},
},
"required": ["location", "format"],
}, },
}, },
required=["location", "format"],
) )
] tools = ToolsSchema(standard_tools=[weather_function])
messages = [ messages = [
{ {
"role": "system", "role": "system",

View File

@@ -11,7 +11,8 @@ import sys
import aiohttp import aiohttp
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
from openai.types.chat import ChatCompletionToolParam from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema
from runner import configure from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
@@ -66,15 +67,10 @@ async def main():
llm.register_function("get_weather", get_weather) llm.register_function("get_weather", get_weather)
llm.register_function("get_image", get_image) llm.register_function("get_image", get_image)
tools = [ weather_function = FunctionSchema(
ChatCompletionToolParam( name="get_weather",
type="function", description="Get the current weather",
function={ properties={
"name": "get_weather",
"description": "Get the current weather",
"parameters": {
"type": "object",
"properties": {
"location": { "location": {
"type": "string", "type": "string",
"description": "The city and state, e.g. San Francisco, CA", "description": "The city and state, e.g. San Francisco, CA",
@@ -82,31 +78,23 @@ async def main():
"format": { "format": {
"type": "string", "type": "string",
"enum": ["celsius", "fahrenheit"], "enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use. Infer this from the users location.", "description": "The temperature unit to use. Infer this from the user's location.",
}, },
}, },
"required": ["location", "format"], required=["location"],
}, )
}, get_image_function = FunctionSchema(
), name="get_image",
ChatCompletionToolParam( description="Get an image from the video stream.",
type="function", properties={
function={
"name": "get_image",
"description": "Get an image from the video stream.",
"parameters": {
"type": "object",
"properties": {
"question": { "question": {
"type": "string", "type": "string",
"description": "The question to ask the AI to generate an image of", "description": "The question that the user is asking about the image.",
}
}, },
}, required=["question"],
"required": ["question"], )
}, tools = ToolsSchema(standard_tools=[weather_function, get_image_function])
},
),
]
system_prompt = """\ system_prompt = """\
You are a helpful assistant who converses with a user and answers questions. Respond concisely to general questions. You are a helpful assistant who converses with a user and answers questions. Respond concisely to general questions.

View File

@@ -11,6 +11,9 @@ import sys
import aiohttp import aiohttp
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema
from runner import configure from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
@@ -73,15 +76,10 @@ async def main():
llm.register_function("get_weather", get_weather, start_fetch_weather) llm.register_function("get_weather", get_weather, start_fetch_weather)
llm.register_function("get_image", get_image) llm.register_function("get_image", get_image)
tools = [ weather_function = FunctionSchema(
{ name="get_weather",
"function_declarations": [ description="Get the current weather",
{ properties={
"name": "get_weather",
"description": "Get the current weather",
"parameters": {
"type": "object",
"properties": {
"location": { "location": {
"type": "string", "type": "string",
"description": "The city and state, e.g. San Francisco, CA", "description": "The city and state, e.g. San Francisco, CA",
@@ -89,29 +87,23 @@ async def main():
"format": { "format": {
"type": "string", "type": "string",
"enum": ["celsius", "fahrenheit"], "enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use. Infer this from the users location.", "description": "The temperature unit to use. Infer this from the user's location.",
}, },
}, },
"required": ["location", "format"], required=["location", "format"],
}, )
}, get_image_function = FunctionSchema(
{ name="get_image",
"name": "get_image", description="Get an image from the video stream.",
"description": "Get and image from the camera or video stream.", properties={
"parameters": {
"type": "object",
"properties": {
"question": { "question": {
"type": "string", "type": "string",
"description": "The question to to use when running inference on the acquired image.", "description": "The question that the user is asking about the image.",
},
},
"required": ["question"],
},
},
]
} }
] },
required=["question"],
)
tools = ToolsSchema(standard_tools=[weather_function, get_image_function])
system_prompt = """\ system_prompt = """\
You are a helpful assistant who converses with a user and answers questions. Respond concisely to general questions. You are a helpful assistant who converses with a user and answers questions. Respond concisely to general questions.

View File

@@ -11,7 +11,8 @@ import sys
import aiohttp import aiohttp
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
from openai.types.chat import ChatCompletionToolParam from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema
from runner import configure from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
@@ -68,30 +69,23 @@ async def main():
# sent to the same callback with an additional function_name parameter. # sent to the same callback with an additional function_name parameter.
llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather) llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather)
tools = [ weather_function = FunctionSchema(
ChatCompletionToolParam( name="get_current_weather",
type="function", description="Get the current weather",
function={ properties={
"name": "get_current_weather",
"description": "Get the current weather",
"parameters": {
"type": "object",
"properties": {
"location": { "location": {
"type": "string", "type": "string",
"description": "The city and state, e.g. San Francisco, CA", "description": "The city and state, e.g. San Francisco, CA",
}, },
"unit": { "format": {
"type": "string", "type": "string",
"enum": ["celsius", "fahrenheit"], "enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use. Infer this from the users location.", "description": "The temperature unit to use. Infer this from the user's location.",
},
},
"required": ["location"],
}, },
}, },
required=["location"],
) )
] tools = ToolsSchema(standard_tools=[weather_function])
messages = [ messages = [
{ {
"role": "system", "role": "system",

View File

@@ -11,7 +11,8 @@ import sys
import aiohttp import aiohttp
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
from openai.types.chat import ChatCompletionToolParam from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema
from runner import configure from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
@@ -66,15 +67,10 @@ async def main():
# sent to the same callback with an additional function_name parameter. # sent to the same callback with an additional function_name parameter.
llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather) llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather)
tools = [ weather_function = FunctionSchema(
ChatCompletionToolParam( name="get_current_weather",
type="function", description="Get the current weather",
function={ properties={
"name": "get_current_weather",
"description": "Get the current weather",
"parameters": {
"type": "object",
"properties": {
"location": { "location": {
"type": "string", "type": "string",
"description": "The city and state, e.g. San Francisco, CA", "description": "The city and state, e.g. San Francisco, CA",
@@ -82,14 +78,12 @@ async def main():
"format": { "format": {
"type": "string", "type": "string",
"enum": ["celsius", "fahrenheit"], "enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use. Infer this from the users location.", "description": "The temperature unit to use. Infer this from the user's location.",
},
},
"required": ["location", "format"],
}, },
}, },
required=["location", "format"],
) )
] tools = ToolsSchema(standard_tools=[weather_function])
messages = [ messages = [
{ {
"role": "system", "role": "system",

View File

@@ -11,7 +11,8 @@ import sys
import aiohttp import aiohttp
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
from openai.types.chat import ChatCompletionToolParam from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema
from runner import configure from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
@@ -70,15 +71,10 @@ async def main():
# sent to the same callback with an additional function_name parameter. # sent to the same callback with an additional function_name parameter.
llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather) llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather)
tools = [ weather_function = FunctionSchema(
ChatCompletionToolParam( name="get_current_weather",
type="function", description="Get the current weather",
function={ properties={
"name": "get_current_weather",
"description": "Get the current weather",
"parameters": {
"type": "object",
"properties": {
"location": { "location": {
"type": "string", "type": "string",
"description": "The city and state, e.g. San Francisco, CA", "description": "The city and state, e.g. San Francisco, CA",
@@ -86,14 +82,12 @@ async def main():
"format": { "format": {
"type": "string", "type": "string",
"enum": ["celsius", "fahrenheit"], "enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use. Infer this from the users location.", "description": "The temperature unit to use. Infer this from the user's location.",
},
},
"required": ["location", "format"],
}, },
}, },
required=["location", "format"],
) )
] tools = ToolsSchema(standard_tools=[weather_function])
messages = [ messages = [
{ {
"role": "system", "role": "system",

View File

@@ -11,7 +11,8 @@ import sys
import aiohttp import aiohttp
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
from openai.types.chat import ChatCompletionToolParam from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema
from runner import configure from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
@@ -69,15 +70,10 @@ async def main():
# sent to the same callback with an additional function_name parameter. # sent to the same callback with an additional function_name parameter.
llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather) llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather)
tools = [ weather_function = FunctionSchema(
ChatCompletionToolParam( name="get_current_weather",
type="function", description="Get the current weather",
function={ properties={
"name": "get_current_weather",
"description": "Get the current weather",
"parameters": {
"type": "object",
"properties": {
"location": { "location": {
"type": "string", "type": "string",
"description": "The city and state, e.g. San Francisco, CA", "description": "The city and state, e.g. San Francisco, CA",
@@ -85,14 +81,12 @@ async def main():
"format": { "format": {
"type": "string", "type": "string",
"enum": ["celsius", "fahrenheit"], "enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use. Infer this from the users location.", "description": "The temperature unit to use. Infer this from the user's location.",
},
},
"required": ["location", "format"],
}, },
}, },
required=["location", "format"],
) )
] tools = ToolsSchema(standard_tools=[weather_function])
messages = [ messages = [
{ {
"role": "system", "role": "system",

View File

@@ -11,7 +11,8 @@ import sys
import aiohttp import aiohttp
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
from openai.types.chat import ChatCompletionToolParam from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema
from runner import configure from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
@@ -69,30 +70,23 @@ async def main():
# sent to the same callback with an additional function_name parameter. # sent to the same callback with an additional function_name parameter.
llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather) llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather)
tools = [ weather_function = FunctionSchema(
ChatCompletionToolParam( name="get_current_weather",
type="function", description="Get the current weather",
function={ properties={
"name": "get_current_weather",
"description": "Returns the current weather at a location, if one is specified, and defaults to the user's location.",
"parameters": {
"type": "object",
"properties": {
"location": { "location": {
"type": "string", "type": "string",
"description": "The location to find the weather of, or if not provided, it's the default location.", "description": "The city and state, e.g. San Francisco, CA",
}, },
"format": { "format": {
"type": "string", "type": "string",
"enum": ["celsius", "fahrenheit"], "enum": ["celsius", "fahrenheit"],
"description": "Whether to use SI or USCS units (celsius or fahrenheit).", "description": "The temperature unit to use. Infer this from the user's location.",
},
},
"required": ["location", "format"],
}, },
}, },
required=["location", "format"],
) )
] tools = ToolsSchema(standard_tools=[weather_function])
messages = [ messages = [
{ {
"role": "system", "role": "system",

View File

@@ -11,7 +11,8 @@ import sys
import aiohttp import aiohttp
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
from openai.types.chat import ChatCompletionToolParam from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema
from runner import configure from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
@@ -66,15 +67,10 @@ async def main():
# sent to the same callback with an additional function_name parameter. # sent to the same callback with an additional function_name parameter.
llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather) llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather)
tools = [ weather_function = FunctionSchema(
ChatCompletionToolParam( name="get_current_weather",
type="function", description="Get the current weather",
function={ properties={
"name": "get_current_weather",
"description": "Get the current weather for a specific location. You MUST use this function whenever asked about weather.",
"parameters": {
"type": "object",
"properties": {
"location": { "location": {
"type": "string", "type": "string",
"description": "The city and state, e.g. San Francisco, CA", "description": "The city and state, e.g. San Francisco, CA",
@@ -82,14 +78,12 @@ async def main():
"format": { "format": {
"type": "string", "type": "string",
"enum": ["celsius", "fahrenheit"], "enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use. Use fahrenheit for US locations, celsius for others.", "description": "The temperature unit to use. Infer this from the user's location.",
},
},
"required": ["location", "format"],
}, },
}, },
required=["location", "format"],
) )
] tools = ToolsSchema(standard_tools=[weather_function])
messages = [ messages = [
{ {
"role": "system", "role": "system",

View File

@@ -11,7 +11,8 @@ import sys
import aiohttp import aiohttp
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
from openai.types.chat import ChatCompletionToolParam from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema
from runner import configure from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
@@ -66,15 +67,10 @@ async def main():
# sent to the same callback with an additional function_name parameter. # sent to the same callback with an additional function_name parameter.
llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather) llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather)
tools = [ weather_function = FunctionSchema(
ChatCompletionToolParam( name="get_current_weather",
type="function", description="Get the current weather",
function={ properties={
"name": "get_current_weather",
"description": "Get the current weather for a specific location. You MUST use this function whenever asked about weather.",
"parameters": {
"type": "object",
"properties": {
"location": { "location": {
"type": "string", "type": "string",
"description": "The city and state, e.g. San Francisco, CA", "description": "The city and state, e.g. San Francisco, CA",
@@ -82,14 +78,12 @@ async def main():
"format": { "format": {
"type": "string", "type": "string",
"enum": ["celsius", "fahrenheit"], "enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use. Use fahrenheit for US locations, celsius for others.", "description": "The temperature unit to use. Infer this from the user's location.",
},
},
"required": ["location", "format"],
}, },
}, },
required=["location", "format"],
) )
] tools = ToolsSchema(standard_tools=[weather_function])
messages = [ messages = [
{ {
"role": "system", "role": "system",

View File

@@ -11,7 +11,8 @@ import sys
import aiohttp import aiohttp
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
from openai.types.chat import ChatCompletionToolParam from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema
from runner import configure from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
@@ -70,15 +71,10 @@ async def main():
# sent to the same callback with an additional function_name parameter. # sent to the same callback with an additional function_name parameter.
llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather) llm.register_function(None, fetch_weather_from_api, start_callback=start_fetch_weather)
tools = [ weather_function = FunctionSchema(
ChatCompletionToolParam( name="get_current_weather",
type="function", description="Get the current weather",
function={ properties={
"name": "get_current_weather",
"description": "Get the current weather",
"parameters": {
"type": "object",
"properties": {
"location": { "location": {
"type": "string", "type": "string",
"description": "The city and state, e.g. San Francisco, CA", "description": "The city and state, e.g. San Francisco, CA",
@@ -86,14 +82,12 @@ async def main():
"format": { "format": {
"type": "string", "type": "string",
"enum": ["celsius", "fahrenheit"], "enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use. Infer this from the users location.", "description": "The temperature unit to use. Infer this from the user's location.",
},
},
"required": ["location", "format"],
}, },
}, },
required=["location", "format"],
) )
] tools = ToolsSchema(standard_tools=[weather_function])
messages = [ messages = [
{ {
"role": "system", "role": "system",

View File

@@ -11,7 +11,8 @@ import sys
import aiohttp import aiohttp
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
from openai.types.chat import ChatCompletionToolParam from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema
from runner import configure from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
@@ -68,15 +69,10 @@ async def main():
"get_current_weather", fetch_weather_from_api, start_callback=start_fetch_weather "get_current_weather", fetch_weather_from_api, start_callback=start_fetch_weather
) )
tools = [ weather_function = FunctionSchema(
ChatCompletionToolParam( name="get_current_weather",
type="function", description="Get the current weather",
function={ properties={
"name": "get_current_weather",
"description": "Get the current weather",
"parameters": {
"type": "object",
"properties": {
"location": { "location": {
"type": "string", "type": "string",
"description": "The city and state, e.g. San Francisco, CA", "description": "The city and state, e.g. San Francisco, CA",
@@ -84,14 +80,12 @@ async def main():
"format": { "format": {
"type": "string", "type": "string",
"enum": ["celsius", "fahrenheit"], "enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use. Infer this from the users location.", "description": "The temperature unit to use. Infer this from the user's location.",
},
},
"required": ["location", "format"],
}, },
}, },
required=["location", "format"],
) )
] tools = ToolsSchema(standard_tools=[weather_function])
messages = [ messages = [
{ {
"role": "user", "role": "user",