fix(langchain): try/catch langchain import in service; Only langchain is installed with the [langchain] extra (#190)
This commit is contained in:
@@ -36,7 +36,7 @@ try:
|
|||||||
|
|
||||||
except ModuleNotFoundError as e:
|
except ModuleNotFoundError as e:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
"You need to `pip install langchain langchain-openai langchain-community` for this example. Also, be sure to set `OPENAI_API_KEY` in the environment variable."
|
"In order to run this example you need to `pip install pipecat-ai[langchain] langchain-community langchain-openai. Also, be sure to set `OPENAI_API_KEY` in the environment variable."
|
||||||
)
|
)
|
||||||
raise Exception(f"Missing module: {e}")
|
raise Exception(f"Missing module: {e}")
|
||||||
|
|
||||||
@@ -94,12 +94,12 @@ async def main(room_url: str, token):
|
|||||||
|
|
||||||
pipeline = Pipeline(
|
pipeline = Pipeline(
|
||||||
[
|
[
|
||||||
transport.input(), # Transport user input
|
transport.input(), # Transport user input
|
||||||
tma_in, # User responses
|
tma_in, # User responses
|
||||||
lc, # Langchain
|
lc, # Langchain
|
||||||
tts, # TTS
|
tts, # TTS
|
||||||
transport.output(), # Transport bot output
|
transport.output(), # Transport bot output
|
||||||
tma_out, # Assistant spoken responses
|
tma_out, # Assistant spoken responses
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ examples = [ "python-dotenv~=1.0.0", "flask~=3.0.3", "flask_cors~=4.0.1" ]
|
|||||||
fal = [ "fal-client~=0.4.0" ]
|
fal = [ "fal-client~=0.4.0" ]
|
||||||
google = [ "google-generativeai~=0.5.3" ]
|
google = [ "google-generativeai~=0.5.3" ]
|
||||||
fireworks = [ "openai~=1.26.0" ]
|
fireworks = [ "openai~=1.26.0" ]
|
||||||
langchain = [ "langchain~=0.2.1", "langchain-community~=0.2.1" ]
|
langchain = [ "langchain~=0.2.1" ]
|
||||||
local = [ "pyaudio~=0.2.0" ]
|
local = [ "pyaudio~=0.2.0" ]
|
||||||
moondream = [ "einops~=0.8.0", "timm~=0.9.16", "transformers~=4.40.2" ]
|
moondream = [ "einops~=0.8.0", "timm~=0.9.16", "transformers~=4.40.2" ]
|
||||||
openai = [ "openai~=1.26.0" ]
|
openai = [ "openai~=1.26.0" ]
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from langchain_core.messages import AIMessageChunk
|
|
||||||
from langchain_core.runnables import Runnable
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from pipecat.frames.frames import (Frame, LLMFullResponseEndFrame,
|
from pipecat.frames.frames import (Frame, LLMFullResponseEndFrame,
|
||||||
@@ -11,6 +9,15 @@ from pipecat.frames.frames import (Frame, LLMFullResponseEndFrame,
|
|||||||
TextFrame)
|
TextFrame)
|
||||||
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
|
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):
|
class LangchainProcessor(FrameProcessor):
|
||||||
def __init__(self, chain: Runnable, transcript_key: str = "input"):
|
def __init__(self, chain: Runnable, transcript_key: str = "input"):
|
||||||
|
|||||||
Reference in New Issue
Block a user