|
4 | 4 | import logging |
5 | 5 | from collections.abc import AsyncGenerator, AsyncIterable |
6 | 6 | from dataclasses import dataclass |
7 | | -from typing import TYPE_CHECKING, Any, Literal, TypeVar |
| 7 | +from typing import TYPE_CHECKING, Any, Literal, TypedDict, TypeVar |
8 | 8 |
|
9 | 9 | from pydantic import BaseModel |
10 | 10 |
|
|
22 | 22 | T = TypeVar("T", bound=BaseModel) |
23 | 23 |
|
24 | 24 |
|
| 25 | +class BaseModelConfig(TypedDict, total=False): |
| 26 | + """Base configuration shared by all model providers. |
| 27 | +
|
| 28 | + Attributes: |
| 29 | + context_window_limit: Maximum context window size in tokens for the model. |
| 30 | + This value represents the total token capacity shared between input and output. |
| 31 | + """ |
| 32 | + |
| 33 | + context_window_limit: int | None |
| 34 | + |
| 35 | + |
25 | 36 | @dataclass |
26 | 37 | class CacheConfig: |
27 | 38 | """Configuration for prompt caching. |
@@ -51,6 +62,16 @@ def stateful(self) -> bool: |
51 | 62 | """ |
52 | 63 | return False |
53 | 64 |
|
| 65 | + @property |
| 66 | + def context_window_limit(self) -> int | None: |
| 67 | + """Maximum context window size in tokens, or None if not configured.""" |
| 68 | + config = self.get_config() |
| 69 | + return ( |
| 70 | + config.get("context_window_limit") |
| 71 | + if isinstance(config, dict) |
| 72 | + else getattr(config, "context_window_limit", None) |
| 73 | + ) |
| 74 | + |
54 | 75 | @abc.abstractmethod |
55 | 76 | # pragma: no cover |
56 | 77 | def update_config(self, **model_config: Any) -> None: |
|
0 commit comments