Skip to content

Commit

Permalink
python client 0.11.0 beta release
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
madeleineth committed Oct 20, 2021
1 parent 759b5f5 commit a6ecf6b
Show file tree
Hide file tree
Showing 42 changed files with 470 additions and 1,154 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.egg-info
__pycache__
/public/dist
.idea
.python-version
.python-version
/public/dist
__pycache__
build
6 changes: 6 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[settings]
include_trailing_comma=True
line_length=88
known_first_party=
multi_line_output=3
py_version=36
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ openai api completions.create -e ada -p "Hello world"

## Requirements

- Python 3.7+
- Python 3.7.1+

In general we want to support the versions of Python that our
customers are using, so if you run into issues with any version
Expand Down
5 changes: 3 additions & 2 deletions bin/openai
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import logging
import sys

import openai
from openai.cli import display_error
from openai.cli import api_register, tools_register
from openai.cli import api_register, display_error, tools_register

logger = logging.getLogger()
formatter = logging.Formatter("[%(asctime)s] %(message)s")
Expand Down Expand Up @@ -62,8 +61,10 @@ def main():
args.func(args)
except openai.error.OpenAIError as e:
display_error(e)
return 1
except KeyboardInterrupt:
sys.stderr.write("\n")
return 1
return 0


Expand Down
6 changes: 4 additions & 2 deletions examples/codex/backtranslation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import openai
from smokey import Smokey
from typing import List, Union

from smokey import Smokey

import openai


def get_candidates(
prompt: str,
Expand Down
3 changes: 2 additions & 1 deletion examples/finetuning/answers-with-ft.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import openai
import argparse

import openai


def create_context(
question, search_file_id, max_len=1800, search_model="ada", max_rerank=10
Expand Down
3 changes: 2 additions & 1 deletion examples/semanticsearch/semanticsearch.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
import openai
import argparse
import logging
import sys
from typing import List

import openai

logger = logging.getLogger()
formatter = logging.Formatter("[%(asctime)s] [%(process)d] %(message)s")
handler = logging.StreamHandler(sys.stderr)
Expand Down
72 changes: 48 additions & 24 deletions openai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
import os

# OpenAI Python bindings.
#
# Originally forked from the MIT-licensed Stripe Python bindings.

# Configuration variables

api_key = os.environ.get("OPENAI_API_KEY")
organization = os.environ.get("OPENAI_ORGANIZATION")
client_id = None
api_base = os.environ.get("OPENAI_API_BASE", "https://api.openai.com")
file_api_base = None
api_version = None
verify_ssl_certs = True
proxy = None
default_http_client = None
app_info = None
enable_telemetry = True
max_network_retries = 0
ca_bundle_path = os.path.join(os.path.dirname(__file__), "data/ca-certificates.crt")
debug = False

# Set to either 'debug' or 'info', controls console logging
log = None
import os
from typing import Optional

# API resources
from openai.api_resources import ( # noqa: E402,F401
from openai.api_resources import (
Answer,
Classification,
Completion,
Expand All @@ -36,4 +16,48 @@
Model,
Search,
)
from openai.error import APIError, InvalidRequestError, OpenAIError # noqa: E402,F401
from openai.error import APIError, InvalidRequestError, OpenAIError

api_key = os.environ.get("OPENAI_API_KEY")
# Path of a file with an API key, whose contents can change. Supercedes
# `api_key` if set. The main use case is volume-mounted Kubernetes secrets,
# which are updated automatically.
api_key_path: Optional[str] = os.environ.get("OPENAI_API_KEY_PATH")

organization = os.environ.get("OPENAI_ORGANIZATION")
api_base = os.environ.get("OPENAI_API_BASE", "https://api.openai.com")
api_version = None
verify_ssl_certs = True # No effect. Certificates are always verified.
proxy = None
app_info = None
enable_telemetry = False # Ignored; the telemetry feature was removed.
ca_bundle_path = os.path.join(os.path.dirname(__file__), "data/ca-certificates.crt")
debug = False
log = None # Set to either 'debug' or 'info', controls console logging

__all__ = [
"APIError",
"Answer",
"Classification",
"Completion",
"Engine",
"ErrorObject",
"File",
"FineTune",
"InvalidRequestError",
"Model",
"OpenAIError",
"Search",
"api_base",
"api_key",
"api_key_path",
"api_version",
"app_info",
"ca_bundle_path",
"debug",
"enable_elemetry",
"log",
"organization",
"proxy",
"verify_ssl_certs",
]
Loading

0 comments on commit a6ecf6b

Please sign in to comment.