MCPcopy
hub / github.com/algorithmicsuperintelligence/optillm / load_plugins

Function load_plugins

optillm/server.py:287–340  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

285 raise
286
287def load_plugins():
288 # Clear existing plugins first but modify the global dict in place
289 plugin_approaches.clear()
290
291 # Get installed package plugins directory
292 import optillm
293 package_plugin_dir = os.path.join(os.path.dirname(optillm.__file__), 'plugins')
294
295 # Get local project plugins directory
296 current_dir = os.getcwd() if server_config.get("plugins_dir", "") == "" else server_config["plugins_dir"]
297 local_plugin_dir = os.path.join(current_dir, 'optillm', 'plugins')
298
299 plugin_dirs = []
300
301 # Add package plugin dir
302 plugin_dirs.append((package_plugin_dir, "package"))
303
304 # Add local plugin dir only if it's different from package dir
305 if local_plugin_dir != package_plugin_dir:
306 plugin_dirs.append((local_plugin_dir, "local"))
307
308 for plugin_dir, source in plugin_dirs:
309 logger.info(f"Looking for {source} plugins in: {plugin_dir}")
310
311 if not os.path.exists(plugin_dir):
312 logger.debug(f"{source.capitalize()} plugin directory not found: {plugin_dir}")
313 continue
314
315 plugin_files = glob.glob(os.path.join(plugin_dir, '*.py'))
316 if not plugin_files:
317 logger.debug(f"No plugin files found in {source} directory: {plugin_dir}")
318 continue
319
320 logger.info(f"Found {source} plugin files: {plugin_files}")
321
322 for plugin_file in plugin_files:
323 try:
324 module_name = os.path.basename(plugin_file)[:-3] # Remove .py extension
325 spec = importlib.util.spec_from_file_location(module_name, plugin_file)
326 module = importlib.util.module_from_spec(spec)
327 spec.loader.exec_module(module)
328
329 if hasattr(module, 'SLUG') and hasattr(module, 'run'):
330 if module.SLUG in plugin_approaches:
331 logger.info(f"Overriding {source} plugin: {module.SLUG}")
332 plugin_approaches[module.SLUG] = module.run
333 logger.info(f"Loaded {source} plugin: {module.SLUG}")
334 else:
335 logger.warning(f"Plugin {module_name} from {source} missing required attributes (SLUG and run)")
336 except Exception as e:
337 logger.error(f"Error loading {source} plugin {plugin_file}: {str(e)}")
338
339 if not plugin_approaches:
340 logger.warning("No plugins loaded from any location")
341
342def get_config_path():
343 # Get installed package config directory

Callers 2

mainFunction · 0.85

Calls

no outgoing calls

Tested by 1