refactor: switch to basedpyright, remove pydantic-settings
- Replace pyright with basedpyright in devenv.nix (custom hook) - Add basedpyright to devenv packages - Fix all basedpyright warnings: add DiGraph[str] type args, annotate class attributes, narrow SyncResponse, handle unused call results, suppress unavoidable Any from yaml.safe_load and untyped blackforest - Replace pydantic-settings[yaml] with direct pyyaml dependency - Update CLAUDE.md to reflect basedpyright and dependency changes
This commit is contained in:
parent
f71af1cfaf
commit
7ab25d49cb
11 changed files with 58 additions and 59 deletions
|
|
@ -8,8 +8,13 @@ from pathlib import Path
|
|||
from typing import override
|
||||
|
||||
import httpx
|
||||
from blackforest import BFLClient
|
||||
from blackforest.types.general.client_config import ClientConfig
|
||||
from blackforest import BFLClient # pyright: ignore[reportMissingTypeStubs]
|
||||
from blackforest.types.general.client_config import ( # pyright: ignore[reportMissingTypeStubs]
|
||||
ClientConfig,
|
||||
)
|
||||
from blackforest.types.responses.responses import ( # pyright: ignore[reportMissingTypeStubs]
|
||||
SyncResponse,
|
||||
)
|
||||
|
||||
from bulkgen.config import TargetConfig
|
||||
from bulkgen.providers import Provider
|
||||
|
|
@ -25,6 +30,8 @@ def _encode_image_b64(path: Path) -> str:
|
|||
class ImageProvider(Provider):
|
||||
"""Generates images via the BlackForestLabs API."""
|
||||
|
||||
_client: BFLClient
|
||||
|
||||
def __init__(self, api_key: str) -> None:
|
||||
self._client = BFLClient(api_key=api_key)
|
||||
|
||||
|
|
@ -58,13 +65,20 @@ class ImageProvider(Provider):
|
|||
self._client.generate, resolved_model, inputs, _BFL_SYNC_CONFIG
|
||||
)
|
||||
|
||||
image_url: str | None = result.result.get("sample") # type: ignore[union-attr]
|
||||
if not isinstance(result, SyncResponse):
|
||||
msg = (
|
||||
f"BFL API returned unexpected response type for target '{target_name}'"
|
||||
)
|
||||
raise RuntimeError(msg)
|
||||
|
||||
result_dict: dict[str, str] = result.result # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
|
||||
image_url = result_dict.get("sample")
|
||||
if not image_url:
|
||||
msg = f"BFL API did not return an image URL for target '{target_name}'"
|
||||
raise RuntimeError(msg)
|
||||
|
||||
async with httpx.AsyncClient() as http:
|
||||
response = await http.get(image_url)
|
||||
response.raise_for_status()
|
||||
_ = response.raise_for_status()
|
||||
|
||||
output_path.write_bytes(response.content)
|
||||
_ = output_path.write_bytes(response.content)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue