@@ -103,18 +103,59 @@ def get_config():
103103plugin_approaches = {}
104104
105105def load_plugins ():
106- plugin_dir = os .path .join (os .path .dirname (__file__ ), 'optillm/plugins' )
107- plugin_files = glob .glob (os .path .join (plugin_dir , '*.py' ))
108-
109- for plugin_file in plugin_files :
110- module_name = os .path .basename (plugin_file )[:- 3 ] # Remove .py extension
111- spec = importlib .util .spec_from_file_location (module_name , plugin_file )
112- module = importlib .util .module_from_spec (spec )
113- spec .loader .exec_module (module )
114-
115- if hasattr (module , 'SLUG' ) and hasattr (module , 'run' ):
116- plugin_approaches [module .SLUG ] = module .run
117- logger .info (f"Loaded plugin: { module .SLUG } " )
106+ # Clear existing plugins first but modify the global dict in place
107+ plugin_approaches .clear ()
108+
109+ # Get installed package plugins directory
110+ import optillm
111+ package_plugin_dir = os .path .join (os .path .dirname (optillm .__file__ ), 'plugins' )
112+
113+ # Get local project plugins directory
114+ current_dir = os .getcwd ()
115+ local_plugin_dir = os .path .join (current_dir , 'optillm' , 'plugins' )
116+
117+ plugin_dirs = []
118+
119+ # Add package plugin dir
120+ plugin_dirs .append ((package_plugin_dir , "package" ))
121+
122+ # Add local plugin dir only if it's different from package dir
123+ if local_plugin_dir != package_plugin_dir :
124+ plugin_dirs .append ((local_plugin_dir , "local" ))
125+
126+ for plugin_dir , source in plugin_dirs :
127+ logger .info (f"Looking for { source } plugins in: { plugin_dir } " )
128+
129+ if not os .path .exists (plugin_dir ):
130+ logger .debug (f"{ source .capitalize ()} plugin directory not found: { plugin_dir } " )
131+ continue
132+
133+ plugin_files = glob .glob (os .path .join (plugin_dir , '*.py' ))
134+ if not plugin_files :
135+ logger .debug (f"No plugin files found in { source } directory: { plugin_dir } " )
136+ continue
137+
138+ logger .info (f"Found { source } plugin files: { plugin_files } " )
139+
140+ for plugin_file in plugin_files :
141+ try :
142+ module_name = os .path .basename (plugin_file )[:- 3 ] # Remove .py extension
143+ spec = importlib .util .spec_from_file_location (module_name , plugin_file )
144+ module = importlib .util .module_from_spec (spec )
145+ spec .loader .exec_module (module )
146+
147+ if hasattr (module , 'SLUG' ) and hasattr (module , 'run' ):
148+ if module .SLUG in plugin_approaches :
149+ logger .info (f"Overriding { source } plugin: { module .SLUG } " )
150+ plugin_approaches [module .SLUG ] = module .run
151+ logger .info (f"Loaded { source } plugin: { module .SLUG } " )
152+ else :
153+ logger .warning (f"Plugin { module_name } from { source } missing required attributes (SLUG and run)" )
154+ except Exception as e :
155+ logger .error (f"Error loading { source } plugin { plugin_file } : { str (e )} " )
156+
157+ if not plugin_approaches :
158+ logger .warning ("No plugins loaded from any location" )
118159
119160def parse_combined_approach (model : str , known_approaches : list , plugin_approaches : dict ):
120161 if model == 'auto' :
0 commit comments