|
1 |
| -import os |
2 |
| - |
3 | 1 | # OpenAI Python bindings.
|
4 | 2 | #
|
5 | 3 | # Originally forked from the MIT-licensed Stripe Python bindings.
|
6 | 4 |
|
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 |
26 | 7 |
|
27 |
| -# API resources |
28 |
| -from openai.api_resources import ( # noqa: E402,F401 |
| 8 | +from openai.api_resources import ( |
29 | 9 | Answer,
|
30 | 10 | Classification,
|
31 | 11 | Completion,
|
|
36 | 16 | Model,
|
37 | 17 | Search,
|
38 | 18 | )
|
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