@@ -177,9 +177,6 @@ class ModelRequestParameters:
177
177
class Model (ABC ):
178
178
"""Abstract class for a model."""
179
179
180
- _model_name : str
181
- _system : str | None
182
-
183
180
@abstractmethod
184
181
async def request (
185
182
self ,
@@ -205,24 +202,25 @@ async def request_stream(
205
202
yield # pragma: no cover
206
203
207
204
@property
205
+ @abstractmethod
208
206
def model_name (self ) -> str :
209
207
"""The model name."""
210
- return self . _model_name
208
+ raise NotImplementedError ()
211
209
212
210
@property
211
+ @abstractmethod
213
212
def system (self ) -> str | None :
214
213
"""The system / model provider, ex: openai."""
215
- return self . _system
214
+ raise NotImplementedError ()
216
215
217
216
218
217
@dataclass
219
218
class StreamedResponse (ABC ):
220
219
"""Streamed response from an LLM when calling a tool."""
221
220
222
- _model_name : str
223
- _usage : Usage = field (default_factory = Usage , init = False )
224
221
_parts_manager : ModelResponsePartsManager = field (default_factory = ModelResponsePartsManager , init = False )
225
222
_event_iterator : AsyncIterator [ModelResponseStreamEvent ] | None = field (default = None , init = False )
223
+ _usage : Usage = field (default_factory = Usage , init = False )
226
224
227
225
def __aiter__ (self ) -> AsyncIterator [ModelResponseStreamEvent ]:
228
226
"""Stream the response as an async iterable of [`ModelResponseStreamEvent`][pydantic_ai.messages.ModelResponseStreamEvent]s."""
@@ -244,17 +242,20 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
244
242
def get (self ) -> ModelResponse :
245
243
"""Build a [`ModelResponse`][pydantic_ai.messages.ModelResponse] from the data received from the stream so far."""
246
244
return ModelResponse (
247
- parts = self ._parts_manager .get_parts (), model_name = self ._model_name , timestamp = self .timestamp ()
245
+ parts = self ._parts_manager .get_parts (), model_name = self .model_name , timestamp = self .timestamp
248
246
)
249
247
250
- def model_name (self ) -> str :
251
- """Get the model name of the response."""
252
- return self ._model_name
253
-
254
248
def usage (self ) -> Usage :
255
249
"""Get the usage of the response so far. This will not be the final usage until the stream is exhausted."""
256
250
return self ._usage
257
251
252
+ @property
253
+ @abstractmethod
254
+ def model_name (self ) -> str :
255
+ """Get the model name of the response."""
256
+ raise NotImplementedError ()
257
+
258
+ @property
258
259
@abstractmethod
259
260
def timestamp (self ) -> datetime :
260
261
"""Get the timestamp of the response."""
0 commit comments