fix(langchain): try/catch langchain import in service; Only langchain is installed with the [langchain] extra (#190)
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import sys
|
||||
from typing import Union
|
||||
|
||||
from langchain_core.messages import AIMessageChunk
|
||||
from langchain_core.runnables import Runnable
|
||||
from loguru import logger
|
||||
|
||||
from pipecat.frames.frames import (Frame, LLMFullResponseEndFrame,
|
||||
@@ -11,6 +9,15 @@ from pipecat.frames.frames import (Frame, LLMFullResponseEndFrame,
|
||||
TextFrame)
|
||||
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
|
||||
|
||||
try:
|
||||
from langchain_core.messages import AIMessageChunk
|
||||
from langchain_core.runnables import Runnable
|
||||
except ModuleNotFoundError as e:
|
||||
logger.exception(
|
||||
"In order to use Langchain, you need to `pip install pipecat-ai[langchain]`. "
|
||||
)
|
||||
raise Exception(f"Missing module: {e}")
|
||||
|
||||
|
||||
class LangchainProcessor(FrameProcessor):
|
||||
def __init__(self, chain: Runnable, transcript_key: str = "input"):
|
||||
|
||||
Reference in New Issue
Block a user