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