|
1 |
| -from typing import TYPE_CHECKING |
2 |
| - |
3 |
| -from ._import_utils import import_attr as _import_attr |
| 1 | +from __future__ import annotations |
4 | 2 | from ._version import __version__
|
5 | 3 |
|
6 |
| -if TYPE_CHECKING: |
7 |
| - # same as dynamic imports but understood by mypy |
8 |
| - from .embedding_providers import ( |
9 |
| - BaseEmbeddingsProvider, |
10 |
| - GPT4AllEmbeddingsProvider, |
11 |
| - HfHubEmbeddingsProvider, |
12 |
| - QianfanEmbeddingsEndpointProvider, |
13 |
| - ) |
14 |
| - from .exception import store_exception |
15 |
| - from .magics import AiMagics |
16 |
| - from .providers import ( |
17 |
| - AI21Provider, |
18 |
| - BaseProvider, |
19 |
| - GPT4AllProvider, |
20 |
| - HfHubProvider, |
21 |
| - QianfanProvider, |
22 |
| - TogetherAIProvider, |
23 |
| - ) |
24 |
| -else: |
25 |
| - _exports_by_module = { |
26 |
| - "embedding_providers": [ |
27 |
| - "BaseEmbeddingsProvider", |
28 |
| - "GPT4AllEmbeddingsProvider", |
29 |
| - "HfHubEmbeddingsProvider", |
30 |
| - "QianfanEmbeddingsEndpointProvider", |
31 |
| - ], |
32 |
| - "exception": ["store_exception"], |
33 |
| - "magics": ["AiMagics"], |
34 |
| - # expose model providers on the package root |
35 |
| - "providers": [ |
36 |
| - "AI21Provider", |
37 |
| - "BaseProvider", |
38 |
| - "GPT4AllProvider", |
39 |
| - "HfHubProvider", |
40 |
| - "QianfanProvider", |
41 |
| - "TogetherAIProvider", |
42 |
| - ], |
43 |
| - } |
| 4 | +from typing import TYPE_CHECKING |
44 | 5 |
|
45 |
| - _modules_by_export = { |
46 |
| - import_name: module |
47 |
| - for module, imports in _exports_by_module.items() |
48 |
| - for import_name in imports |
49 |
| - } |
| 6 | +if TYPE_CHECKING: |
| 7 | + from IPython.core.interactiveshell import InteractiveShell |
50 | 8 |
|
51 |
| - def __getattr__(export_name: str) -> object: |
52 |
| - module_name = _modules_by_export.get(export_name) |
53 |
| - result = _import_attr(export_name, module_name, __spec__.parent) |
54 |
| - globals()[export_name] = result |
55 |
| - return result |
56 | 9 |
|
| 10 | +def load_ipython_extension(ipython: InteractiveShell): |
| 11 | + from .exception import store_exception |
| 12 | + from .magics import AiMagics |
57 | 13 |
|
58 |
| -def load_ipython_extension(ipython): |
59 |
| - ipython.register_magics(__getattr__("AiMagics")) |
60 |
| - ipython.set_custom_exc((BaseException,), __getattr__("store_exception")) |
| 14 | + ipython.register_magics(AiMagics) |
| 15 | + ipython.set_custom_exc((BaseException,), store_exception) |
61 | 16 |
|
62 | 17 |
|
63 |
| -def unload_ipython_extension(ipython): |
| 18 | +def unload_ipython_extension(ipython: InteractiveShell): |
64 | 19 | ipython.set_custom_exc((BaseException,), ipython.CustomTB)
|
65 |
| - |
66 |
| - |
67 |
| -# required to preserve backward compatibility with `from jupyter_ai_magics import *` |
68 |
| -__all__ = [ |
69 |
| - "__version__", |
70 |
| - "load_ipython_extension", |
71 |
| - "unload_ipython_extension", |
72 |
| - "BaseEmbeddingsProvider", |
73 |
| - "GPT4AllEmbeddingsProvider", |
74 |
| - "HfHubEmbeddingsProvider", |
75 |
| - "QianfanEmbeddingsEndpointProvider", |
76 |
| - "store_exception", |
77 |
| - "AiMagics", |
78 |
| - "AI21Provider", |
79 |
| - "BaseProvider", |
80 |
| - "GPT4AllProvider", |
81 |
| - "HfHubProvider", |
82 |
| - "QianfanProvider", |
83 |
| - "TogetherAIProvider", |
84 |
| -] |
85 |
| - |
86 |
| - |
87 |
| -def __dir__(): |
88 |
| - # Allows more editors (e.g. IPython) to complete on `jupyter_ai_magics.<tab>` |
89 |
| - return list(__all__) |
0 commit comments