Set tool choice from context aggregator
This commit is contained in:
@@ -362,6 +362,12 @@ class LLMSetToolsFrame(DataFrame):
|
|||||||
|
|
||||||
tools: List[dict]
|
tools: List[dict]
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class LLMSetToolChoiceFrame(DataFrame):
|
||||||
|
"""A frame containing a tool choice for an LLM to use for function calling."""
|
||||||
|
|
||||||
|
tool_choice: Literal["none", "auto", "required"]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class LLMEnablePromptCachingFrame(DataFrame):
|
class LLMEnablePromptCachingFrame(DataFrame):
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import time
|
import time
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from typing import List
|
from typing import List, Literal
|
||||||
|
|
||||||
from pipecat.frames.frames import (
|
from pipecat.frames.frames import (
|
||||||
CancelFrame,
|
CancelFrame,
|
||||||
@@ -22,6 +22,7 @@ from pipecat.frames.frames import (
|
|||||||
LLMMessagesFrame,
|
LLMMessagesFrame,
|
||||||
LLMMessagesUpdateFrame,
|
LLMMessagesUpdateFrame,
|
||||||
LLMSetToolsFrame,
|
LLMSetToolsFrame,
|
||||||
|
LLMSetToolChoiceFrame,
|
||||||
LLMTextFrame,
|
LLMTextFrame,
|
||||||
StartFrame,
|
StartFrame,
|
||||||
StartInterruptionFrame,
|
StartInterruptionFrame,
|
||||||
@@ -132,6 +133,11 @@ class BaseLLMResponseAggregator(FrameProcessor):
|
|||||||
"""Set LLM tools to be used in the current conversation."""
|
"""Set LLM tools to be used in the current conversation."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def set_tool_choice(self, tool_choice):
|
||||||
|
"""Set the tool choice. This should modify the LLM context."""
|
||||||
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def reset(self):
|
def reset(self):
|
||||||
"""Reset the internals of this aggregator. This should not modify the
|
"""Reset the internals of this aggregator. This should not modify the
|
||||||
@@ -185,6 +191,9 @@ class LLMResponseAggregator(BaseLLMResponseAggregator):
|
|||||||
def set_tools(self, tools):
|
def set_tools(self, tools):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def set_tool_choice(self, tool_choice):
|
||||||
|
pass
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self._aggregation = ""
|
self._aggregation = ""
|
||||||
|
|
||||||
@@ -244,6 +253,9 @@ class LLMContextResponseAggregator(BaseLLMResponseAggregator):
|
|||||||
def set_tools(self, tools: List):
|
def set_tools(self, tools: List):
|
||||||
self._context.set_tools(tools)
|
self._context.set_tools(tools)
|
||||||
|
|
||||||
|
def set_tool_choice(self, tool_choice: Literal["none", "auto", "required"]):
|
||||||
|
self._context.set_tool_choice(tool_choice)
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self._aggregation = ""
|
self._aggregation = ""
|
||||||
|
|
||||||
@@ -328,6 +340,8 @@ class LLMUserContextAggregator(LLMContextResponseAggregator):
|
|||||||
self.set_messages(frame.messages)
|
self.set_messages(frame.messages)
|
||||||
elif isinstance(frame, LLMSetToolsFrame):
|
elif isinstance(frame, LLMSetToolsFrame):
|
||||||
self.set_tools(frame.tools)
|
self.set_tools(frame.tools)
|
||||||
|
elif isinstance(frame, LLMSetToolChoiceFrame):
|
||||||
|
self.set_tool_choice(frame.tool_choice)
|
||||||
else:
|
else:
|
||||||
await self.push_frame(frame, direction)
|
await self.push_frame(frame, direction)
|
||||||
|
|
||||||
@@ -448,6 +462,8 @@ class LLMAssistantContextAggregator(LLMContextResponseAggregator):
|
|||||||
self.set_messages(frame.messages)
|
self.set_messages(frame.messages)
|
||||||
elif isinstance(frame, LLMSetToolsFrame):
|
elif isinstance(frame, LLMSetToolsFrame):
|
||||||
self.set_tools(frame.tools)
|
self.set_tools(frame.tools)
|
||||||
|
elif isinstance(frame, LLMSetToolChoiceFrame):
|
||||||
|
self.set_tool_choice(frame.tool_choice)
|
||||||
else:
|
else:
|
||||||
await self.push_frame(frame, direction)
|
await self.push_frame(frame, direction)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user