Skip to content

Commit 14440b4

Browse files
committed
fix: switch langchain imports to core
1 parent 96d36d5 commit 14440b4

7 files changed

+163
-77
lines changed

langfuse/callback/langchain.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import pydantic
77

8-
try: # Test that langchain is installed before proceeding
9-
import langchain # noqa
8+
try: # Test that langchain core is installed before proceeding
9+
import langchain_core # noqa
1010
except ImportError as e:
1111
log = logging.getLogger("langfuse")
1212
log.error(
@@ -24,11 +24,11 @@
2424
from langfuse.utils.base_callback_handler import LangfuseBaseCallbackHandler
2525

2626
try:
27-
from langchain.callbacks.base import (
27+
from langchain_core.callbacks.base import (
2828
BaseCallbackHandler as LangchainBaseCallbackHandler,
2929
)
30-
from langchain.schema.agent import AgentAction, AgentFinish
31-
from langchain.schema.document import Document
30+
from langchain_core.agents import AgentAction, AgentFinish
31+
from langchain_core.documents import Document
3232
from langchain_core.outputs import (
3333
ChatGeneration,
3434
LLMResult,
@@ -44,7 +44,8 @@
4444
)
4545
except ImportError:
4646
raise ModuleNotFoundError(
47-
"Please install langchain to use the Langfuse langchain integration: 'pip install langchain'"
47+
"Please install 'langchain core' to use the Langfuse langchain integration:"
48+
" 'pip install langchain-core'"
4849
)
4950

5051

langfuse/serializer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
# Attempt to import Serializable
1717
try:
18-
from langchain.load.serializable import Serializable
18+
from langchain_core.load.serializable import Serializable
1919
except ImportError:
2020
# If Serializable is not available, set it to NoneType
2121
Serializable = type(None)

poetry.lock

+145-63
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pydantic = ">=1.10.7, <3.0"
1313
backoff = ">=1.10.0"
1414
openai = { version = ">=0.27.8", optional = true }
1515
wrapt = "^1.14"
16-
langchain = { version = ">=0.0.309", optional = true }
16+
langchain-core = { version = ">=0.2.0", optional = true }
1717
llama-index = {version = ">=0.10.12, <2.0.0", optional = true}
1818
packaging = "^23.2"
1919
idna = "^3.7"
@@ -48,13 +48,16 @@ bson = "^0.5.10"
4848
langchain-anthropic = "^0.1.4"
4949
langchain-groq = "^0.1.3"
5050
langchain-aws = "^0.1.3"
51+
langchain = "^0.2.9"
52+
langchain-cohere = "^0.1.9"
53+
langchain-community = "^0.2.7"
5154

5255
[tool.poetry.group.docs.dependencies]
5356
pdoc = "^14.4.0"
5457

5558
[tool.poetry.extras]
5659
openai = ["openai"]
57-
langchain = ["langchain"]
60+
langchain = ["langchain-core"]
5861
llama-index = ["llama-index"]
5962

6063
[build-system]
@@ -67,4 +70,4 @@ log_cli = true
6770
[tool.poetry_bumpversion.file."langfuse/version.py"]
6871

6972
[tool.poetry.scripts]
70-
release = "scripts.release:main"
73+
release = "scripts.release:main"

tests/test_decorators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from concurrent.futures import ThreadPoolExecutor
55
import pytest
66

7-
from langchain_community.chat_models import ChatOpenAI
7+
from langchain_openai import ChatOpenAI
88
from langchain.prompts import ChatPromptTemplate
99
from langfuse.openai import AsyncOpenAI
1010
from langfuse.decorators import langfuse_context, observe

tests/test_langchain.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ def test_aws_bedrock_chain():
14011401
import os
14021402

14031403
import boto3
1404-
from langchain.llms.bedrock import Bedrock
1404+
from langchain_aws import Bedrock
14051405

14061406
api_wrapper = LangfuseAPI()
14071407
handler = CallbackHandler(debug=False)

tests/test_langchain_integration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from langchain_openai import ChatOpenAI, OpenAI
2-
from langchain.prompts import ChatPromptTemplate, PromptTemplate
3-
from langchain.schema import StrOutputParser
2+
from langchain_core.prompts import ChatPromptTemplate, PromptTemplate
3+
from langchain_core.output_parsers import StrOutputParser
44
import pytest
55
import types
66
from langfuse.callback import CallbackHandler

0 commit comments

Comments
 (0)