Update langchain to avoid using the now-deprecated LLMMessagesFrame, LLMUserResponseAggregator, and LLMAssistantResponseAggregator
This commit is contained in:
@@ -16,13 +16,16 @@ from langchain_openai import ChatOpenAI
|
|||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from pipecat.audio.vad.silero import SileroVADAnalyzer
|
from pipecat.audio.vad.silero import SileroVADAnalyzer
|
||||||
from pipecat.frames.frames import LLMMessagesFrame
|
from pipecat.frames.frames import LLMMessagesFrame, LLMMessagesUpdateFrame
|
||||||
from pipecat.pipeline.pipeline import Pipeline
|
from pipecat.pipeline.pipeline import Pipeline
|
||||||
from pipecat.pipeline.runner import PipelineRunner
|
from pipecat.pipeline.runner import PipelineRunner
|
||||||
from pipecat.pipeline.task import PipelineParams, PipelineTask
|
from pipecat.pipeline.task import PipelineParams, PipelineTask
|
||||||
from pipecat.processors.aggregators.llm_response import (
|
from pipecat.processors.aggregators.llm_response import (
|
||||||
LLMAssistantResponseAggregator,
|
LLMAssistantContextAggregator,
|
||||||
LLMUserResponseAggregator,
|
LLMUserContextAggregator,
|
||||||
|
)
|
||||||
|
from pipecat.processors.aggregators.openai_llm_context import (
|
||||||
|
OpenAILLMContext,
|
||||||
)
|
)
|
||||||
from pipecat.processors.frameworks.langchain import LangchainProcessor
|
from pipecat.processors.frameworks.langchain import LangchainProcessor
|
||||||
from pipecat.runner.types import RunnerArguments
|
from pipecat.runner.types import RunnerArguments
|
||||||
@@ -97,8 +100,9 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
|||||||
)
|
)
|
||||||
lc = LangchainProcessor(history_chain)
|
lc = LangchainProcessor(history_chain)
|
||||||
|
|
||||||
tma_in = LLMUserResponseAggregator()
|
context = OpenAILLMContext()
|
||||||
tma_out = LLMAssistantResponseAggregator()
|
tma_in = LLMUserContextAggregator(context=context)
|
||||||
|
tma_out = LLMAssistantContextAggregator(context=context)
|
||||||
|
|
||||||
pipeline = Pipeline(
|
pipeline = Pipeline(
|
||||||
[
|
[
|
||||||
@@ -125,11 +129,11 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
|||||||
async def on_client_connected(transport, client):
|
async def on_client_connected(transport, client):
|
||||||
logger.info(f"Client connected")
|
logger.info(f"Client connected")
|
||||||
# Kick off the conversation.
|
# Kick off the conversation.
|
||||||
# the `LLMMessagesFrame` will be picked up by the LangchainProcessor using
|
# An `OpenAILLMContextFrame` will be picked up by the LangchainProcessor using
|
||||||
# only the content of the last message to inject it in the prompt defined
|
# only the content of the last message to inject it in the prompt defined
|
||||||
# above. So no role is required here.
|
# above. So no role is required here.
|
||||||
messages = [({"content": "Please briefly introduce yourself to the user."})]
|
messages = [({"content": "Please briefly introduce yourself to the user."})]
|
||||||
await task.queue_frames([LLMMessagesFrame(messages)])
|
await task.queue_frames([LLMMessagesUpdateFrame(messages, run_llm=True)])
|
||||||
|
|
||||||
@transport.event_handler("on_client_disconnected")
|
@transport.event_handler("on_client_disconnected")
|
||||||
async def on_client_disconnected(transport, client):
|
async def on_client_disconnected(transport, client):
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ from pipecat.frames.frames import (
|
|||||||
Frame,
|
Frame,
|
||||||
LLMFullResponseEndFrame,
|
LLMFullResponseEndFrame,
|
||||||
LLMFullResponseStartFrame,
|
LLMFullResponseStartFrame,
|
||||||
LLMMessagesFrame,
|
|
||||||
TextFrame,
|
TextFrame,
|
||||||
)
|
)
|
||||||
|
from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContextFrame
|
||||||
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
|
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -64,11 +64,11 @@ class LangchainProcessor(FrameProcessor):
|
|||||||
"""
|
"""
|
||||||
await super().process_frame(frame, direction)
|
await super().process_frame(frame, direction)
|
||||||
|
|
||||||
if isinstance(frame, LLMMessagesFrame):
|
if isinstance(frame, OpenAILLMContextFrame):
|
||||||
# Messages are accumulated on the context as a list of messages.
|
# Messages are accumulated on the context as a list of messages.
|
||||||
# The last one by the human is the one we want to send to the LLM.
|
# The last one by the human is the one we want to send to the LLM.
|
||||||
logger.debug(f"Got transcription frame {frame}")
|
logger.debug(f"Got transcription frame {frame}")
|
||||||
text: str = frame.messages[-1]["content"]
|
text: str = frame.context.messages[-1]["content"]
|
||||||
|
|
||||||
await self._ainvoke(text.strip())
|
await self._ainvoke(text.strip())
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user