From fa598ac147b295ade7ac14281fe09657d6b436dd Mon Sep 17 00:00:00 2001 From: James Chua Date: Fri, 27 Jan 2023 01:30:06 +0800 Subject: [PATCH 1/8] chore(pipeline): add pipeline for tests --- .github/workflows/dev.yml | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/dev.yml diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 0000000000..f772545517 --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,42 @@ +# This is a basic workflow to help you get started with Actions + +name: dev workflow + +# Controls when the action will run. +on: + # Triggers the workflow on push or pull request events but only for the master branch + push: + branches: [ main ] + pull_request: + branches: [ main ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "test" + test: + # The type of runner that the job will run on + strategy: + matrix: + python-versions: [3.7, 3.8, 3.9, "3.10"] + os: [ubuntu-18.04, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-versions }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install . + + - name: test with pytest + run: + pytest tests From ca2fbacf4a26124c315e83077db636c6fdc27691 Mon Sep 17 00:00:00 2001 From: Damien Deville Date: Thu, 26 Jan 2023 13:34:42 -0800 Subject: [PATCH 2/8] Fix invalid pyproject.toml file and move to setup.cfg (#201) The `[project]` section of a `pyproject.toml` file *has* to include both a `name` and a `version`, that we were missing. However, rather than adding more stuff to `pyproject.toml`, I've moved the license info to the setup file and pointed `pyproject.toml` to use `setuptools` for building (the `pyproject.toml` file is really only needed to integrated with `black`, that doesn't support setup files...) While I was at it I decided to migrate to a `setup.cfg` file rather than `setup.py` since its declaritive config is usally preferred these days (and it's a bit easier to load from version/license files than with a `setup.py` file). --- pyproject.toml | 10 +++----- setup.cfg | 65 +++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 68 ++------------------------------------------------ 3 files changed, 70 insertions(+), 73 deletions(-) create mode 100644 setup.cfg diff --git a/pyproject.toml b/pyproject.toml index 65fe55ff7d..6116c7fa2f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,6 @@ -[project] -license = {file = "LICENSE"} -classifiers = [ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", -] +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" [tool.black] target-version = ['py36'] diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000000..a42b05ef01 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,65 @@ +[metadata] +name = openai +version = attr: openai.version.VERSION +description = Python client library for the OpenAI API +long_description = file: README.md +long_description_content_type = text/markdown +author = OpenAI +author_email = support@openai.com +url = https://github.com/openai/openai-python +license_files = LICENSE +classifiers = + Programming Language :: Python :: 3 + License :: OSI Approved :: MIT License + Operating System :: OS Independent + +[options] +packages = find: +python_requires = >=3.7.1 +zip_safe = True +include_package_data = True +install_requires = + requests >= 2.20 # to get the patch for CVE-2018-18074 + tqdm # Needed for progress bars + typing_extensions; python_version<"3.8" # Needed for type hints for mypy + aiohttp # Needed for async support + +[options.extras_require] +dev = + black ~= 21.6b0 + pytest == 6.* + pytest-asyncio + pytest-mock +datalib = + numpy + pandas >= 1.2.3 # Needed for CLI fine-tuning data preparation tool + pandas-stubs >= 1.1.0.11 # Needed for type hints for mypy + openpyxl >= 3.0.7 # Needed for CLI fine-tuning data preparation tool xlsx format +wandb = + wandb + numpy + pandas >= 1.2.3 # Needed for CLI fine-tuning data preparation tool + pandas-stubs >= 1.1.0.11 # Needed for type hints for mypy + openpyxl >= 3.0.7 # Needed for CLI fine-tuning data preparation tool xlsx format +embeddings = + scikit-learn >= 1.0.2 # Needed for embedding utils, versions >= 1.1 require python 3.8 + tenacity >= 8.0.1 + matplotlib + sklearn + plotly + numpy + pandas >= 1.2.3 # Needed for CLI fine-tuning data preparation tool + pandas-stubs >= 1.1.0.11 # Needed for type hints for mypy + openpyxl >= 3.0.7 # Needed for CLI fine-tuning data preparation tool xlsx format + +[options.entry_points] +console_scripts = + openai = openai._openai_scripts:main + +[options.package_data] + openai = py.typed + +[options.packages.find] +exclude = + tests + tests.* diff --git a/setup.py b/setup.py index e431d26ccd..606849326a 100644 --- a/setup.py +++ b/setup.py @@ -1,67 +1,3 @@ -import os +from setuptools import setup -from setuptools import find_packages, setup - -version_contents = {} -version_path = os.path.join( - os.path.abspath(os.path.dirname(__file__)), "openai/version.py" -) -with open(version_path, "rt") as f: - exec(f.read(), version_contents) - -with open("README.md", "r") as fh: - long_description = fh.read() - - -DATA_LIBRARIES = [ - # These libraries are optional because of their size. See `openai/datalib.py`. - "numpy", - "pandas>=1.2.3", # Needed for CLI fine-tuning data preparation tool - "pandas-stubs>=1.1.0.11", # Needed for type hints for mypy - "openpyxl>=3.0.7", # Needed for CLI fine-tuning data preparation tool xlsx format -] - -setup( - name="openai", - description="Python client library for the OpenAI API", - long_description=long_description, - long_description_content_type="text/markdown", - version=version_contents["VERSION"], - install_requires=[ - "requests>=2.20", # to get the patch for CVE-2018-18074 - "tqdm", # Needed for progress bars - 'typing_extensions;python_version<"3.8"', # Needed for type hints for mypy - "aiohttp", # Needed for async support - ], - extras_require={ - "dev": ["black~=21.6b0", "pytest==6.*", "pytest-asyncio", "pytest-mock"], - "datalib": DATA_LIBRARIES, - "wandb": [ - "wandb", - *DATA_LIBRARIES, - ], - "embeddings": [ - "scikit-learn>=1.0.2", # Needed for embedding utils, versions >= 1.1 require python 3.8 - "tenacity>=8.0.1", - "matplotlib", - "sklearn", - "plotly", - *DATA_LIBRARIES, - ], - }, - python_requires=">=3.7.1", - entry_points={ - "console_scripts": [ - "openai=openai._openai_scripts:main", - ], - }, - packages=find_packages(exclude=["tests", "tests.*"]), - package_data={ - "openai": [ - "py.typed", - ] - }, - author="OpenAI", - author_email="support@openai.com", - url="https://github.com/openai/openai-python", -) +setup() From b23ecafe49133da9812d96cb693f656e0a223050 Mon Sep 17 00:00:00 2001 From: Damien Deville Date: Thu, 26 Jan 2023 13:38:52 -0800 Subject: [PATCH 3/8] Bump version (#204) --- openai/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openai/version.py b/openai/version.py index 72ad5c9364..cbd0c64107 100644 --- a/openai/version.py +++ b/openai/version.py @@ -1 +1 @@ -VERSION = "0.26.3" +VERSION = "0.26.4" From 3306f4248f192d5d4a5b6cc105e9babc85da7812 Mon Sep 17 00:00:00 2001 From: James Chua Date: Fri, 3 Feb 2023 15:36:11 +0800 Subject: [PATCH 4/8] install extras too --- .github/workflows/dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index f772545517..392d6ee9e6 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -35,7 +35,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install . + pip install .[extra] - name: test with pytest run: From 9d05e47cd34dd74b69e9a55e0b26de6830e7c8e9 Mon Sep 17 00:00:00 2001 From: James Chua Date: Fri, 3 Feb 2023 15:39:44 +0800 Subject: [PATCH 5/8] fix extras command --- .github/workflows/dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 392d6ee9e6..f139e4bd3f 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -35,7 +35,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install .[extra] + pip install .[extras_require] - name: test with pytest run: From 67976b903d4247940b25bc9192e67d6b1208a741 Mon Sep 17 00:00:00 2001 From: James Chua Date: Sat, 4 Feb 2023 14:49:21 +0800 Subject: [PATCH 6/8] fix install for dev deps --- .github/workflows/dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index f139e4bd3f..8b22d57619 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -35,7 +35,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install .[extras_require] + pip install .[dev] - name: test with pytest run: From 26d462c526d4b6d395a47a23a29ea01bcfc816d3 Mon Sep 17 00:00:00 2001 From: James Chua Date: Sat, 4 Feb 2023 14:52:52 +0800 Subject: [PATCH 7/8] fix tests directory --- .github/workflows/dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 8b22d57619..cd103628b2 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -39,4 +39,4 @@ jobs: - name: test with pytest run: - pytest tests + pytest openai/tests From add117bbf29b5d23e4f43bc0cdb848874ebc6972 Mon Sep 17 00:00:00 2001 From: James Chua Date: Sat, 4 Feb 2023 15:01:20 +0800 Subject: [PATCH 8/8] fix test --- openai/tests/asyncio/test_endpoints.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/openai/tests/asyncio/test_endpoints.py b/openai/tests/asyncio/test_endpoints.py index 3dc355b733..077a954c35 100644 --- a/openai/tests/asyncio/test_endpoints.py +++ b/openai/tests/asyncio/test_endpoints.py @@ -14,10 +14,12 @@ # FILE TESTS async def test_file_upload(): result = await openai.File.acreate( - file=io.StringIO(json.dumps({"text": "test file data"})), - purpose="search", + file=io.StringIO( + json.dumps({"prompt": "test file data", "completion": "tada"}) + ), + purpose="fine-tune", ) - assert result.purpose == "search" + assert result.purpose == "fine-tune" assert "id" in result result = await openai.File.aretrieve(id=result.id)