openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
openai/__init__.py
77lines · modecode
| 1 | # OpenAI Python bindings. |
| 2 | # |
| 3 | # Originally forked from the MIT-licensed Stripe Python bindings. |
| 4 | |
| 5 | import os |
| 6 | from typing import Optional |
| 7 | |
| 8 | from openai.api_resources import ( |
| 9 | Answer, |
| 10 | Classification, |
| 11 | Completion, |
| 12 | Customer, |
| 13 | Edit, |
| 14 | Deployment, |
| 15 | Embedding, |
| 16 | Engine, |
| 17 | ErrorObject, |
| 18 | File, |
| 19 | FineTune, |
| 20 | Model, |
| 21 | Moderation, |
| 22 | Search, |
| 23 | ) |
| 24 | from openai.error import APIError, InvalidRequestError, OpenAIError |
| 25 | |
| 26 | api_key = os.environ.get("OPENAI_API_KEY") |
| 27 | # Path of a file with an API key, whose contents can change. Supercedes |
| 28 | # `api_key` if set. The main use case is volume-mounted Kubernetes secrets, |
| 29 | # which are updated automatically. |
| 30 | api_key_path: Optional[str] = os.environ.get("OPENAI_API_KEY_PATH") |
| 31 | |
| 32 | organization = os.environ.get("OPENAI_ORGANIZATION") |
| 33 | api_base = os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1") |
| 34 | api_type = os.environ.get("OPENAI_API_TYPE", "open_ai") |
| 35 | api_version = ( |
| 36 | "2022-03-01-preview" if api_type in ("azure", "azure_ad", "azuread") else None |
| 37 | ) |
| 38 | verify_ssl_certs = True # No effect. Certificates are always verified. |
| 39 | proxy = None |
| 40 | app_info = None |
| 41 | enable_telemetry = False # Ignored; the telemetry feature was removed. |
| 42 | ca_bundle_path = None # No longer used, feature was removed |
| 43 | debug = False |
| 44 | log = None # Set to either 'debug' or 'info', controls console logging |
| 45 | |
| 46 | __all__ = [ |
| 47 | "APIError", |
| 48 | "Answer", |
| 49 | "Classification", |
| 50 | "Completion", |
| 51 | "Customer", |
| 52 | "Edit", |
| 53 | "Deployment", |
| 54 | "Embedding", |
| 55 | "Engine", |
| 56 | "ErrorObject", |
| 57 | "File", |
| 58 | "FineTune", |
| 59 | "InvalidRequestError", |
| 60 | "Model", |
| 61 | "Moderation", |
| 62 | "OpenAIError", |
| 63 | "Search", |
| 64 | "api_base", |
| 65 | "api_key", |
| 66 | "api_type", |
| 67 | "api_key_path", |
| 68 | "api_version", |
| 69 | "app_info", |
| 70 | "ca_bundle_path", |
| 71 | "debug", |
| 72 | "enable_elemetry", |
| 73 | "log", |
| 74 | "organization", |
| 75 | "proxy", |
| 76 | "verify_ssl_certs", |
| 77 | ] |
| 78 | |