Skip to content

Commit 62f8d40

Browse files
authored
python client 0.11.0 beta release (#42)
- Add `.isort.cfg` and fix imports to match. - Exit with status 1 instead of 0 on error in `openai`. - Support `openai.api_key_path` variable to make it easy to have long-running processes with auto-updated keys. - Drop support for unverified SSL connections. - Substantially simplify HTTP client code. Now that we use `requests` for everything, we do not need distinct `HTTPClient` and `APIRequestor` abstractions, and we can use the `requests` implementation for multipart data, rather than our own. - Drop vestigial code originally from the Stripe client. For example, there was a bunch of code related to an idempotency framework; OpenAI does not have an idempotency framework. - Drop support for `APIResource.delete` as an instance method; it is just a class method now. - Drop support for `APIResource.save`; use `APIResource.modify` instead. This substantially simplifies API resources, since they no longer need to track changed fields, and there's less risk of race conditions. And the only thing it could be used for is changing the number of replicas an engine had, which does not justify the complexity of the code. - Drop the request-metrics code. It is unused.
1 parent 759b5f5 commit 62f8d40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+470
-1154
lines changed

.gitignore

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*.egg-info
2-
__pycache__
3-
/public/dist
42
.idea
5-
.python-version
3+
.python-version
4+
/public/dist
5+
__pycache__
6+
build

.isort.cfg

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[settings]
2+
include_trailing_comma=True
3+
line_length=88
4+
known_first_party=
5+
multi_line_output=3
6+
py_version=36

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ openai api completions.create -e ada -p "Hello world"
6868

6969
## Requirements
7070

71-
- Python 3.7+
71+
- Python 3.7.1+
7272

7373
In general we want to support the versions of Python that our
7474
customers are using, so if you run into issues with any version

bin/openai

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import logging
44
import sys
55

66
import openai
7-
from openai.cli import display_error
8-
from openai.cli import api_register, tools_register
7+
from openai.cli import api_register, display_error, tools_register
98

109
logger = logging.getLogger()
1110
formatter = logging.Formatter("[%(asctime)s] %(message)s")
@@ -62,8 +61,10 @@ def main():
6261
args.func(args)
6362
except openai.error.OpenAIError as e:
6463
display_error(e)
64+
return 1
6565
except KeyboardInterrupt:
6666
sys.stderr.write("\n")
67+
return 1
6768
return 0
6869

6970

examples/codex/backtranslation.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import openai
2-
from smokey import Smokey
31
from typing import List, Union
42

3+
from smokey import Smokey
4+
5+
import openai
6+
57

68
def get_candidates(
79
prompt: str,

examples/finetuning/answers-with-ft.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import openai
21
import argparse
32

3+
import openai
4+
45

56
def create_context(
67
question, search_file_id, max_len=1800, search_model="ada", max_rerank=10

examples/semanticsearch/semanticsearch.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python
2-
import openai
32
import argparse
43
import logging
54
import sys
65
from typing import List
76

7+
import openai
8+
89
logger = logging.getLogger()
910
formatter = logging.Formatter("[%(asctime)s] [%(process)d] %(message)s")
1011
handler = logging.StreamHandler(sys.stderr)

openai/__init__.py

+48-24
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,11 @@
1-
import os
2-
31
# OpenAI Python bindings.
42
#
53
# Originally forked from the MIT-licensed Stripe Python bindings.
64

7-
# Configuration variables
8-
9-
api_key = os.environ.get("OPENAI_API_KEY")
10-
organization = os.environ.get("OPENAI_ORGANIZATION")
11-
client_id = None
12-
api_base = os.environ.get("OPENAI_API_BASE", "https://api.openai.com")
13-
file_api_base = None
14-
api_version = None
15-
verify_ssl_certs = True
16-
proxy = None
17-
default_http_client = None
18-
app_info = None
19-
enable_telemetry = True
20-
max_network_retries = 0
21-
ca_bundle_path = os.path.join(os.path.dirname(__file__), "data/ca-certificates.crt")
22-
debug = False
23-
24-
# Set to either 'debug' or 'info', controls console logging
25-
log = None
5+
import os
6+
from typing import Optional
267

27-
# API resources
28-
from openai.api_resources import ( # noqa: E402,F401
8+
from openai.api_resources import (
299
Answer,
3010
Classification,
3111
Completion,
@@ -36,4 +16,48 @@
3616
Model,
3717
Search,
3818
)
39-
from openai.error import APIError, InvalidRequestError, OpenAIError # noqa: E402,F401
19+
from openai.error import APIError, InvalidRequestError, OpenAIError
20+
21+
api_key = os.environ.get("OPENAI_API_KEY")
22+
# Path of a file with an API key, whose contents can change. Supercedes
23+
# `api_key` if set. The main use case is volume-mounted Kubernetes secrets,
24+
# which are updated automatically.
25+
api_key_path: Optional[str] = os.environ.get("OPENAI_API_KEY_PATH")
26+
27+
organization = os.environ.get("OPENAI_ORGANIZATION")
28+
api_base = os.environ.get("OPENAI_API_BASE", "https://api.openai.com")
29+
api_version = None
30+
verify_ssl_certs = True # No effect. Certificates are always verified.
31+
proxy = None
32+
app_info = None
33+
enable_telemetry = False # Ignored; the telemetry feature was removed.
34+
ca_bundle_path = os.path.join(os.path.dirname(__file__), "data/ca-certificates.crt")
35+
debug = False
36+
log = None # Set to either 'debug' or 'info', controls console logging
37+
38+
__all__ = [
39+
"APIError",
40+
"Answer",
41+
"Classification",
42+
"Completion",
43+
"Engine",
44+
"ErrorObject",
45+
"File",
46+
"FineTune",
47+
"InvalidRequestError",
48+
"Model",
49+
"OpenAIError",
50+
"Search",
51+
"api_base",
52+
"api_key",
53+
"api_key_path",
54+
"api_version",
55+
"app_info",
56+
"ca_bundle_path",
57+
"debug",
58+
"enable_elemetry",
59+
"log",
60+
"organization",
61+
"proxy",
62+
"verify_ssl_certs",
63+
]

0 commit comments

Comments
 (0)