main
 1from __future__ import annotations
 2
 3from typing import TYPE_CHECKING, Any
 4from typing_extensions import override
 5
 6from .._utils import LazyProxy
 7from .._exceptions import OpenAIError
 8
 9INSTRUCTIONS = """
10
11You tried to access openai.{symbol}, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the API.
12
13You can run `openai migrate` to automatically upgrade your codebase to use the 1.0.0 interface. 
14
15Alternatively, you can pin your installation to the old version, e.g. `pip install openai==0.28`
16
17A detailed migration guide is available here: https://github.com/openai/openai-python/discussions/742
18"""
19
20
21class APIRemovedInV1(OpenAIError):
22    def __init__(self, *, symbol: str) -> None:
23        super().__init__(INSTRUCTIONS.format(symbol=symbol))
24
25
26class APIRemovedInV1Proxy(LazyProxy[Any]):
27    def __init__(self, *, symbol: str) -> None:
28        super().__init__()
29        self._symbol = symbol
30
31    @override
32    def __load__(self) -> Any:
33        # return the proxy until it is eventually called so that
34        # we don't break people that are just checking the attributes
35        # of a module
36        return self
37
38    def __call__(self, *_args: Any, **_kwargs: Any) -> Any:
39        raise APIRemovedInV1(symbol=self._symbol)
40
41
42SYMBOLS = [
43    "Edit",
44    "File",
45    "Audio",
46    "Image",
47    "Model",
48    "Engine",
49    "Customer",
50    "FineTune",
51    "Embedding",
52    "Completion",
53    "Deployment",
54    "Moderation",
55    "ErrorObject",
56    "FineTuningJob",
57    "ChatCompletion",
58]
59
60# we explicitly tell type checkers that nothing is exported
61# from this file so that when we re-export the old symbols
62# in `openai/__init__.py` they aren't added to the auto-complete
63# suggestions given by editors
64if TYPE_CHECKING:
65    __all__: list[str] = []
66else:
67    __all__ = SYMBOLS
68
69
70__locals = locals()
71for symbol in SYMBOLS:
72    __locals[symbol] = APIRemovedInV1Proxy(symbol=symbol)