1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6
7 # build-system
8 pdm-backend,
9
10 # dependencies
11 jsonpatch,
12 langsmith,
13 packaging,
14 pydantic,
15 pyyaml,
16 tenacity,
17 typing-extensions,
18
19 # tests
20 blockbuster,
21 freezegun,
22 grandalf,
23 httpx,
24 langchain-core,
25 langchain-tests,
26 numpy,
27 pytest-asyncio,
28 pytest-mock,
29 pytest-xdist,
30 pytestCheckHook,
31 syrupy,
32
33 # passthru
34 gitUpdater,
35}:
36
37buildPythonPackage rec {
38 pname = "langchain-core";
39 version = "0.3.72";
40 pyproject = true;
41
42 src = fetchFromGitHub {
43 owner = "langchain-ai";
44 repo = "langchain";
45 tag = "langchain-core==${version}";
46 hash = "sha256-Q2uGMiODUtwkPdOyuSqp8vqjlLjiXk75QjXp7rr20tc=";
47 };
48
49 sourceRoot = "${src.name}/libs/core";
50
51 build-system = [ pdm-backend ];
52
53 pythonRelaxDeps = [
54 "packaging"
55 "tenacity"
56 ];
57
58 dependencies = [
59 jsonpatch
60 langsmith
61 packaging
62 pydantic
63 pyyaml
64 tenacity
65 typing-extensions
66 ];
67
68 pythonImportsCheck = [ "langchain_core" ];
69
70 # avoid infinite recursion
71 doCheck = false;
72
73 nativeCheckInputs = [
74 blockbuster
75 freezegun
76 grandalf
77 httpx
78 langchain-tests
79 numpy
80 pytest-asyncio
81 pytest-mock
82 pytest-xdist
83 pytestCheckHook
84 syrupy
85 ];
86
87 enabledTestPaths = [ "tests/unit_tests" ];
88
89 passthru = {
90 tests.pytest = langchain-core.overridePythonAttrs (_: {
91 doCheck = true;
92 });
93 # python updater script sets the wrong tag
94 skipBulkUpdate = true;
95 updateScript = gitUpdater {
96 rev-prefix = "langchain-core==";
97 };
98 };
99
100 disabledTests = [
101 # flaky, sometimes fail to strip uuid from AIMessageChunk before comparing to test value
102 "test_map_stream"
103 # Compares with machine-specific timings
104 "test_rate_limit"
105 # flaky: assert (1726352133.7419367 - 1726352132.2697523) < 1
106 "test_benchmark_model"
107
108 # TypeError: exceptions must be derived from Warning, not <class 'NoneType'>
109 "test_chat_prompt_template_variable_names"
110 "test_create_model_v2"
111
112 # Comparison with magic strings
113 "test_prompt_with_chat_model"
114 "test_prompt_with_chat_model_async"
115 "test_prompt_with_llm"
116 "test_prompt_with_llm_parser"
117 "test_prompt_with_llm_and_async_lambda"
118 "test_prompt_with_chat_model_and_parser"
119 "test_combining_sequences"
120
121 # AssertionError: assert [+ received] == [- snapshot]
122 "test_chat_input_schema"
123 # AssertionError: assert {'$defs': {'D...ype': 'array'} == {'$defs': {'D...ype': 'array'}
124 "test_schemas"
125 # AssertionError: assert [+ received] == [- snapshot]
126 "test_graph_sequence_map"
127 "test_representation_of_runnables"
128 ]
129 ++ lib.optionals stdenv.hostPlatform.isDarwin [
130 # Langchain-core the following tests due to the test comparing execution time with magic values.
131 "test_queue_for_streaming_via_sync_call"
132 "test_same_event_loop"
133 # Comparisons with magic numbers
134 "test_rate_limit_ainvoke"
135 "test_rate_limit_astream"
136 ];
137
138 disabledTestPaths = [ "tests/unit_tests/runnables/test_runnable_events_v2.py" ];
139
140 meta = {
141 description = "Building applications with LLMs through composability";
142 homepage = "https://github.com/langchain-ai/langchain/tree/master/libs/core";
143 changelog = "https://github.com/langchain-ai/langchain/releases/tag/${src.tag}";
144 license = lib.licenses.mit;
145 maintainers = with lib.maintainers; [
146 natsukium
147 sarahec
148 ];
149 };
150}