Implementation:1Panel dev MaxKB ModelInfoManage
| Knowledge Sources | |
|---|---|
| Domains | Model_Provider, Design_Patterns |
| Last Updated | 2026-10-10 00:00 GMT |
Overview
Concrete registry for model information entries with a fluent builder pattern, provided by MaxKB.
Description
The ModelInfoManage class stores all registered ModelInfo entries for a vendor, organized by model type and name in a nested dict (`model_dict[type][name] → ModelInfo`). It also tracks default models per type. The inner builder class provides a fluent API: `builder().append_model_info(info).append_model_info_list(list).append_default_model_info(info).build()`. The ModelInfo class wraps a model's name, description, type, credential handler, and model class.
Usage
Import this class when you need to:
- Register model entries for a vendor provider
- Query available models by type
- Look up a specific model's credential handler or model class
Code Reference
Source Location
- Repository: MaxKB
- File: apps/models_provider/base_model_provider.py
Signature
class ModelInfo:
def __init__(
self,
name: str,
desc: str,
model_type: ModelTypeConst,
model_credential: BaseModelCredential,
model_class: Type[MaxKBBaseModel],
**keywords,
):
"""Create a model info entry."""
class ModelInfoManage:
model_dict: Dict[str, Dict[str, ModelInfo]] # type → name → ModelInfo
model_list: List[ModelInfo]
default_model_list: List[ModelInfo]
default_model_dict: Dict[str, ModelInfo]
def append_model_info(self, model_info: ModelInfo) -> None:
"""Register a model entry."""
def get_model_info(self, model_type: str, model_name: str) -> ModelInfo:
"""Look up by type and name (falls back to default)."""
def get_model_type_list(self) -> list:
"""Return list of supported model types with counts."""
class builder:
def append_model_info(self, model_info: ModelInfo) -> builder:
"""Add a single model info. Returns self for chaining."""
def append_model_info_list(self, model_info_list: List[ModelInfo]) -> builder:
"""Add multiple model infos. Returns self for chaining."""
def append_default_model_info(self, model_info: ModelInfo) -> builder:
"""Set default model for its type. Returns self for chaining."""
def build(self) -> ModelInfoManage:
"""Return the constructed ModelInfoManage."""
Import
from models_provider.base_model_provider import ModelInfo, ModelInfoManage
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| model_info | ModelInfo | Yes | Model entry to register |
Outputs
| Name | Type | Description |
|---|---|---|
| build() returns | ModelInfoManage | Registry with all entries |
| get_model_info() returns | ModelInfo | Entry for type+name (or default) |
Usage Examples
Building a Model Registry
from models_provider.base_model_provider import ModelInfo, ModelInfoManage, ModelTypeConst
# Build the registry
model_info_manage = (
ModelInfoManage.builder()
.append_model_info(ModelInfo(
name='gpt-4',
desc='GPT-4 model',
model_type=ModelTypeConst.LLM,
model_credential=OpenAILLMCredential(),
model_class=OpenAIChatModel,
))
.append_model_info(ModelInfo(
name='text-embedding-ada-002',
desc='OpenAI embedding model',
model_type=ModelTypeConst.EMBEDDING,
model_credential=OpenAIEmbeddingCredential(),
model_class=OpenAIEmbeddingModel,
))
.append_default_model_info(ModelInfo(
name='gpt-3.5-turbo',
desc='Default LLM',
model_type=ModelTypeConst.LLM,
model_credential=OpenAILLMCredential(),
model_class=OpenAIChatModel,
))
.build()
)
# Query models
llm_list = model_info_manage.get_model_list_by_model_type('LLM')
model_info = model_info_manage.get_model_info('LLM', 'gpt-4')