Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2293fc0

Browse filesBrowse files
fix(package): support direct resource imports
1 parent 01a69ab commit 2293fc0
Copy full SHA for 2293fc0

File tree

Expand file treeCollapse file tree

2 files changed

+28
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+28
-0
lines changed

‎src/openai/__init__.py

Copy file name to clipboardExpand all lines: src/openai/__init__.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import os as _os
6+
import typing as _t
67
from typing_extensions import override
78

89
from . import types
@@ -78,6 +79,9 @@
7879
"DefaultAsyncHttpxClient",
7980
]
8081

82+
if not _t.TYPE_CHECKING:
83+
from ._utils._resources_proxy import resources as resources
84+
8185
from .lib import azure as _azure, pydantic_function_tool as pydantic_function_tool
8286
from .version import VERSION as VERSION
8387
from .lib.azure import AzureOpenAI as AzureOpenAI, AsyncAzureOpenAI as AsyncAzureOpenAI

‎src/openai/_utils/_resources_proxy.py

Copy file name to clipboard
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from __future__ import annotations
2+
3+
from typing import Any
4+
from typing_extensions import override
5+
6+
from ._proxy import LazyProxy
7+
8+
9+
class ResourcesProxy(LazyProxy[Any]):
10+
"""A proxy for the `openai.resources` module.
11+
12+
This is used so that we can lazily import `openai.resources` only when
13+
needed *and* so that users can just import `openai` and reference `openai.resources`
14+
"""
15+
16+
@override
17+
def __load__(self) -> Any:
18+
import importlib
19+
20+
mod = importlib.import_module("openai.resources")
21+
return mod
22+
23+
24+
resources = ResourcesProxy().__as_proxied__()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.