refactor: pass ModelInfo instead of model name string through provider interface
This commit is contained in:
parent
8e3ed7010f
commit
d15444bdb0
8 changed files with 83 additions and 43 deletions
|
|
@ -4,11 +4,14 @@ from __future__ import annotations
|
|||
|
||||
import enum
|
||||
from pathlib import Path
|
||||
from typing import Self
|
||||
from typing import TYPE_CHECKING, Self
|
||||
|
||||
import yaml
|
||||
from pydantic import BaseModel, model_validator
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from bulkgen.providers.models import ModelInfo
|
||||
|
||||
|
||||
class TargetType(enum.Enum):
|
||||
"""The kind of artifact a target produces."""
|
||||
|
|
@ -65,14 +68,29 @@ def infer_target_type(target_name: str) -> TargetType:
|
|||
raise ValueError(msg)
|
||||
|
||||
|
||||
def resolve_model(target_name: str, target: TargetConfig, defaults: Defaults) -> str:
|
||||
"""Return the effective model for a target (explicit or default by type)."""
|
||||
def resolve_model(
|
||||
target_name: str, target: TargetConfig, defaults: Defaults
|
||||
) -> ModelInfo:
|
||||
"""Return the effective model for a target (explicit or default by type).
|
||||
|
||||
Raises :class:`ValueError` if the resolved model name is not in the registry.
|
||||
"""
|
||||
from bulkgen.providers.models import ALL_MODELS
|
||||
|
||||
if target.model is not None:
|
||||
return target.model
|
||||
target_type = infer_target_type(target_name)
|
||||
if target_type is TargetType.IMAGE:
|
||||
return defaults.image_model
|
||||
return defaults.text_model
|
||||
model_name = target.model
|
||||
else:
|
||||
target_type = infer_target_type(target_name)
|
||||
model_name = (
|
||||
defaults.image_model
|
||||
if target_type is TargetType.IMAGE
|
||||
else defaults.text_model
|
||||
)
|
||||
for model in ALL_MODELS:
|
||||
if model.name == model_name:
|
||||
return model
|
||||
msg = f"Unknown model '{model_name}' for target '{target_name}'"
|
||||
raise ValueError(msg)
|
||||
|
||||
|
||||
def load_config(config_path: Path) -> ProjectConfig:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue