PotionUI Docs v0.3.0

Contributing an LLM configuration type

A plugin can add a provider to the Type list of Admin → LLM / Assistant → Add configuration. Declare it under llm_providers::

yaml
llm_providers:
  - type: acme
    label: Acme
    backend: backend.adapter:AcmeAdapter   # "module.path:ClassName"
    default_base_url: https://api.acme.example/v1

backend is loaded and instantiated once when the plugin enables, like a recipe_steps[].backend, and every configuration whose type is acme is then sent through that object. The object is an Adapter: it renders a RenderRequest (the typed messages, tools and settings of one model call) into a WireRequest, sends it, and decodes the reply into stream events. For a service that speaks the OpenAI chat-completions schema, subclass OpenAIChatAdapter from src.plugin_api.llm and adjust the request body in build_body, which every call (streamed, buffered and tool-calling) goes through before it is sent:

python
from src.plugin_api.llm import CapabilityProfile, OpenAIChatAdapter, RenderRequest

class AcmeAdapter(OpenAIChatAdapter):
    display_name = "Acme"

    def build_body(self, request: RenderRequest, profile: CapabilityProfile) -> dict:
        body = super().build_body(request, profile)
        body["max_tokens"] = body.pop("max_completion_tokens")
        return body

The inherited list_models and discover read the service's /models listing, so the model picker and the model's context window work without more code; override them (they return DiscoveredModel entries and a ProfileLayer) when the service lists models another way. A service with its own wire format subclasses HttpAdapter and implements render, decoder, discover and list_models; override classify_error when its error replies need a different mapping to the typed provider errors. The form lists label after the built-in types. When the admin picks a type, it puts that type's default_base_url in the Base URL if the field is empty or still holds another type's default, and leaves a URL the admin typed alone. A type named like a built-in one (openai, ollama, native) is ignored, and a type another enabled plugin already owns fails the enable. Disabling the plugin takes the type away: configurations saved with it stay, and fail with "Unsupported LLM type" until the plugin is enabled again.