1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5
6 # build-system
7 pdm-backend,
8
9 # dependencies
10 langchain-core,
11 openai,
12 tiktoken,
13
14 # tests
15 freezegun,
16 langchain-tests,
17 lark,
18 pandas,
19 pytest-asyncio,
20 pytestCheckHook,
21 pytest-mock,
22 pytest-socket,
23 requests-mock,
24 responses,
25 syrupy,
26 toml,
27
28 # passthru
29 nix-update-script,
30}:
31
32buildPythonPackage rec {
33 pname = "langchain-openai";
34 version = "0.3.16";
35 pyproject = true;
36
37 src = fetchFromGitHub {
38 owner = "langchain-ai";
39 repo = "langchain";
40 tag = "langchain-openai==${version}";
41 hash = "sha256-e8y5rL+OUFOAPfXTC+XHn/wVfsecPInsS8hBxm1USAw=";
42 };
43
44 sourceRoot = "${src.name}/libs/partners/openai";
45
46 preConfigure = ''
47 substituteInPlace pyproject.toml \
48 --replace-fail "--cov=langchain_openai" ""
49 '';
50
51 build-system = [ pdm-backend ];
52
53 pythonRelaxDeps = [
54 # Each component release requests the exact latest core.
55 # That prevents us from updating individul components.
56 "langchain-core"
57 ];
58
59 dependencies = [
60 langchain-core
61 openai
62 tiktoken
63 ];
64
65 nativeCheckInputs = [
66 freezegun
67 langchain-tests
68 lark
69 pandas
70 pytest-asyncio
71 pytestCheckHook
72 pytest-mock
73 pytest-socket
74 requests-mock
75 responses
76 syrupy
77 toml
78 ];
79
80 pytestFlagsArray = [ "tests/unit_tests" ];
81
82 disabledTests = [
83 # These tests require network access
84 "test__convert_dict_to_message_tool_call"
85 "test__get_encoding_model"
86 "test_azure_openai_api_key_is_secret_string"
87 "test_azure_openai_api_key_masked_when_passed_from_env"
88 "test_azure_openai_api_key_masked_when_passed_via_constructor"
89 "test_azure_openai_secrets"
90 "test_azure_openai_uses_actual_secret_value_from_secretstr"
91 "test_azure_serialized_secrets"
92 "test_chat_openai_get_num_tokens"
93 "test_embed_documents_with_custom_chunk_size"
94 "test_get_num_tokens_from_messages"
95 "test_get_token_ids"
96 "test_init_o1"
97 "test_openai_get_num_tokens"
98 ];
99
100 pythonImportsCheck = [ "langchain_openai" ];
101
102 passthru.updateScript = nix-update-script {
103 extraArgs = [
104 "--version-regex"
105 "langchain-openai==([0-9.]+)"
106 ];
107 };
108
109 meta = {
110 changelog = "https://github.com/langchain-ai/langchain/releases/tag/langchain-openai==${version}";
111 description = "Integration package connecting OpenAI and LangChain";
112 homepage = "https://github.com/langchain-ai/langchain/tree/master/libs/partners/openai";
113 license = lib.licenses.mit;
114 maintainers = with lib.maintainers; [
115 natsukium
116 sarahec
117 ];
118 };
119}