simonw / simonw/llm

Load Plugins at Runtime for the Python API

Open
#114 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation enhancement
Dominant language
Python
Stars
12.5k
Forks
998
Avg merge
3d 13h
Merged PRs (30d)
10

Description

I have been thoroughly enjoying and using the Python API from this library for a research project related to language models and hardware design.

I understand the use case of the plugin system is designed so that plugins are developed and installed separately from the main package. However, it is nice to be able to define models and other components and load them at runtime without having to develop a separate package/project.

After reading the source code, I was able to come up with a simple working example to load a model plugin at runtime:

import importlib

def load_plugin_module(name, module_path):
    mod = importlib.import_module(module_path)
    llm.plugins.pm.register(mod, name)

if __name__ == "__main__":
    load_plugin_module("my_markov_plugin", "my_models.markov")
    model = llm.get_model("markov")

This is just an initial idea to motivate the inclusion of utility functions to load plugins at runtime. I want to support loading specific classes directly rather than whole modules, but I am having trouble understanding how the Pluggy system works and how to achieve this at runtime.

Would like to hear what others also think about this idea.

Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Python API plugin flow shown in the issue: importlib, llm.plugins.pm.register, and llm.get_model("markov"). Read how the Pluggy-based plugin manager currently registers modules, then define whether runtime loading should support whole modules, individual classes, or both. Done should be a decided and documented runtime-loading behavior with a clear resolution path for registered models.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.