Skip to content

Commit 66326aa

Browse files
committed
Move some types around
1 parent 580b6ac commit 66326aa

7 files changed

Lines changed: 69 additions & 67 deletions

File tree

src/ai/models/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@
2525
"""
2626

2727
from ..types.stream import StreamResultLike
28-
from .ai_gateway.types import GenerateParams, ImageParams, VideoParams
2928
from .core.adapters import register_check, register_generate, register_stream
3029
from .core.api import check_connection, generate, stream
3130
from .core.catalog import get_models, get_providers, register_catalog
3231
from .core.catalog import model as model
3332
from .core.client import _PROVIDER_DEFAULTS, Client
3433
from .core.model import Model, ModelCost
3534
from .core.proto import CheckConnFn, GenerateFn, StreamFn
36-
from .core.stream_result import StreamResult
35+
from .core.types import GenerateParams, ImageParams, StreamResult, VideoParams
3736

3837
__all__ = [
3938
# Core types

src/ai/models/ai_gateway/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
"""
77

88
from . import errors
9-
from .types import GenerateParams, ImageParams, VideoParams
109

1110
__all__ = [
12-
"GenerateParams",
13-
"ImageParams",
14-
"VideoParams",
1511
"errors",
1612
]
1713

src/ai/models/ai_gateway/generate.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""AI Gateway v3 generation adapter — image-model and video-model endpoints.
22
3-
Provides typed parameter objects (:class:`ImageParams`, :class:`VideoParams`)
4-
and a unified :func:`generate` entry point that dispatches based on param type
3+
Unified :func:`generate` entry point that dispatches based on param type
54
and validates against model capabilities.
65
"""
76

@@ -16,10 +15,10 @@
1615
from ..core import client as client_
1716
from ..core import model as model_
1817
from ..core.helpers import files
18+
from ..core.types import GenerateParams as GenerateParams
19+
from ..core.types import ImageParams as ImageParams
20+
from ..core.types import VideoParams as VideoParams
1921
from . import _common, errors
20-
from .types import GenerateParams as GenerateParams
21-
from .types import ImageParams as ImageParams
22-
from .types import VideoParams as VideoParams
2322

2423
# ---------------------------------------------------------------------------
2524
# Image generation — /image-model

src/ai/models/ai_gateway/types.py

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/ai/models/core/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@
77
from .client import Client
88
from .model import Model, ModelCost
99
from .proto import CheckConnFn, GenerateFn, StreamFn
10-
from .stream_result import StreamResult
10+
from .types import GenerateParams, ImageParams, StreamResult, VideoParams
1111

1212
__all__ = [
1313
"CheckConnFn",
1414
"Client",
1515
"GenerateFn",
16+
"GenerateParams",
17+
"ImageParams",
1618
"Model",
1719
"ModelCost",
1820
"StreamFn",
1921
"StreamResult",
22+
"VideoParams",
2023
"check_connection",
2124
"generate",
2225
"get_models",

src/ai/models/core/api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
from ...types import messages as messages_
1515
from ...types import stream as stream_
1616
from ...types import tools as tools_
17-
from ..ai_gateway import types as ai_gw_types
18-
from . import adapters, stream_result
17+
from . import adapters
1918
from . import client as client_
2019
from . import model as model_
20+
from . import types as types_
2121

2222

2323
async def stream(
@@ -50,7 +50,7 @@ async def stream(
5050
async def _real(call: middleware_.ModelContext) -> stream_.StreamResultLike:
5151
c = call.client or client_.auto_client(call.model)
5252
adapter_fn = adapters.get_stream_adapter(call.model.adapter)
53-
return stream_result.StreamResult(
53+
return types_.StreamResult(
5454
adapter_fn(
5555
c,
5656
call.model,
@@ -68,7 +68,7 @@ async def _real(call: middleware_.ModelContext) -> stream_.StreamResultLike:
6868
async def generate(
6969
model: model_.Model,
7070
messages: list[messages_.Message],
71-
params: ai_gw_types.GenerateParams | None = None,
71+
params: types_.GenerateParams | None = None,
7272
*,
7373
client: client_.Client | None = None,
7474
) -> messages_.Message:
Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,67 @@
1-
"""StreamResult — concrete wrapper around a message stream."""
1+
"""Core model-layer types — parameter objects and StreamResult.
2+
3+
Parameter types (:class:`ImageParams`, :class:`VideoParams`) live here
4+
because they parameterise the public :func:`generate` API.
5+
6+
:class:`StreamResult` is the concrete wrapper returned by :func:`stream`.
7+
"""
28

39
from __future__ import annotations
410

511
from collections.abc import AsyncGenerator
612
from typing import Any
713

14+
import pydantic
15+
816
from ...types import messages as messages_
917

18+
# ---------------------------------------------------------------------------
19+
# Generation parameter types
20+
# ---------------------------------------------------------------------------
21+
22+
_PARAMS_CONFIG = pydantic.ConfigDict(frozen=True, populate_by_name=True)
23+
24+
25+
class ImageParams(pydantic.BaseModel):
26+
"""Parameters for image generation (``/image-model`` endpoint)."""
27+
28+
model_config = _PARAMS_CONFIG
29+
30+
n: int = 1
31+
size: str | None = None
32+
aspect_ratio: str | None = pydantic.Field(
33+
default=None, serialization_alias="aspectRatio"
34+
)
35+
seed: int | None = None
36+
provider_options: dict[str, Any] = pydantic.Field(
37+
default_factory=dict, serialization_alias="providerOptions"
38+
)
39+
40+
41+
class VideoParams(pydantic.BaseModel):
42+
"""Parameters for video generation (``/video-model`` endpoint)."""
43+
44+
model_config = _PARAMS_CONFIG
45+
46+
n: int = 1
47+
aspect_ratio: str | None = pydantic.Field(
48+
default=None, serialization_alias="aspectRatio"
49+
)
50+
resolution: str | None = None
51+
duration: int | None = None
52+
fps: int | None = None
53+
seed: int | None = None
54+
provider_options: dict[str, Any] = pydantic.Field(
55+
default_factory=dict, serialization_alias="providerOptions"
56+
)
57+
58+
59+
GenerateParams = ImageParams | VideoParams
60+
61+
# ---------------------------------------------------------------------------
62+
# StreamResult
63+
# ---------------------------------------------------------------------------
64+
1065

1166
class StreamResult:
1267
"""Wrapper around a message stream. Async-iterable; collects the final result.

0 commit comments

Comments
 (0)