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
|
|
@ -6,6 +6,7 @@ import abc
|
|||
from pathlib import Path
|
||||
|
||||
from bulkgen.config import TargetConfig
|
||||
from bulkgen.providers.models import ModelInfo
|
||||
|
||||
|
||||
class Provider(abc.ABC):
|
||||
|
|
@ -17,7 +18,7 @@ class Provider(abc.ABC):
|
|||
target_name: str,
|
||||
target_config: TargetConfig,
|
||||
resolved_prompt: str,
|
||||
resolved_model: str,
|
||||
resolved_model: ModelInfo,
|
||||
project_dir: Path,
|
||||
) -> None:
|
||||
"""Generate the target artifact and write it to *project_dir / target_name*.
|
||||
|
|
@ -26,6 +27,6 @@ class Provider(abc.ABC):
|
|||
target_name: Output filename (relative to project_dir).
|
||||
target_config: The parsed target configuration.
|
||||
resolved_prompt: The fully resolved prompt text.
|
||||
resolved_model: The resolved model name.
|
||||
resolved_model: The resolved model information.
|
||||
project_dir: The project working directory.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import httpx
|
|||
from bulkgen.config import TargetConfig
|
||||
from bulkgen.providers import Provider
|
||||
from bulkgen.providers.bfl import BFLClient
|
||||
from bulkgen.providers.models import ModelInfo
|
||||
|
||||
|
||||
def _encode_image_b64(path: Path) -> str:
|
||||
|
|
@ -58,7 +59,7 @@ class ImageProvider(Provider):
|
|||
target_name: str,
|
||||
target_config: TargetConfig,
|
||||
resolved_prompt: str,
|
||||
resolved_model: str,
|
||||
resolved_model: ModelInfo,
|
||||
project_dir: Path,
|
||||
) -> None:
|
||||
output_path = project_dir / target_name
|
||||
|
|
@ -72,14 +73,14 @@ class ImageProvider(Provider):
|
|||
|
||||
if target_config.reference_images:
|
||||
_add_reference_images(
|
||||
inputs, target_config.reference_images, resolved_model, project_dir
|
||||
inputs, target_config.reference_images, resolved_model.name, project_dir
|
||||
)
|
||||
|
||||
for control_name in target_config.control_images:
|
||||
ctrl_path = project_dir / control_name
|
||||
inputs["control_image"] = _encode_image_b64(ctrl_path)
|
||||
|
||||
result = await self._client.generate(resolved_model, inputs)
|
||||
result = await self._client.generate(resolved_model.name, inputs)
|
||||
|
||||
async with httpx.AsyncClient() as http:
|
||||
response = await http.get(result.sample_url)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ from mistralai import Mistral, models
|
|||
|
||||
from bulkgen.config import IMAGE_EXTENSIONS, TargetConfig
|
||||
from bulkgen.providers import Provider
|
||||
from bulkgen.providers.models import ModelInfo
|
||||
|
||||
|
||||
def _image_to_data_url(path: Path) -> str:
|
||||
|
|
@ -34,7 +35,7 @@ class TextProvider(Provider):
|
|||
target_name: str,
|
||||
target_config: TargetConfig,
|
||||
resolved_prompt: str,
|
||||
resolved_model: str,
|
||||
resolved_model: ModelInfo,
|
||||
project_dir: Path,
|
||||
) -> None:
|
||||
output_path = project_dir / target_name
|
||||
|
|
@ -57,7 +58,7 @@ class TextProvider(Provider):
|
|||
|
||||
async with Mistral(api_key=self._api_key) as client:
|
||||
response = await client.chat.complete_async(
|
||||
model=resolved_model,
|
||||
model=resolved_model.name,
|
||||
messages=[message],
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue