34
34
- LangChain (LLMs, Chat Models, and Prompt Templates)
35
35
"""
36
36
37
- from . import utils
38
- from . import consts
39
- from .adapters import anthropic , openai
40
- from .logger import logger , reconfigure_logger
37
+ # Import consts directly to avoid cyclic imports
38
+ from .consts import package_name , package_version , indent
41
39
42
- # Re-export configuration flags for easy access
43
- enabled = utils .enabled
44
- use_stderr = utils .use_stderr
45
- pretty_print = utils .pretty_print
46
- print_messages = utils .print_messages
47
- indent = consts .indent
48
-
49
- # Re-export initialization function
50
- init = utils .init
51
-
52
- # Export adapter functions
53
- wrap_anthropic = anthropic .wrap_anthropic
54
- wrap_openai = openai .wrap_openai
55
-
56
- # Export disable and enable functions
57
- disable_hoover = utils .disable_hoover
58
- enable_hoover = utils .enable_hoover
59
-
60
- # Automatically apply patches when the module is imported
61
- wrap_anthropic ()
62
- wrap_openai ()
63
-
64
- # Conditionally load and apply LangChain wrapper
65
- try :
66
- from .adapters import langchain
67
- wrap_langchain = langchain .wrap_langchain
68
- # Apply the wrapper, but don't fail if it doesn't work
40
+ # Use lazy imports to avoid importing modules during setup
41
+ def _import_modules ():
42
+ global utils , logger , reconfigure_logger , anthropic , openai , langchain
43
+ global enabled , use_stderr , pretty_print , print_messages
44
+ global init , wrap_anthropic , wrap_openai , disable_hoover , enable_hoover , wrap_langchain
45
+
46
+ from . import utils
47
+ from .logger import logger , reconfigure_logger
48
+ from .adapters import anthropic , openai
49
+
50
+ # Re-export configuration flags for easy access
51
+ enabled = utils .enabled
52
+ use_stderr = utils .use_stderr
53
+ pretty_print = utils .pretty_print
54
+ print_messages = utils .print_messages
55
+
56
+ # Re-export initialization function
57
+ init = utils .init
58
+
59
+ # Export adapter functions
60
+ wrap_anthropic = anthropic .wrap_anthropic
61
+ wrap_openai = openai .wrap_openai
62
+
63
+ # Export disable and enable functions
64
+ disable_hoover = utils .disable_hoover
65
+ enable_hoover = utils .enable_hoover
66
+
67
+ # Automatically apply patches when the module is imported
68
+ wrap_anthropic ()
69
+ wrap_openai ()
70
+
71
+ # Conditionally load and apply LangChain wrapper
69
72
try :
70
- wrap_langchain ()
71
- except Exception as e :
72
- logger .warning (f"Failed to wrap LangChain: { str (e )} " )
73
- except ImportError :
74
- # LangChain not installed or not compatible
75
- def wrap_langchain ():
76
- logger .warning ("LangChain support not available. Install LangChain to use this feature." )
73
+ from .adapters import langchain
74
+ wrap_langchain = langchain .wrap_langchain
75
+ # Apply the wrapper, but don't fail if it doesn't work
76
+ try :
77
+ wrap_langchain ()
78
+ except Exception as e :
79
+ logger .warning (f"Failed to wrap LangChain: { str (e )} " )
80
+ except ImportError :
81
+ # LangChain not installed or not compatible
82
+ def wrap_langchain ():
83
+ logger .warning ("LangChain support not available. Install LangChain to use this feature." )
84
+
85
+ # Initialize the module on first import, but not during installation
86
+ import sys
87
+ if 'pip' not in sys .modules :
88
+ _import_modules ()
0 commit comments