summary refs log tree commit diff
path: root/pkgs/development/python-modules/openai/default.nix
blob: a5529af2ab156d4a4f317b8820fe91f3032f62f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
{ lib
, buildPythonPackage
, fetchFromGitHub
, aiohttp
, matplotlib
, numpy
, openpyxl
, pandas
, pandas-stubs
, plotly
, pytest-asyncio
, pytest-mock
, pytestCheckHook
, pythonOlder
, requests
, scikit-learn
, tenacity
, tqdm
, typing-extensions
, wandb
, withOptionalDependencies ? false
}:

buildPythonPackage rec {
  pname = "openai";
  version = "0.26.2";
  format = "setuptools";

  disabled = pythonOlder "3.7.1";

  src = fetchFromGitHub {
    owner = "openai";
    repo = "openai-python";
    rev = "v${version}";
    hash = "sha256-rUXwrr8hgKwqJ/ittK2DOKaqxTAs8wKyVTSdEhfiWfI=";
  };

  propagatedBuildInputs = [
    aiohttp
    requests
    tqdm
  ] ++ lib.optionals (pythonOlder "3.8") [
    typing-extensions
  ] ++ lib.optionals withOptionalDependencies (builtins.attrValues {
    inherit (passthru.optional-dependencies) embeddings wandb;
  });

  passthru.optional-dependencies = {
    datalib = [
      numpy
      openpyxl
      pandas
      pandas-stubs
    ];
    embeddings = [
      matplotlib
      plotly
      scikit-learn
      tenacity
    ] ++ passthru.optional-dependencies.datalib;
    wandb = [
      wandb
    ] ++ passthru.optional-dependencies.datalib;
  };

  pythonImportsCheck = [
    "openai"
  ];

  nativeCheckInputs = [
    pytestCheckHook
    pytest-asyncio
    pytest-mock
  ];

  pytestFlagsArray = [
    "openai/tests"
  ];

  OPENAI_API_KEY = "sk-foo";

  disabledTestPaths = [
    # Requires a real API key
    "openai/tests/test_endpoints.py"
    "openai/tests/asyncio/test_endpoints.py"
    # openai: command not found
    "openai/tests/test_file_cli.py"
    "openai/tests/test_long_examples_validator.py"
  ];

  meta = with lib; {
    description = "Python client library for the OpenAI API";
    homepage = "https://github.com/openai/openai-python";
    license = licenses.mit;
    maintainers = with maintainers; [ malo ];
  };
}