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 nix-update-script,
35}:
36
37buildPythonPackage rec {
38 pname = "langchain-core";
39 version = "0.3.59";
40 pyproject = true;
41
42 src = fetchFromGitHub {
43 owner = "langchain-ai";
44 repo = "langchain";
45 tag = "langchain-core==${version}";
46 hash = "sha256-qfNt6rH2nHIFfzqZCTsIhWfXntRXvSKnzfQrNS3LWcs=";
47 };
48
49 sourceRoot = "${src.name}/libs/core";
50
51 build-system = [ pdm-backend ];
52
53 pythonRelaxDeps = [ "tenacity" ];
54
55 dependencies = [
56 jsonpatch
57 langsmith
58 packaging
59 pydantic
60 pyyaml
61 tenacity
62 typing-extensions
63 ];
64
65 pythonImportsCheck = [ "langchain_core" ];
66
67 # avoid infinite recursion
68 doCheck = false;
69
70 nativeCheckInputs = [
71 blockbuster
72 freezegun
73 grandalf
74 httpx
75 langchain-tests
76 numpy
77 pytest-asyncio
78 pytest-mock
79 pytest-xdist
80 pytestCheckHook
81 syrupy
82 ];
83
84 pytestFlagsArray = [ "tests/unit_tests" ];
85
86 passthru = {
87 tests.pytest = langchain-core.overridePythonAttrs (_: {
88 doCheck = true;
89 });
90
91 updateScript = nix-update-script {
92 extraArgs = [
93 "--version-regex"
94 "langchain-core==([0-9.]+)"
95 ];
96 };
97 };
98
99 disabledTests =
100 [
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/v${version}";
144 license = lib.licenses.mit;
145 maintainers = with lib.maintainers; [
146 natsukium
147 sarahec
148 ];
149 };
150}