xbasis 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openai/__init__.py +104 -0
- openai/_openai_scripts.py +89 -0
- openai/api_requestor.py +778 -0
- openai/api_resources/__init__.py +14 -0
- openai/api_resources/abstract/__init__.py +10 -0
- openai/api_resources/abstract/api_resource.py +172 -0
- openai/api_resources/abstract/createable_api_resource.py +98 -0
- openai/api_resources/abstract/deletable_api_resource.py +48 -0
- openai/api_resources/abstract/engine_api_resource.py +325 -0
- openai/api_resources/abstract/listable_api_resource.py +95 -0
- openai/api_resources/abstract/nested_resource_class_methods.py +154 -0
- openai/api_resources/abstract/updateable_api_resource.py +16 -0
- openai/api_resources/audio.py +269 -0
- openai/api_resources/chat_completion.py +50 -0
- openai/api_resources/completion.py +50 -0
- openai/api_resources/customer.py +17 -0
- openai/api_resources/deployment.py +119 -0
- openai/api_resources/edit.py +57 -0
- openai/api_resources/embedding.py +91 -0
- openai/api_resources/engine.py +50 -0
- openai/api_resources/error_object.py +28 -0
- openai/api_resources/experimental/__init__.py +3 -0
- openai/api_resources/experimental/completion_config.py +11 -0
- openai/api_resources/file.py +261 -0
- openai/api_resources/fine_tune.py +204 -0
- openai/api_resources/image.py +273 -0
- openai/api_resources/model.py +5 -0
- openai/api_resources/moderation.py +45 -0
- openai/cli.py +1136 -0
- openai/datalib/__init__.py +14 -0
- openai/datalib/common.py +17 -0
- openai/datalib/numpy_helper.py +15 -0
- openai/datalib/pandas_helper.py +15 -0
- openai/embeddings_utils.py +252 -0
- openai/error.py +169 -0
- openai/object_classes.py +11 -0
- openai/openai_object.py +347 -0
- openai/openai_response.py +31 -0
- openai/py.typed +0 -0
- openai/tests/__init__.py +0 -0
- openai/tests/asyncio/__init__.py +0 -0
- openai/tests/asyncio/test_endpoints.py +90 -0
- openai/tests/test_api_requestor.py +101 -0
- openai/tests/test_endpoints.py +118 -0
- openai/tests/test_exceptions.py +40 -0
- openai/tests/test_file_cli.py +39 -0
- openai/tests/test_long_examples_validator.py +54 -0
- openai/tests/test_url_composition.py +209 -0
- openai/tests/test_util.py +55 -0
- openai/upload_progress.py +52 -0
- openai/util.py +188 -0
- openai/validators.py +852 -0
- openai/version.py +1 -0
- openai/wandb_logger.py +300 -0
- xbasis-0.0.1.dist-info/METADATA +356 -0
- xbasis-0.0.1.dist-info/RECORD +61 -0
- xbasis-0.0.1.dist-info/WHEEL +5 -0
- xbasis-0.0.1.dist-info/entry_points.txt +2 -0
- xbasis-0.0.1.dist-info/licenses/LICENSE +21 -0
- xbasis-0.0.1.dist-info/top_level.txt +1 -0
- xbasis-0.0.1.dist-info/zip-safe +1 -0
openai/__init__.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# OpenAI Python bindings.
|
|
2
|
+
#
|
|
3
|
+
# Originally forked from the MIT-licensed Stripe Python bindings.
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
from typing import TYPE_CHECKING, Optional, Union, Callable
|
|
8
|
+
|
|
9
|
+
from contextvars import ContextVar
|
|
10
|
+
|
|
11
|
+
if "pkg_resources" not in sys.modules:
|
|
12
|
+
# workaround for the following:
|
|
13
|
+
# https://github.com/benoitc/gunicorn/pull/2539
|
|
14
|
+
sys.modules["pkg_resources"] = object() # type: ignore[assignment]
|
|
15
|
+
import aiohttp
|
|
16
|
+
|
|
17
|
+
del sys.modules["pkg_resources"]
|
|
18
|
+
|
|
19
|
+
from openai.api_resources import (
|
|
20
|
+
Audio,
|
|
21
|
+
ChatCompletion,
|
|
22
|
+
Completion,
|
|
23
|
+
Customer,
|
|
24
|
+
Deployment,
|
|
25
|
+
Edit,
|
|
26
|
+
Embedding,
|
|
27
|
+
Engine,
|
|
28
|
+
ErrorObject,
|
|
29
|
+
File,
|
|
30
|
+
FineTune,
|
|
31
|
+
Image,
|
|
32
|
+
Model,
|
|
33
|
+
Moderation,
|
|
34
|
+
)
|
|
35
|
+
from openai.error import APIError, InvalidRequestError, OpenAIError
|
|
36
|
+
from openai.version import VERSION
|
|
37
|
+
|
|
38
|
+
if TYPE_CHECKING:
|
|
39
|
+
import requests
|
|
40
|
+
from aiohttp import ClientSession
|
|
41
|
+
|
|
42
|
+
api_key = os.environ.get("OPENAI_API_KEY")
|
|
43
|
+
# Path of a file with an API key, whose contents can change. Supercedes
|
|
44
|
+
# `api_key` if set. The main use case is volume-mounted Kubernetes secrets,
|
|
45
|
+
# which are updated automatically.
|
|
46
|
+
api_key_path: Optional[str] = os.environ.get("OPENAI_API_KEY_PATH")
|
|
47
|
+
|
|
48
|
+
organization = os.environ.get("OPENAI_ORGANIZATION")
|
|
49
|
+
api_base = os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1")
|
|
50
|
+
api_type = os.environ.get("OPENAI_API_TYPE", "open_ai")
|
|
51
|
+
api_version = os.environ.get(
|
|
52
|
+
"OPENAI_API_VERSION",
|
|
53
|
+
("2023-05-15" if api_type in ("azure", "azure_ad", "azuread") else None),
|
|
54
|
+
)
|
|
55
|
+
verify_ssl_certs = True # No effect. Certificates are always verified.
|
|
56
|
+
proxy = None
|
|
57
|
+
app_info = None
|
|
58
|
+
enable_telemetry = False # Ignored; the telemetry feature was removed.
|
|
59
|
+
ca_bundle_path = None # No longer used, feature was removed
|
|
60
|
+
debug = False
|
|
61
|
+
log = None # Set to either 'debug' or 'info', controls console logging
|
|
62
|
+
|
|
63
|
+
requestssession: Optional[
|
|
64
|
+
Union["requests.Session", Callable[[], "requests.Session"]]
|
|
65
|
+
] = None # Provide a requests.Session or Session factory.
|
|
66
|
+
|
|
67
|
+
aiosession: ContextVar[Optional["ClientSession"]] = ContextVar(
|
|
68
|
+
"aiohttp-session", default=None
|
|
69
|
+
) # Acts as a global aiohttp ClientSession that reuses connections.
|
|
70
|
+
# This is user-supplied; otherwise, a session is remade for each request.
|
|
71
|
+
|
|
72
|
+
__version__ = VERSION
|
|
73
|
+
__all__ = [
|
|
74
|
+
"APIError",
|
|
75
|
+
"Audio",
|
|
76
|
+
"ChatCompletion",
|
|
77
|
+
"Completion",
|
|
78
|
+
"Customer",
|
|
79
|
+
"Edit",
|
|
80
|
+
"Image",
|
|
81
|
+
"Deployment",
|
|
82
|
+
"Embedding",
|
|
83
|
+
"Engine",
|
|
84
|
+
"ErrorObject",
|
|
85
|
+
"File",
|
|
86
|
+
"FineTune",
|
|
87
|
+
"InvalidRequestError",
|
|
88
|
+
"Model",
|
|
89
|
+
"Moderation",
|
|
90
|
+
"OpenAIError",
|
|
91
|
+
"api_base",
|
|
92
|
+
"api_key",
|
|
93
|
+
"api_type",
|
|
94
|
+
"api_key_path",
|
|
95
|
+
"api_version",
|
|
96
|
+
"app_info",
|
|
97
|
+
"ca_bundle_path",
|
|
98
|
+
"debug",
|
|
99
|
+
"enable_telemetry",
|
|
100
|
+
"log",
|
|
101
|
+
"organization",
|
|
102
|
+
"proxy",
|
|
103
|
+
"verify_ssl_certs",
|
|
104
|
+
]
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
import argparse
|
|
3
|
+
import logging
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
import openai
|
|
7
|
+
from openai import version
|
|
8
|
+
from openai.cli import api_register, display_error, tools_register, wandb_register
|
|
9
|
+
|
|
10
|
+
logger = logging.getLogger()
|
|
11
|
+
formatter = logging.Formatter("[%(asctime)s] %(message)s")
|
|
12
|
+
handler = logging.StreamHandler(sys.stderr)
|
|
13
|
+
handler.setFormatter(formatter)
|
|
14
|
+
logger.addHandler(handler)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def main():
|
|
18
|
+
parser = argparse.ArgumentParser(description=None)
|
|
19
|
+
parser.add_argument(
|
|
20
|
+
"-V",
|
|
21
|
+
"--version",
|
|
22
|
+
action="version",
|
|
23
|
+
version="%(prog)s " + version.VERSION,
|
|
24
|
+
)
|
|
25
|
+
parser.add_argument(
|
|
26
|
+
"-v",
|
|
27
|
+
"--verbose",
|
|
28
|
+
action="count",
|
|
29
|
+
dest="verbosity",
|
|
30
|
+
default=0,
|
|
31
|
+
help="Set verbosity.",
|
|
32
|
+
)
|
|
33
|
+
parser.add_argument("-b", "--api-base", help="What API base url to use.")
|
|
34
|
+
parser.add_argument("-k", "--api-key", help="What API key to use.")
|
|
35
|
+
parser.add_argument("-p", "--proxy", nargs='+', help="What proxy to use.")
|
|
36
|
+
parser.add_argument(
|
|
37
|
+
"-o",
|
|
38
|
+
"--organization",
|
|
39
|
+
help="Which organization to run as (will use your default organization if not specified)",
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
def help(args):
|
|
43
|
+
parser.print_help()
|
|
44
|
+
|
|
45
|
+
parser.set_defaults(func=help)
|
|
46
|
+
|
|
47
|
+
subparsers = parser.add_subparsers()
|
|
48
|
+
sub_api = subparsers.add_parser("api", help="Direct API calls")
|
|
49
|
+
sub_tools = subparsers.add_parser("tools", help="Client side tools for convenience")
|
|
50
|
+
sub_wandb = subparsers.add_parser("wandb", help="Logging with Weights & Biases")
|
|
51
|
+
|
|
52
|
+
api_register(sub_api)
|
|
53
|
+
tools_register(sub_tools)
|
|
54
|
+
wandb_register(sub_wandb)
|
|
55
|
+
|
|
56
|
+
args = parser.parse_args()
|
|
57
|
+
if args.verbosity == 1:
|
|
58
|
+
logger.setLevel(logging.INFO)
|
|
59
|
+
elif args.verbosity >= 2:
|
|
60
|
+
logger.setLevel(logging.DEBUG)
|
|
61
|
+
|
|
62
|
+
openai.debug = True
|
|
63
|
+
if args.api_key is not None:
|
|
64
|
+
openai.api_key = args.api_key
|
|
65
|
+
if args.api_base is not None:
|
|
66
|
+
openai.api_base = args.api_base
|
|
67
|
+
if args.organization is not None:
|
|
68
|
+
openai.organization = args.organization
|
|
69
|
+
if args.proxy is not None:
|
|
70
|
+
openai.proxy = {}
|
|
71
|
+
for proxy in args.proxy:
|
|
72
|
+
if proxy.startswith('https'):
|
|
73
|
+
openai.proxy['https'] = proxy
|
|
74
|
+
elif proxy.startswith('http'):
|
|
75
|
+
openai.proxy['http'] = proxy
|
|
76
|
+
|
|
77
|
+
try:
|
|
78
|
+
args.func(args)
|
|
79
|
+
except openai.error.OpenAIError as e:
|
|
80
|
+
display_error(e)
|
|
81
|
+
return 1
|
|
82
|
+
except KeyboardInterrupt:
|
|
83
|
+
sys.stderr.write("\n")
|
|
84
|
+
return 1
|
|
85
|
+
return 0
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
if __name__ == "__main__":
|
|
89
|
+
sys.exit(main())
|