1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 pythonOlder,
6
7 # build-system
8 pdm-backend,
9
10 # buildInputs
11 bash,
12
13 # dependencies
14 aiohttp,
15 async-timeout,
16 langchain-core,
17 langchain-text-splitters,
18 langsmith,
19 numpy,
20 pydantic,
21 pyyaml,
22 requests,
23 sqlalchemy,
24 tenacity,
25
26 # tests
27 blockbuster,
28 freezegun,
29 httpx,
30 lark,
31 pandas,
32 pytest-asyncio,
33 pytest-mock,
34 pytest-socket,
35 pytestCheckHook,
36 requests-mock,
37 responses,
38 syrupy,
39 toml,
40
41 # passthru
42 gitUpdater,
43}:
44
45buildPythonPackage rec {
46 pname = "langchain";
47 version = "0.3.72";
48 pyproject = true;
49
50 src = fetchFromGitHub {
51 owner = "langchain-ai";
52 repo = "langchain";
53 tag = "langchain-core==${version}";
54 hash = "sha256-Q2uGMiODUtwkPdOyuSqp8vqjlLjiXk75QjXp7rr20tc=";
55 };
56
57 sourceRoot = "${src.name}/libs/langchain";
58
59 build-system = [ pdm-backend ];
60
61 buildInputs = [ bash ];
62
63 pythonRelaxDeps = [
64 # Each component release requests the exact latest core.
65 # That prevents us from updating individual components.
66 "langchain-core"
67 "numpy"
68 "tenacity"
69 ];
70
71 dependencies = [
72 aiohttp
73 langchain-core
74 langchain-text-splitters
75 langsmith
76 numpy
77 pydantic
78 pyyaml
79 requests
80 sqlalchemy
81 tenacity
82 ]
83 ++ lib.optional (pythonOlder "3.11") async-timeout;
84
85 optional-dependencies = {
86 numpy = [ numpy ];
87 };
88
89 nativeCheckInputs = [
90 blockbuster
91 freezegun
92 httpx
93 lark
94 pandas
95 pytest-asyncio
96 pytest-mock
97 pytest-socket
98 pytestCheckHook
99 requests-mock
100 responses
101 syrupy
102 toml
103 ];
104
105 pytestFlags = [
106 "--only-core"
107 ];
108
109 enabledTestPaths = [
110 # integration_tests require network access, database access and require `OPENAI_API_KEY`, etc.
111 "tests/unit_tests"
112 ];
113
114 disabledTests = [
115 # These tests have database access
116 "test_table_info"
117 "test_sql_database_run"
118 # These tests have network access
119 "test_socket_disabled"
120 "test_openai_agent_with_streaming"
121 "test_openai_agent_tools_agent"
122 # This test may require a specific version of langchain-community
123 "test_compatible_vectorstore_documentation"
124 # AssertionErrors
125 "test_callback_handlers"
126 "test_generic_fake_chat_model"
127 # Test is outdated
128 "test_serializable_mapping"
129 "test_person"
130 "test_aliases_hidden"
131 # AssertionError: (failed string match due to terminal control chars in output)
132 # https://github.com/langchain-ai/langchain/issues/32150
133 "test_filecallback"
134 ];
135
136 disabledTestPaths = [
137 # pydantic.errors.PydanticUserError: `ConversationSummaryMemory` is not fully defined; you should define `BaseCache`, then call `ConversationSummaryMemory.model_rebuild()`.
138 "tests/unit_tests/chains/test_conversation.py"
139 # pydantic.errors.PydanticUserError: `ConversationSummaryMemory` is not fully defined; you should define `BaseCache`, then call `ConversationSummaryMemory.model_rebuild()`.
140 "tests/unit_tests/chains/test_memory.py"
141 # pydantic.errors.PydanticUserError: `ConversationSummaryBufferMemory` is not fully defined; you should define `BaseCache`, then call `ConversationSummaryBufferMemory.model_rebuild()`.
142 "tests/unit_tests/chains/test_summary_buffer_memory.py"
143 "tests/unit_tests/output_parsers/test_fix.py"
144 "tests/unit_tests/chains/test_llm_checker.py"
145 # TypeError: Can't instantiate abstract class RunnableSerializable[RetryOutputParserRetryChainInput, str] without an implementation for abstract method 'invoke'
146 "tests/unit_tests/output_parsers/test_retry.py"
147 # pydantic.errors.PydanticUserError: `LLMSummarizationCheckerChain` is not fully defined; you should define `BaseCache`, then call `LLMSummarizationCheckerChain.model_rebuild()`.
148 "tests/unit_tests/chains/test_llm_summarization_checker.py"
149 ];
150
151 pythonImportsCheck = [ "langchain" ];
152
153 passthru.updateScript = gitUpdater {
154 rev-prefix = "langchain==";
155 };
156
157 __darwinAllowLocalNetworking = true;
158
159 meta = {
160 description = "Building applications with LLMs through composability";
161 homepage = "https://github.com/langchain-ai/langchain";
162 changelog = "https://github.com/langchain-ai/langchain/releases/tag/${src.tag}";
163 license = lib.licenses.mit;
164 maintainers = with lib.maintainers; [
165 natsukium
166 sarahec
167 ];
168 mainProgram = "langchain-server";
169 };
170}