at master 2.7 kB view raw
1{ 2 lib, 3 buildPythonPackage, 4 fetchFromGitHub, 5 6 # build-system 7 hatchling, 8 hatch-fancy-pypi-readme, 9 10 # dependencies 11 anyio, 12 distro, 13 httpx, 14 jiter, 15 pydantic, 16 sniffio, 17 tqdm, 18 typing-extensions, 19 20 # optional-dependencies (aiohttp) 21 aiohttp, 22 httpx-aiohttp, 23 24 # optional-dependencies (datalib) 25 numpy, 26 pandas, 27 pandas-stubs, 28 29 # optional-dependencies (realtime) 30 websockets, 31 32 # optional-dependencies (voice-helpers) 33 sounddevice, 34 35 # check deps 36 pytestCheckHook, 37 dirty-equals, 38 inline-snapshot, 39 nest-asyncio, 40 pytest-asyncio, 41 pytest-mock, 42 pytest-xdist, 43 respx, 44 45 # optional-dependencies toggle 46 withAiohttp ? true, 47 withDatalib ? false, 48 withRealtime ? true, 49 withVoiceHelpers ? true, 50}: 51 52buildPythonPackage rec { 53 pname = "openai"; 54 version = "1.101.0"; 55 pyproject = true; 56 57 src = fetchFromGitHub { 58 owner = "openai"; 59 repo = "openai-python"; 60 tag = "v${version}"; 61 hash = "sha256-XCstUYM2jiq3PbNiRmLnguzQtvrGk0Ik5K0tk37bq2U="; 62 }; 63 64 postPatch = ''substituteInPlace pyproject.toml --replace-fail "hatchling==1.26.3" "hatchling"''; 65 66 build-system = [ 67 hatchling 68 hatch-fancy-pypi-readme 69 ]; 70 71 dependencies = [ 72 anyio 73 distro 74 httpx 75 jiter 76 pydantic 77 sniffio 78 tqdm 79 typing-extensions 80 ] 81 ++ lib.optionals withAiohttp optional-dependencies.aiohttp 82 ++ lib.optionals withDatalib optional-dependencies.datalib 83 ++ lib.optionals withRealtime optional-dependencies.realtime 84 ++ lib.optionals withVoiceHelpers optional-dependencies.voice-helpers; 85 86 optional-dependencies = { 87 aiohttp = [ 88 aiohttp 89 httpx-aiohttp 90 ]; 91 datalib = [ 92 numpy 93 pandas 94 pandas-stubs 95 ]; 96 realtime = [ 97 websockets 98 ]; 99 voice-helpers = [ 100 numpy 101 sounddevice 102 ]; 103 }; 104 105 pythonImportsCheck = [ "openai" ]; 106 107 nativeCheckInputs = [ 108 pytestCheckHook 109 dirty-equals 110 inline-snapshot 111 nest-asyncio 112 pytest-asyncio 113 pytest-mock 114 pytest-xdist 115 respx 116 ]; 117 118 disabledTestPaths = [ 119 # Test makes network requests 120 "tests/api_resources" 121 # E TypeError: Unexpected type for 'content', <class 'inline_snapshot._external.external'> 122 # This seems to be due to `inline-snapshot` being disabled when `pytest-xdist` is used. 123 "tests/lib/chat/test_completions_streaming.py" 124 ]; 125 126 meta = { 127 description = "Python client library for the OpenAI API"; 128 homepage = "https://github.com/openai/openai-python"; 129 changelog = "https://github.com/openai/openai-python/blob/${src.tag}/CHANGELOG.md"; 130 license = lib.licenses.mit; 131 maintainers = [ lib.maintainers.malo ]; 132 mainProgram = "openai"; 133 }; 134}