Skip to content

Commit d867efc

Browse files
authored
Merge pull request #8 from mmacy/chat.completions.create
docstrings for resource module & chat.completions.create() impl
2 parents 498205c + a73aa41 commit d867efc

19 files changed

+336
-34
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}
33

44
USER vscode
55

6-
RUN curl -sSf https://rye-up.com/get | RYE_VERSION="0.15.2" RYE_INSTALL_OPTION="--yes" bash
6+
RUN curl -sSf https://rye-up.com/get | RYE_VERSION="0.24.0" RYE_INSTALL_OPTION="--yes" bash
77
ENV PATH=/home/vscode/.rye/shims:$PATH
88

99
RUN echo "[[ -d .venv ]] && source .venv/bin/activate" >> /home/vscode/.bashrc

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
curl -sSf https://rye-up.com/get | bash
2222
echo "$HOME/.rye/shims" >> $GITHUB_PATH
2323
env:
24-
RYE_VERSION: 0.15.2
24+
RYE_VERSION: 0.24.0
2525
RYE_INSTALL_OPTION: "--yes"
2626

2727
- name: Install dependencies

.github/workflows/create-releases.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Create releases
2+
on:
3+
schedule:
4+
- cron: '0 5 * * *' # every day at 5am UTC
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
release:
11+
name: release
12+
if: github.ref == 'refs/heads/main' && github.repository == 'openai/openai-python'
13+
runs-on: ubuntu-latest
14+
environment: publish
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- uses: stainless-api/trigger-release-please@v1
20+
id: release
21+
with:
22+
repo: ${{ github.event.repository.full_name }}
23+
stainless-api-key: ${{ secrets.STAINLESS_API_KEY }}
24+
25+
- name: Install Rye
26+
if: ${{ steps.release.outputs.releases_created }}
27+
run: |
28+
curl -sSf https://rye-up.com/get | bash
29+
echo "$HOME/.rye/shims" >> $GITHUB_PATH
30+
env:
31+
RYE_VERSION: 0.24.0
32+
RYE_INSTALL_OPTION: "--yes"
33+
34+
- name: Publish to PyPI
35+
if: ${{ steps.release.outputs.releases_created }}
36+
run: |
37+
bash ./bin/publish-pypi
38+
env:
39+
PYPI_TOKEN: ${{ secrets.OPENAI_PYPI_TOKEN || secrets.PYPI_TOKEN }}

.github/workflows/publish-pypi.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
# This workflow is triggered when a GitHub release is created.
2-
# It can also be run manually to re-publish to PyPI in case it failed for some reason.
3-
# You can run this workflow by navigating to https://www.github.com/openai/openai-python/actions/workflows/publish-pypi.yml
1+
# workflow for re-running publishing to PyPI in case it fails for some reason
2+
# you can run this workflow by navigating to https://www.github.com/openai/openai-python/actions/workflows/publish-pypi.yml
43
name: Publish PyPI
54
on:
65
workflow_dispatch:
76

8-
release:
9-
types: [published]
10-
117
jobs:
128
publish:
139
name: publish
@@ -21,7 +17,7 @@ jobs:
2117
curl -sSf https://rye-up.com/get | bash
2218
echo "$HOME/.rye/shims" >> $GITHUB_PATH
2319
env:
24-
RYE_VERSION: 0.15.2
20+
RYE_VERSION: 0.24.0
2521
RYE_INSTALL_OPTION: "--yes"
2622

2723
- name: Publish to PyPI

.github/workflows/release-doctor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ jobs:
1919
run: |
2020
bash ./bin/check-release-environment
2121
env:
22+
STAINLESS_API_KEY: ${{ secrets.STAINLESS_API_KEY }}
2223
PYPI_TOKEN: ${{ secrets.OPENAI_PYPI_TOKEN || secrets.PYPI_TOKEN }}

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "1.13.0"
2+
".": "1.13.2"
33
}

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# Changelog
22

3+
## 1.13.2 (2024-02-20)
4+
5+
Full Changelog: [v1.13.1...v1.13.2](https://github.com/openai/openai-python/compare/v1.13.1...v1.13.2)
6+
7+
### Bug Fixes
8+
9+
* **ci:** revert "move github release logic to github app" ([#1170](https://github.com/openai/openai-python/issues/1170)) ([f1adc2e](https://github.com/openai/openai-python/commit/f1adc2e6f2f29acb4404e84137a9d3109714c585))
10+
11+
## 1.13.1 (2024-02-20)
12+
13+
Full Changelog: [v1.13.0...v1.13.1](https://github.com/openai/openai-python/compare/v1.13.0...v1.13.1)
14+
15+
### Chores
16+
17+
* **internal:** bump rye to v0.24.0 ([#1168](https://github.com/openai/openai-python/issues/1168)) ([84c4256](https://github.com/openai/openai-python/commit/84c4256316f2a79068ecadb852e5e69b6b104a1f))
18+
319
## 1.13.0 (2024-02-19)
420

521
Full Changelog: [v1.12.0...v1.13.0](https://github.com/openai/openai-python/compare/v1.12.0...v1.13.0)

bin/check-release-environment

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
errors=()
44

5+
if [ -z "${STAINLESS_API_KEY}" ]; then
6+
errors+=("The STAINLESS_API_KEY secret has not been set. Please contact Stainless for an API key & set it in your organization secrets on GitHub.")
7+
fi
8+
59
if [ -z "${PYPI_TOKEN}" ]; then
610
errors+=("The OPENAI_PYPI_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets.")
711
fi

docs/reference/include/openai.resources.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
"""Snippets in this docstring are ingested by other documentation (including library docstrings) during the MkDocs build process.
22
3+
# --8<-- [start:resources]
4+
The `resources` module aggregates classes and functions for interacting with the OpenAI API into several submodules,
5+
each representing a specific resource or feature of the API.
6+
7+
The submodules' classes mirror the structure of the API's endpoints and offer synchronous and asynchronous
8+
communication with the API.
9+
10+
Each resource is accessible as an attribute on the [`OpenAI`][src.openai.OpenAI] and [`AsyncOpenAI`][src.openai.AsyncOpenAI]
11+
clients. To work with a resource, initialize an instance of one of the clients and access the resource as an attribute
12+
on the client instance. For example, to work with the `chat` resource, create an instance of the `OpenAI` client and
13+
access the attributes and methods on `your_client_instance.chat`.
14+
# --8<-- [end:resources]
15+
316
# --8<-- [start:audio]
417
The `audio` module provides classes for handling various audio processing operations, including transcription of audio to text, translation of spoken content, and speech synthesis.
518
@@ -15,7 +28,7 @@
1528
# --8<-- [start:chat]
1629
The `chat` module provides classes for creating and managing chat sessions that leverage OpenAI's language models to generate conversational responses.
1730
18-
The module supports both synchronous and asynchronous operations, offering interfaces for direct interaction with the completion endpoints tailored for chat applications. Designed for developers looking to integrate AI-powered chat functionalities into their applicationsand features like raw and streaming response handling for more flexible integration.
31+
The module supports both synchronous and asynchronous operations, offering interfaces for direct interaction with the completion endpoints tailored for chat applications. Designed for developers looking to integrate AI-powered chat functionalities into their applications and features like raw and streaming response handling for more flexible integration.
1932
# --8<-- [end:chat]
2033
2134
# --8<-- [start:chat_completions]

docs/reference/include/openai_init.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,34 @@
88
provides both synchronous and asynchronous API clients, options to configure their behavior, and modules that provide
99
Python code with an API surface to interact with the OpenAI platform.
1010
11-
To get started, check out the documentation for the module representing the [resource][src.openai.resources] you're interested in using for your
12-
project. For example, the [`resources.chat.completions`][src.openai.resources.chat.completions] module is what you'd use
11+
To get started, read the submodule descriptions in [`resources`][src.openai.resources] to determine which best fits your
12+
project. For example, the [`resources.chat`][src.openai.resources.chat] submodule description indicates it's a good fit
1313
for conversational chat-style interactions with an LLM like [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo).
14-
Or, maybe you need the [`resources.audio`][src.openai.resources.audio] module for performing audio transcription, translation, and
15-
speech synthesis in your app.
14+
Or, maybe you need the [`resources.audio`][src.openai.resources.audio] module to perform audio transcription,
15+
translation, and speech synthesis in your app.
1616
17-
Documentation for the library's main API client classes, [`OpenAI`][src.openai.OpenAI] and
18-
[`AsyncOpenAI`][src.openai.AsyncOpenAI], is another good place to start. The clients are the primary contact point for
19-
your code that needs to work with any of the resources available on OpenAI API endpoints.
17+
Once you've determined the resource to use, create an [`OpenAI`][src.openai.OpenAI] or [`AsyncOpenAI`][src.openai.AsyncOpenAI]
18+
client instance and access the instance attribute for that resource on the client object. For example, if you instantiate
19+
an `OpenAI` client object named `client`, youd access the [`OpenAI.chat`][src.openai.OpenAI.chat] instance attribute:
20+
21+
```python
22+
from openai import OpenAI
23+
24+
# Reads API key from OPENAI_API_KEY environment variable
25+
client = OpenAI()
26+
27+
# Use the `chat` resource to interact with the OpenAI chat completions endpoint
28+
completion = client.chat.completions.create(
29+
model="gpt-4",
30+
messages=[
31+
{
32+
"role": "user",
33+
"content": "Say this is a test",
34+
},
35+
],
36+
)
37+
print(completion.choices[0].message.content)
38+
```
2039
2140
For more information about the REST API this package talks to or to find client libraries for other programming
2241
languages, see:

mkdocs-requirements.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
annotated-types==0.6.0
2+
anyio==4.3.0
13
Babel==2.14.0
24
black==24.1.1
35
certifi==2024.2.2
46
charset-normalizer==3.3.2
57
click==8.1.7
68
colorama==0.4.6
9+
distro==1.9.0
710
ghp-import==2.1.0
811
griffe==0.40.1
912
griffe-inherited-docstrings==1.0.0
13+
h11==0.14.0
14+
httpcore==1.0.3
15+
httpx==0.26.0
1016
idna==3.6
17+
iniconfig==2.0.0
1118
Jinja2==3.1.3
1219
Markdown==3.5.2
1320
MarkupSafe==2.1.5
@@ -16,22 +23,31 @@ mkdocs==1.5.3
1623
mkdocs-autorefs==0.5.0
1724
mkdocs-gen-files==0.5.0
1825
mkdocs-literate-nav==0.6.1
19-
mkdocs-material==9.5.8
26+
mkdocs-material==9.5.9
2027
mkdocs-material-extensions==1.3.1
2128
mkdocstrings==0.24.0
2229
mkdocstrings-python @ git+ssh://[email protected]/pawamoy-insiders/mkdocstrings-python.git@157224dddefd2f2b979f9e92f0506e44c1548f64
2330
mypy-extensions==1.0.0
31+
openai==1.12.0
2432
packaging==23.2
2533
paginate==0.5.6
2634
pathspec==0.12.1
2735
platformdirs==4.2.0
36+
pluggy==1.4.0
37+
pydantic==2.6.1
38+
pydantic_core==2.16.2
2839
Pygments==2.17.2
2940
pymdown-extensions==10.7
41+
pytest==8.0.1
3042
python-dateutil==2.8.2
3143
PyYAML==6.0.1
3244
pyyaml_env_tag==0.1
3345
regex==2023.12.25
3446
requests==2.31.0
47+
respx==0.20.2
3548
six==1.16.0
49+
sniffio==1.3.0
50+
tqdm==4.66.2
51+
typing_extensions==4.9.0
3652
urllib3==2.2.0
3753
watchdog==4.0.0

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "openai"
3-
version = "1.13.0"
3+
version = "1.13.2"
44
description = "The official Python library for the openai API"
55
readme = "README.md"
66
license = "Apache-2.0"

0 commit comments

Comments
 (0)