LLMService: s/FunctionCallLLM/FunctionCallFromLLM/ s/FunctionCallRunner/FunctionCallRunnerItem/
This commit is contained in:
@@ -45,7 +45,7 @@ from pipecat.processors.aggregators.openai_llm_context import (
|
|||||||
OpenAILLMContextFrame,
|
OpenAILLMContextFrame,
|
||||||
)
|
)
|
||||||
from pipecat.processors.frame_processor import FrameDirection
|
from pipecat.processors.frame_processor import FrameDirection
|
||||||
from pipecat.services.llm_service import FunctionCallLLM, LLMService
|
from pipecat.services.llm_service import FunctionCallFromLLM, LLMService
|
||||||
from pipecat.utils.tracing.service_decorators import traced_llm
|
from pipecat.utils.tracing.service_decorators import traced_llm
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -227,7 +227,7 @@ class AnthropicLLMService(LLMService):
|
|||||||
if tool_use_block:
|
if tool_use_block:
|
||||||
args = json.loads(json_accumulator) if json_accumulator else {}
|
args = json.loads(json_accumulator) if json_accumulator else {}
|
||||||
function_calls.append(
|
function_calls.append(
|
||||||
FunctionCallLLM(
|
FunctionCallFromLLM(
|
||||||
context=context,
|
context=context,
|
||||||
tool_call_id=tool_use_block.id,
|
tool_call_id=tool_use_block.id,
|
||||||
function_name=tool_use_block.name,
|
function_name=tool_use_block.name,
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ from pipecat.processors.aggregators.openai_llm_context import (
|
|||||||
OpenAILLMContextFrame,
|
OpenAILLMContextFrame,
|
||||||
)
|
)
|
||||||
from pipecat.processors.frame_processor import FrameDirection
|
from pipecat.processors.frame_processor import FrameDirection
|
||||||
from pipecat.services.llm_service import FunctionCallLLM, LLMService
|
from pipecat.services.llm_service import FunctionCallFromLLM, LLMService
|
||||||
from pipecat.services.openai.llm import (
|
from pipecat.services.openai.llm import (
|
||||||
OpenAIAssistantContextAggregator,
|
OpenAIAssistantContextAggregator,
|
||||||
OpenAIUserContextAggregator,
|
OpenAIUserContextAggregator,
|
||||||
@@ -893,7 +893,7 @@ class GeminiMultimodalLiveLLMService(LLMService):
|
|||||||
logger.error("Function calls are not supported without a context object.")
|
logger.error("Function calls are not supported without a context object.")
|
||||||
|
|
||||||
function_calls_llm = [
|
function_calls_llm = [
|
||||||
FunctionCallLLM(
|
FunctionCallFromLLM(
|
||||||
context=self._context,
|
context=self._context,
|
||||||
tool_call_id=f.id,
|
tool_call_id=f.id,
|
||||||
function_name=f.name,
|
function_name=f.name,
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ from pipecat.processors.aggregators.openai_llm_context import (
|
|||||||
)
|
)
|
||||||
from pipecat.processors.frame_processor import FrameDirection
|
from pipecat.processors.frame_processor import FrameDirection
|
||||||
from pipecat.services.google.frames import LLMSearchResponseFrame
|
from pipecat.services.google.frames import LLMSearchResponseFrame
|
||||||
from pipecat.services.llm_service import FunctionCallLLM, LLMService
|
from pipecat.services.llm_service import FunctionCallFromLLM, LLMService
|
||||||
from pipecat.services.openai.llm import (
|
from pipecat.services.openai.llm import (
|
||||||
OpenAIAssistantContextAggregator,
|
OpenAIAssistantContextAggregator,
|
||||||
OpenAIUserContextAggregator,
|
OpenAIUserContextAggregator,
|
||||||
@@ -578,7 +578,7 @@ class GoogleLLMService(LLMService):
|
|||||||
id = function_call.id or str(uuid.uuid4())
|
id = function_call.id or str(uuid.uuid4())
|
||||||
logger.debug(f"Function call: {function_call.name}:{id}")
|
logger.debug(f"Function call: {function_call.name}:{id}")
|
||||||
function_calls.append(
|
function_calls.append(
|
||||||
FunctionCallLLM(
|
FunctionCallFromLLM(
|
||||||
context=context,
|
context=context,
|
||||||
tool_call_id=id,
|
tool_call_id=id,
|
||||||
function_name=function_call.name,
|
function_name=function_call.name,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import os
|
|||||||
from openai import AsyncStream
|
from openai import AsyncStream
|
||||||
from openai.types.chat import ChatCompletionChunk
|
from openai.types.chat import ChatCompletionChunk
|
||||||
|
|
||||||
from pipecat.services.llm_service import FunctionCallLLM
|
from pipecat.services.llm_service import FunctionCallFromLLM
|
||||||
|
|
||||||
# Suppress gRPC fork warnings
|
# Suppress gRPC fork warnings
|
||||||
os.environ["GRPC_ENABLE_FORK_SUPPORT"] = "false"
|
os.environ["GRPC_ENABLE_FORK_SUPPORT"] = "false"
|
||||||
@@ -127,7 +127,7 @@ class GoogleLLMOpenAIBetaService(OpenAILLMService):
|
|||||||
arguments = json.loads(arguments)
|
arguments = json.loads(arguments)
|
||||||
|
|
||||||
function_calls.append(
|
function_calls.append(
|
||||||
FunctionCallLLM(
|
FunctionCallFromLLM(
|
||||||
context=context,
|
context=context,
|
||||||
tool_call_id=tool_id,
|
tool_call_id=tool_id,
|
||||||
function_name=function_name,
|
function_name=function_name,
|
||||||
|
|||||||
@@ -44,62 +44,6 @@ class FunctionCallResultCallback(Protocol):
|
|||||||
) -> None: ...
|
) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class FunctionCallRegistryItem:
|
|
||||||
"""Represents an entry of our function call registry.
|
|
||||||
|
|
||||||
Attributes:
|
|
||||||
function_name (Optional[str]): The name of the function.
|
|
||||||
handler (FunctionCallHandler): The handler for processing function call parameters.
|
|
||||||
cancel_on_interruption (bool): Flag indicating whether to cancel the call on interruption.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
function_name: Optional[str]
|
|
||||||
handler: FunctionCallHandler
|
|
||||||
cancel_on_interruption: bool
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class FunctionCallLLM:
|
|
||||||
"""Represents a function call returned by the LLM to be registered for execution.
|
|
||||||
|
|
||||||
Attributes:
|
|
||||||
function_name (str): The name of the function.
|
|
||||||
tool_call_id (str): A unique identifier for the function call.
|
|
||||||
arguments (Mapping[str, Any]): The arguments for the function.
|
|
||||||
context (OpenAILLMContext): The LLM context.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
function_name: str
|
|
||||||
tool_call_id: str
|
|
||||||
arguments: Mapping[str, Any]
|
|
||||||
context: OpenAILLMContext
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class FunctionCallRunner:
|
|
||||||
"""Represents an internal function call entry to our function call
|
|
||||||
runner. The runner executes function calls in order.
|
|
||||||
|
|
||||||
Attributes:
|
|
||||||
registry_name (Optional[str]): The function call name registration (could be None).
|
|
||||||
function_name (str): The name of the function.
|
|
||||||
tool_call_id (str): A unique identifier for the function call.
|
|
||||||
arguments (Mapping[str, Any]): The arguments for the function.
|
|
||||||
context (OpenAILLMContext): The LLM context.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
registry_item: FunctionCallRegistryItem
|
|
||||||
function_name: str
|
|
||||||
tool_call_id: str
|
|
||||||
arguments: Mapping[str, Any]
|
|
||||||
context: OpenAILLMContext
|
|
||||||
run_llm: Optional[bool] = None
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class FunctionCallParams:
|
class FunctionCallParams:
|
||||||
"""Parameters for a function call.
|
"""Parameters for a function call.
|
||||||
@@ -122,6 +66,63 @@ class FunctionCallParams:
|
|||||||
result_callback: FunctionCallResultCallback
|
result_callback: FunctionCallResultCallback
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class FunctionCallFromLLM:
|
||||||
|
"""Represents a function call returned by the LLM to be registered for execution.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
function_name (str): The name of the function.
|
||||||
|
tool_call_id (str): A unique identifier for the function call.
|
||||||
|
arguments (Mapping[str, Any]): The arguments for the function.
|
||||||
|
context (OpenAILLMContext): The LLM context.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
function_name: str
|
||||||
|
tool_call_id: str
|
||||||
|
arguments: Mapping[str, Any]
|
||||||
|
context: OpenAILLMContext
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class FunctionCallRegistryItem:
|
||||||
|
"""Represents an entry in our function call registry. This is what the user
|
||||||
|
registers.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
function_name (Optional[str]): The name of the function.
|
||||||
|
handler (FunctionCallHandler): The handler for processing function call parameters.
|
||||||
|
cancel_on_interruption (bool): Flag indicating whether to cancel the call on interruption.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
function_name: Optional[str]
|
||||||
|
handler: FunctionCallHandler
|
||||||
|
cancel_on_interruption: bool
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class FunctionCallRunnerItem:
|
||||||
|
"""Represents an internal function call entry to our function call
|
||||||
|
runner. The runner executes function calls in order.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
registry_name (Optional[str]): The function call name registration (could be None).
|
||||||
|
function_name (str): The name of the function.
|
||||||
|
tool_call_id (str): A unique identifier for the function call.
|
||||||
|
arguments (Mapping[str, Any]): The arguments for the function.
|
||||||
|
context (OpenAILLMContext): The LLM context.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
registry_item: FunctionCallRegistryItem
|
||||||
|
function_name: str
|
||||||
|
tool_call_id: str
|
||||||
|
arguments: Mapping[str, Any]
|
||||||
|
context: OpenAILLMContext
|
||||||
|
run_llm: Optional[bool] = None
|
||||||
|
|
||||||
|
|
||||||
class LLMService(AIService):
|
class LLMService(AIService):
|
||||||
"""This class is a no-op but serves as a base class for LLM services."""
|
"""This class is a no-op but serves as a base class for LLM services."""
|
||||||
|
|
||||||
@@ -135,7 +136,7 @@ class LLMService(AIService):
|
|||||||
self._start_callbacks = {}
|
self._start_callbacks = {}
|
||||||
self._adapter = self.adapter_class()
|
self._adapter = self.adapter_class()
|
||||||
self._functions: Dict[Optional[str], FunctionCallRegistryItem] = {}
|
self._functions: Dict[Optional[str], FunctionCallRegistryItem] = {}
|
||||||
self._function_call_tasks: Dict[asyncio.Task, FunctionCallRunner] = {}
|
self._function_call_tasks: Dict[asyncio.Task, FunctionCallRunnerItem] = {}
|
||||||
self._sequential_runner_task: Optional[asyncio.Task] = None
|
self._sequential_runner_task: Optional[asyncio.Task] = None
|
||||||
|
|
||||||
self._register_event_handler("on_completion_timeout")
|
self._register_event_handler("on_completion_timeout")
|
||||||
@@ -217,7 +218,7 @@ class LLMService(AIService):
|
|||||||
return True
|
return True
|
||||||
return function_name in self._functions.keys()
|
return function_name in self._functions.keys()
|
||||||
|
|
||||||
async def run_function_calls(self, function_calls: Sequence[FunctionCallLLM]):
|
async def run_function_calls(self, function_calls: Sequence[FunctionCallFromLLM]):
|
||||||
total_function_calls = len(function_calls)
|
total_function_calls = len(function_calls)
|
||||||
for index, function_call in enumerate(function_calls):
|
for index, function_call in enumerate(function_calls):
|
||||||
if function_call.function_name in self._functions.keys():
|
if function_call.function_name in self._functions.keys():
|
||||||
@@ -237,7 +238,7 @@ class LLMService(AIService):
|
|||||||
if not self._run_in_parallel:
|
if not self._run_in_parallel:
|
||||||
run_llm = index == total_function_calls - 1
|
run_llm = index == total_function_calls - 1
|
||||||
|
|
||||||
runner_item = FunctionCallRunner(
|
runner_item = FunctionCallRunnerItem(
|
||||||
registry_item=item,
|
registry_item=item,
|
||||||
function_name=function_call.function_name,
|
function_name=function_call.function_name,
|
||||||
tool_call_id=function_call.tool_call_id,
|
tool_call_id=function_call.tool_call_id,
|
||||||
@@ -299,7 +300,7 @@ class LLMService(AIService):
|
|||||||
await self.wait_for_task(task)
|
await self.wait_for_task(task)
|
||||||
del self._function_call_tasks[task]
|
del self._function_call_tasks[task]
|
||||||
|
|
||||||
async def _run_function_call(self, runner_item: FunctionCallRunner):
|
async def _run_function_call(self, runner_item: FunctionCallRunnerItem):
|
||||||
if runner_item.function_name in self._functions.keys():
|
if runner_item.function_name in self._functions.keys():
|
||||||
item = self._functions[runner_item.function_name]
|
item = self._functions[runner_item.function_name]
|
||||||
elif None in self._functions.keys():
|
elif None in self._functions.keys():
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ from pipecat.processors.aggregators.openai_llm_context import (
|
|||||||
OpenAILLMContextFrame,
|
OpenAILLMContextFrame,
|
||||||
)
|
)
|
||||||
from pipecat.processors.frame_processor import FrameDirection
|
from pipecat.processors.frame_processor import FrameDirection
|
||||||
from pipecat.services.llm_service import FunctionCallLLM, LLMService
|
from pipecat.services.llm_service import FunctionCallFromLLM, LLMService
|
||||||
from pipecat.utils.tracing.service_decorators import traced_llm
|
from pipecat.utils.tracing.service_decorators import traced_llm
|
||||||
|
|
||||||
|
|
||||||
@@ -263,7 +263,7 @@ class BaseOpenAILLMService(LLMService):
|
|||||||
):
|
):
|
||||||
arguments = json.loads(arguments)
|
arguments = json.loads(arguments)
|
||||||
function_calls.append(
|
function_calls.append(
|
||||||
FunctionCallLLM(
|
FunctionCallFromLLM(
|
||||||
context=context,
|
context=context,
|
||||||
tool_call_id=tool_id,
|
tool_call_id=tool_id,
|
||||||
function_name=function_name,
|
function_name=function_name,
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ from pipecat.processors.aggregators.openai_llm_context import (
|
|||||||
OpenAILLMContextFrame,
|
OpenAILLMContextFrame,
|
||||||
)
|
)
|
||||||
from pipecat.processors.frame_processor import FrameDirection
|
from pipecat.processors.frame_processor import FrameDirection
|
||||||
from pipecat.services.llm_service import FunctionCallLLM, LLMService
|
from pipecat.services.llm_service import FunctionCallFromLLM, LLMService
|
||||||
from pipecat.services.openai.llm import OpenAIContextAggregatorPair
|
from pipecat.services.openai.llm import OpenAIContextAggregatorPair
|
||||||
from pipecat.transcriptions.language import Language
|
from pipecat.transcriptions.language import Language
|
||||||
from pipecat.utils.time import time_now_iso8601
|
from pipecat.utils.time import time_now_iso8601
|
||||||
@@ -587,7 +587,7 @@ class OpenAIRealtimeBetaLLMService(LLMService):
|
|||||||
for item in items:
|
for item in items:
|
||||||
args = json.loads(item.arguments)
|
args = json.loads(item.arguments)
|
||||||
function_calls.append(
|
function_calls.append(
|
||||||
FunctionCallLLM(
|
FunctionCallFromLLM(
|
||||||
context=self._context,
|
context=self._context,
|
||||||
tool_call_id=item.call_id,
|
tool_call_id=item.call_id,
|
||||||
function_name=item.name,
|
function_name=item.name,
|
||||||
|
|||||||
Reference in New Issue
Block a user