mirascope 2.0.1__py3-none-any.whl → 2.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mirascope/_stubs.py +39 -18
- mirascope/_utils.py +34 -0
- mirascope/api/_generated/__init__.py +4 -0
- mirascope/api/_generated/organization_invitations/client.py +2 -2
- mirascope/api/_generated/organization_invitations/raw_client.py +2 -2
- mirascope/api/_generated/project_memberships/__init__.py +4 -0
- mirascope/api/_generated/project_memberships/client.py +91 -0
- mirascope/api/_generated/project_memberships/raw_client.py +239 -0
- mirascope/api/_generated/project_memberships/types/__init__.py +4 -0
- mirascope/api/_generated/project_memberships/types/project_memberships_get_response.py +33 -0
- mirascope/api/_generated/project_memberships/types/project_memberships_get_response_role.py +7 -0
- mirascope/api/_generated/reference.md +73 -1
- mirascope/llm/__init__.py +19 -0
- mirascope/llm/calls/calls.py +28 -21
- mirascope/llm/calls/decorator.py +17 -24
- mirascope/llm/formatting/__init__.py +2 -2
- mirascope/llm/formatting/format.py +2 -4
- mirascope/llm/formatting/types.py +19 -2
- mirascope/llm/models/models.py +66 -146
- mirascope/llm/prompts/decorator.py +5 -16
- mirascope/llm/prompts/prompts.py +35 -38
- mirascope/llm/providers/anthropic/_utils/beta_decode.py +22 -7
- mirascope/llm/providers/anthropic/_utils/beta_encode.py +22 -16
- mirascope/llm/providers/anthropic/_utils/decode.py +45 -7
- mirascope/llm/providers/anthropic/_utils/encode.py +28 -15
- mirascope/llm/providers/anthropic/beta_provider.py +33 -69
- mirascope/llm/providers/anthropic/provider.py +52 -91
- mirascope/llm/providers/base/_utils.py +4 -9
- mirascope/llm/providers/base/base_provider.py +89 -205
- mirascope/llm/providers/google/_utils/decode.py +51 -1
- mirascope/llm/providers/google/_utils/encode.py +38 -21
- mirascope/llm/providers/google/provider.py +33 -69
- mirascope/llm/providers/mirascope/provider.py +25 -61
- mirascope/llm/providers/mlx/encoding/base.py +3 -6
- mirascope/llm/providers/mlx/encoding/transformers.py +4 -8
- mirascope/llm/providers/mlx/mlx.py +9 -21
- mirascope/llm/providers/mlx/provider.py +33 -69
- mirascope/llm/providers/openai/completions/_utils/encode.py +39 -20
- mirascope/llm/providers/openai/completions/base_provider.py +34 -75
- mirascope/llm/providers/openai/provider.py +25 -61
- mirascope/llm/providers/openai/responses/_utils/decode.py +31 -2
- mirascope/llm/providers/openai/responses/_utils/encode.py +32 -17
- mirascope/llm/providers/openai/responses/provider.py +34 -75
- mirascope/llm/responses/__init__.py +2 -1
- mirascope/llm/responses/base_stream_response.py +4 -0
- mirascope/llm/responses/response.py +8 -12
- mirascope/llm/responses/stream_response.py +8 -12
- mirascope/llm/responses/usage.py +44 -0
- mirascope/llm/tools/__init__.py +24 -0
- mirascope/llm/tools/provider_tools.py +18 -0
- mirascope/llm/tools/tool_schema.py +11 -4
- mirascope/llm/tools/toolkit.py +24 -6
- mirascope/llm/tools/types.py +112 -0
- mirascope/llm/tools/web_search_tool.py +32 -0
- mirascope/ops/__init__.py +19 -1
- mirascope/ops/_internal/closure.py +4 -1
- mirascope/ops/_internal/exporters/exporters.py +13 -46
- mirascope/ops/_internal/exporters/utils.py +37 -0
- mirascope/ops/_internal/instrumentation/__init__.py +20 -0
- mirascope/ops/_internal/instrumentation/llm/common.py +19 -49
- mirascope/ops/_internal/instrumentation/llm/model.py +61 -82
- mirascope/ops/_internal/instrumentation/llm/serialize.py +36 -12
- mirascope/ops/_internal/instrumentation/providers/__init__.py +29 -0
- mirascope/ops/_internal/instrumentation/providers/anthropic.py +78 -0
- mirascope/ops/_internal/instrumentation/providers/base.py +179 -0
- mirascope/ops/_internal/instrumentation/providers/google_genai.py +85 -0
- mirascope/ops/_internal/instrumentation/providers/openai.py +82 -0
- mirascope/ops/_internal/traced_calls.py +14 -0
- mirascope/ops/_internal/traced_functions.py +7 -2
- mirascope/ops/_internal/utils.py +12 -4
- mirascope/ops/_internal/versioned_functions.py +1 -1
- {mirascope-2.0.1.dist-info → mirascope-2.1.0.dist-info}/METADATA +96 -68
- {mirascope-2.0.1.dist-info → mirascope-2.1.0.dist-info}/RECORD +75 -64
- {mirascope-2.0.1.dist-info → mirascope-2.1.0.dist-info}/WHEEL +0 -0
- {mirascope-2.0.1.dist-info → mirascope-2.1.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -10,7 +10,7 @@ from typing_extensions import TypeVar, Unpack
|
|
|
10
10
|
|
|
11
11
|
from ...context import Context, DepsT
|
|
12
12
|
from ...exceptions import APIError, ProviderError
|
|
13
|
-
from ...formatting import
|
|
13
|
+
from ...formatting import FormatSpec, FormattableT
|
|
14
14
|
from ...messages import Message, UserContent, user
|
|
15
15
|
from ...responses import (
|
|
16
16
|
AsyncChunkIterator,
|
|
@@ -25,13 +25,9 @@ from ...responses import (
|
|
|
25
25
|
StreamResponse,
|
|
26
26
|
)
|
|
27
27
|
from ...tools import (
|
|
28
|
-
AsyncContextTool,
|
|
29
28
|
AsyncContextToolkit,
|
|
30
|
-
AsyncTool,
|
|
31
29
|
AsyncToolkit,
|
|
32
|
-
ContextTool,
|
|
33
30
|
ContextToolkit,
|
|
34
|
-
Tool,
|
|
35
31
|
Toolkit,
|
|
36
32
|
)
|
|
37
33
|
|
|
@@ -150,7 +146,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
150
146
|
*,
|
|
151
147
|
model_id: str,
|
|
152
148
|
messages: Sequence[Message],
|
|
153
|
-
|
|
149
|
+
toolkit: Toolkit,
|
|
154
150
|
format: None = None,
|
|
155
151
|
**params: Unpack[Params],
|
|
156
152
|
) -> Response:
|
|
@@ -163,8 +159,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
163
159
|
*,
|
|
164
160
|
model_id: str,
|
|
165
161
|
messages: Sequence[Message],
|
|
166
|
-
|
|
167
|
-
format:
|
|
162
|
+
toolkit: Toolkit,
|
|
163
|
+
format: FormatSpec[FormattableT],
|
|
168
164
|
**params: Unpack[Params],
|
|
169
165
|
) -> Response[FormattableT]:
|
|
170
166
|
"""Generate an `llm.Response` with a response format."""
|
|
@@ -176,11 +172,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
176
172
|
*,
|
|
177
173
|
model_id: str,
|
|
178
174
|
messages: Sequence[Message],
|
|
179
|
-
|
|
180
|
-
format:
|
|
181
|
-
| Format[FormattableT]
|
|
182
|
-
| OutputParser[FormattableT]
|
|
183
|
-
| None,
|
|
175
|
+
toolkit: Toolkit,
|
|
176
|
+
format: FormatSpec[FormattableT] | None,
|
|
184
177
|
**params: Unpack[Params],
|
|
185
178
|
) -> Response | Response[FormattableT]:
|
|
186
179
|
"""Generate an `llm.Response` with an optional response format."""
|
|
@@ -191,11 +184,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
191
184
|
*,
|
|
192
185
|
model_id: str,
|
|
193
186
|
messages: Sequence[Message],
|
|
194
|
-
|
|
195
|
-
format:
|
|
196
|
-
| Format[FormattableT]
|
|
197
|
-
| OutputParser[FormattableT]
|
|
198
|
-
| None = None,
|
|
187
|
+
toolkit: Toolkit,
|
|
188
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
199
189
|
**params: Unpack[Params],
|
|
200
190
|
) -> Response | Response[FormattableT]:
|
|
201
191
|
"""Generate an `llm.Response` by synchronously calling this client's LLM provider.
|
|
@@ -214,7 +204,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
214
204
|
return self._call(
|
|
215
205
|
model_id=model_id,
|
|
216
206
|
messages=messages,
|
|
217
|
-
|
|
207
|
+
toolkit=toolkit,
|
|
218
208
|
format=format,
|
|
219
209
|
**params,
|
|
220
210
|
)
|
|
@@ -225,11 +215,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
225
215
|
*,
|
|
226
216
|
model_id: str,
|
|
227
217
|
messages: Sequence[Message],
|
|
228
|
-
|
|
229
|
-
format:
|
|
230
|
-
| Format[FormattableT]
|
|
231
|
-
| OutputParser[FormattableT]
|
|
232
|
-
| None = None,
|
|
218
|
+
toolkit: Toolkit,
|
|
219
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
233
220
|
**params: Unpack[Params],
|
|
234
221
|
) -> Response | Response[FormattableT]:
|
|
235
222
|
"""Implementation for call(). Subclasses override this method."""
|
|
@@ -242,9 +229,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
242
229
|
ctx: Context[DepsT],
|
|
243
230
|
model_id: str,
|
|
244
231
|
messages: Sequence[Message],
|
|
245
|
-
|
|
246
|
-
| ContextToolkit[DepsT]
|
|
247
|
-
| None = None,
|
|
232
|
+
toolkit: ContextToolkit[DepsT],
|
|
248
233
|
format: None = None,
|
|
249
234
|
**params: Unpack[Params],
|
|
250
235
|
) -> ContextResponse[DepsT, None]:
|
|
@@ -258,10 +243,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
258
243
|
ctx: Context[DepsT],
|
|
259
244
|
model_id: str,
|
|
260
245
|
messages: Sequence[Message],
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
| None = None,
|
|
264
|
-
format: type[FormattableT] | Format[FormattableT],
|
|
246
|
+
toolkit: ContextToolkit[DepsT],
|
|
247
|
+
format: FormatSpec[FormattableT],
|
|
265
248
|
**params: Unpack[Params],
|
|
266
249
|
) -> ContextResponse[DepsT, FormattableT]:
|
|
267
250
|
"""Generate an `llm.ContextResponse` with a response format."""
|
|
@@ -274,13 +257,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
274
257
|
ctx: Context[DepsT],
|
|
275
258
|
model_id: str,
|
|
276
259
|
messages: Sequence[Message],
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
| None = None,
|
|
280
|
-
format: type[FormattableT]
|
|
281
|
-
| Format[FormattableT]
|
|
282
|
-
| OutputParser[FormattableT]
|
|
283
|
-
| None,
|
|
260
|
+
toolkit: ContextToolkit[DepsT],
|
|
261
|
+
format: FormatSpec[FormattableT] | None,
|
|
284
262
|
**params: Unpack[Params],
|
|
285
263
|
) -> ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT]:
|
|
286
264
|
"""Generate an `llm.ContextResponse` with an optional response format."""
|
|
@@ -292,13 +270,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
292
270
|
ctx: Context[DepsT],
|
|
293
271
|
model_id: str,
|
|
294
272
|
messages: Sequence[Message],
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
| None = None,
|
|
298
|
-
format: type[FormattableT]
|
|
299
|
-
| Format[FormattableT]
|
|
300
|
-
| OutputParser[FormattableT]
|
|
301
|
-
| None = None,
|
|
273
|
+
toolkit: ContextToolkit[DepsT],
|
|
274
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
302
275
|
**params: Unpack[Params],
|
|
303
276
|
) -> ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT]:
|
|
304
277
|
"""Generate an `llm.ContextResponse` by synchronously calling this client's LLM provider.
|
|
@@ -319,7 +292,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
319
292
|
ctx=ctx,
|
|
320
293
|
model_id=model_id,
|
|
321
294
|
messages=messages,
|
|
322
|
-
|
|
295
|
+
toolkit=toolkit,
|
|
323
296
|
format=format,
|
|
324
297
|
**params,
|
|
325
298
|
)
|
|
@@ -331,13 +304,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
331
304
|
ctx: Context[DepsT],
|
|
332
305
|
model_id: str,
|
|
333
306
|
messages: Sequence[Message],
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
| None = None,
|
|
337
|
-
format: type[FormattableT]
|
|
338
|
-
| Format[FormattableT]
|
|
339
|
-
| OutputParser[FormattableT]
|
|
340
|
-
| None = None,
|
|
307
|
+
toolkit: ContextToolkit[DepsT],
|
|
308
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
341
309
|
**params: Unpack[Params],
|
|
342
310
|
) -> ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT]:
|
|
343
311
|
"""Implementation for context_call(). Subclasses override this method."""
|
|
@@ -349,7 +317,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
349
317
|
*,
|
|
350
318
|
model_id: str,
|
|
351
319
|
messages: Sequence[Message],
|
|
352
|
-
|
|
320
|
+
toolkit: AsyncToolkit,
|
|
353
321
|
format: None = None,
|
|
354
322
|
**params: Unpack[Params],
|
|
355
323
|
) -> AsyncResponse:
|
|
@@ -362,8 +330,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
362
330
|
*,
|
|
363
331
|
model_id: str,
|
|
364
332
|
messages: Sequence[Message],
|
|
365
|
-
|
|
366
|
-
format:
|
|
333
|
+
toolkit: AsyncToolkit,
|
|
334
|
+
format: FormatSpec[FormattableT],
|
|
367
335
|
**params: Unpack[Params],
|
|
368
336
|
) -> AsyncResponse[FormattableT]:
|
|
369
337
|
"""Generate an `llm.AsyncResponse` with a response format."""
|
|
@@ -375,11 +343,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
375
343
|
*,
|
|
376
344
|
model_id: str,
|
|
377
345
|
messages: Sequence[Message],
|
|
378
|
-
|
|
379
|
-
format:
|
|
380
|
-
| Format[FormattableT]
|
|
381
|
-
| OutputParser[FormattableT]
|
|
382
|
-
| None,
|
|
346
|
+
toolkit: AsyncToolkit,
|
|
347
|
+
format: FormatSpec[FormattableT] | None,
|
|
383
348
|
**params: Unpack[Params],
|
|
384
349
|
) -> AsyncResponse | AsyncResponse[FormattableT]:
|
|
385
350
|
"""Generate an `llm.AsyncResponse` with an optional response format."""
|
|
@@ -390,11 +355,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
390
355
|
*,
|
|
391
356
|
model_id: str,
|
|
392
357
|
messages: Sequence[Message],
|
|
393
|
-
|
|
394
|
-
format:
|
|
395
|
-
| Format[FormattableT]
|
|
396
|
-
| OutputParser[FormattableT]
|
|
397
|
-
| None = None,
|
|
358
|
+
toolkit: AsyncToolkit,
|
|
359
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
398
360
|
**params: Unpack[Params],
|
|
399
361
|
) -> AsyncResponse | AsyncResponse[FormattableT]:
|
|
400
362
|
"""Generate an `llm.AsyncResponse` by asynchronously calling this client's LLM provider.
|
|
@@ -413,7 +375,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
413
375
|
return await self._call_async(
|
|
414
376
|
model_id=model_id,
|
|
415
377
|
messages=messages,
|
|
416
|
-
|
|
378
|
+
toolkit=toolkit,
|
|
417
379
|
format=format,
|
|
418
380
|
**params,
|
|
419
381
|
)
|
|
@@ -424,11 +386,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
424
386
|
*,
|
|
425
387
|
model_id: str,
|
|
426
388
|
messages: Sequence[Message],
|
|
427
|
-
|
|
428
|
-
format:
|
|
429
|
-
| Format[FormattableT]
|
|
430
|
-
| OutputParser[FormattableT]
|
|
431
|
-
| None = None,
|
|
389
|
+
toolkit: AsyncToolkit,
|
|
390
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
432
391
|
**params: Unpack[Params],
|
|
433
392
|
) -> AsyncResponse | AsyncResponse[FormattableT]:
|
|
434
393
|
"""Implementation for call_async(). Subclasses override this method."""
|
|
@@ -441,9 +400,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
441
400
|
ctx: Context[DepsT],
|
|
442
401
|
model_id: str,
|
|
443
402
|
messages: Sequence[Message],
|
|
444
|
-
|
|
445
|
-
| AsyncContextToolkit[DepsT]
|
|
446
|
-
| None = None,
|
|
403
|
+
toolkit: AsyncContextToolkit[DepsT],
|
|
447
404
|
format: None = None,
|
|
448
405
|
**params: Unpack[Params],
|
|
449
406
|
) -> AsyncContextResponse[DepsT, None]:
|
|
@@ -457,10 +414,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
457
414
|
ctx: Context[DepsT],
|
|
458
415
|
model_id: str,
|
|
459
416
|
messages: Sequence[Message],
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
| None = None,
|
|
463
|
-
format: type[FormattableT] | Format[FormattableT],
|
|
417
|
+
toolkit: AsyncContextToolkit[DepsT],
|
|
418
|
+
format: FormatSpec[FormattableT],
|
|
464
419
|
**params: Unpack[Params],
|
|
465
420
|
) -> AsyncContextResponse[DepsT, FormattableT]:
|
|
466
421
|
"""Generate an `llm.AsyncContextResponse` with a response format."""
|
|
@@ -473,13 +428,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
473
428
|
ctx: Context[DepsT],
|
|
474
429
|
model_id: str,
|
|
475
430
|
messages: Sequence[Message],
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
| None = None,
|
|
479
|
-
format: type[FormattableT]
|
|
480
|
-
| Format[FormattableT]
|
|
481
|
-
| OutputParser[FormattableT]
|
|
482
|
-
| None,
|
|
431
|
+
toolkit: AsyncContextToolkit[DepsT],
|
|
432
|
+
format: FormatSpec[FormattableT] | None,
|
|
483
433
|
**params: Unpack[Params],
|
|
484
434
|
) -> AsyncContextResponse[DepsT, None] | AsyncContextResponse[DepsT, FormattableT]:
|
|
485
435
|
"""Generate an `llm.AsyncContextResponse` with an optional response format."""
|
|
@@ -491,13 +441,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
491
441
|
ctx: Context[DepsT],
|
|
492
442
|
model_id: str,
|
|
493
443
|
messages: Sequence[Message],
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
| None = None,
|
|
497
|
-
format: type[FormattableT]
|
|
498
|
-
| Format[FormattableT]
|
|
499
|
-
| OutputParser[FormattableT]
|
|
500
|
-
| None = None,
|
|
444
|
+
toolkit: AsyncContextToolkit[DepsT],
|
|
445
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
501
446
|
**params: Unpack[Params],
|
|
502
447
|
) -> AsyncContextResponse[DepsT, None] | AsyncContextResponse[DepsT, FormattableT]:
|
|
503
448
|
"""Generate an `llm.AsyncContextResponse` by asynchronously calling this client's LLM provider.
|
|
@@ -518,7 +463,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
518
463
|
ctx=ctx,
|
|
519
464
|
model_id=model_id,
|
|
520
465
|
messages=messages,
|
|
521
|
-
|
|
466
|
+
toolkit=toolkit,
|
|
522
467
|
format=format,
|
|
523
468
|
**params,
|
|
524
469
|
)
|
|
@@ -530,13 +475,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
530
475
|
ctx: Context[DepsT],
|
|
531
476
|
model_id: str,
|
|
532
477
|
messages: Sequence[Message],
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
| None = None,
|
|
536
|
-
format: type[FormattableT]
|
|
537
|
-
| Format[FormattableT]
|
|
538
|
-
| OutputParser[FormattableT]
|
|
539
|
-
| None = None,
|
|
478
|
+
toolkit: AsyncContextToolkit[DepsT],
|
|
479
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
540
480
|
**params: Unpack[Params],
|
|
541
481
|
) -> AsyncContextResponse[DepsT, None] | AsyncContextResponse[DepsT, FormattableT]:
|
|
542
482
|
"""Implementation for context_call_async(). Subclasses override this method."""
|
|
@@ -548,7 +488,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
548
488
|
*,
|
|
549
489
|
model_id: str,
|
|
550
490
|
messages: Sequence[Message],
|
|
551
|
-
|
|
491
|
+
toolkit: Toolkit,
|
|
552
492
|
format: None = None,
|
|
553
493
|
**params: Unpack[Params],
|
|
554
494
|
) -> StreamResponse:
|
|
@@ -561,8 +501,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
561
501
|
*,
|
|
562
502
|
model_id: str,
|
|
563
503
|
messages: Sequence[Message],
|
|
564
|
-
|
|
565
|
-
format:
|
|
504
|
+
toolkit: Toolkit,
|
|
505
|
+
format: FormatSpec[FormattableT],
|
|
566
506
|
**params: Unpack[Params],
|
|
567
507
|
) -> StreamResponse[FormattableT]:
|
|
568
508
|
"""Stream an `llm.StreamResponse` with a response format."""
|
|
@@ -574,11 +514,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
574
514
|
*,
|
|
575
515
|
model_id: str,
|
|
576
516
|
messages: Sequence[Message],
|
|
577
|
-
|
|
578
|
-
format:
|
|
579
|
-
| Format[FormattableT]
|
|
580
|
-
| OutputParser[FormattableT]
|
|
581
|
-
| None,
|
|
517
|
+
toolkit: Toolkit,
|
|
518
|
+
format: FormatSpec[FormattableT] | None,
|
|
582
519
|
**params: Unpack[Params],
|
|
583
520
|
) -> StreamResponse | StreamResponse[FormattableT]:
|
|
584
521
|
"""Stream an `llm.StreamResponse` with an optional response format."""
|
|
@@ -589,11 +526,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
589
526
|
*,
|
|
590
527
|
model_id: str,
|
|
591
528
|
messages: Sequence[Message],
|
|
592
|
-
|
|
593
|
-
format:
|
|
594
|
-
| Format[FormattableT]
|
|
595
|
-
| OutputParser[FormattableT]
|
|
596
|
-
| None = None,
|
|
529
|
+
toolkit: Toolkit,
|
|
530
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
597
531
|
**params: Unpack[Params],
|
|
598
532
|
) -> StreamResponse | StreamResponse[FormattableT]:
|
|
599
533
|
"""Generate an `llm.StreamResponse` by synchronously streaming from this client's LLM provider.
|
|
@@ -612,7 +546,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
612
546
|
stream_response = self._stream(
|
|
613
547
|
model_id=model_id,
|
|
614
548
|
messages=messages,
|
|
615
|
-
|
|
549
|
+
toolkit=toolkit,
|
|
616
550
|
format=format,
|
|
617
551
|
**params,
|
|
618
552
|
)
|
|
@@ -627,11 +561,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
627
561
|
*,
|
|
628
562
|
model_id: str,
|
|
629
563
|
messages: Sequence[Message],
|
|
630
|
-
|
|
631
|
-
format:
|
|
632
|
-
| Format[FormattableT]
|
|
633
|
-
| OutputParser[FormattableT]
|
|
634
|
-
| None = None,
|
|
564
|
+
toolkit: Toolkit,
|
|
565
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
635
566
|
**params: Unpack[Params],
|
|
636
567
|
) -> StreamResponse | StreamResponse[FormattableT]:
|
|
637
568
|
"""Implementation for stream(). Subclasses override this method."""
|
|
@@ -644,9 +575,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
644
575
|
ctx: Context[DepsT],
|
|
645
576
|
model_id: str,
|
|
646
577
|
messages: Sequence[Message],
|
|
647
|
-
|
|
648
|
-
| ContextToolkit[DepsT]
|
|
649
|
-
| None = None,
|
|
578
|
+
toolkit: ContextToolkit[DepsT],
|
|
650
579
|
format: None = None,
|
|
651
580
|
**params: Unpack[Params],
|
|
652
581
|
) -> ContextStreamResponse[DepsT, None]:
|
|
@@ -660,10 +589,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
660
589
|
ctx: Context[DepsT],
|
|
661
590
|
model_id: str,
|
|
662
591
|
messages: Sequence[Message],
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
| None = None,
|
|
666
|
-
format: type[FormattableT] | Format[FormattableT],
|
|
592
|
+
toolkit: ContextToolkit[DepsT],
|
|
593
|
+
format: FormatSpec[FormattableT],
|
|
667
594
|
**params: Unpack[Params],
|
|
668
595
|
) -> ContextStreamResponse[DepsT, FormattableT]:
|
|
669
596
|
"""Stream an `llm.ContextStreamResponse` with a response format."""
|
|
@@ -676,13 +603,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
676
603
|
ctx: Context[DepsT],
|
|
677
604
|
model_id: str,
|
|
678
605
|
messages: Sequence[Message],
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
| None = None,
|
|
682
|
-
format: type[FormattableT]
|
|
683
|
-
| Format[FormattableT]
|
|
684
|
-
| OutputParser[FormattableT]
|
|
685
|
-
| None,
|
|
606
|
+
toolkit: ContextToolkit[DepsT],
|
|
607
|
+
format: FormatSpec[FormattableT] | None,
|
|
686
608
|
**params: Unpack[Params],
|
|
687
609
|
) -> (
|
|
688
610
|
ContextStreamResponse[DepsT, None] | ContextStreamResponse[DepsT, FormattableT]
|
|
@@ -696,13 +618,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
696
618
|
ctx: Context[DepsT],
|
|
697
619
|
model_id: str,
|
|
698
620
|
messages: Sequence[Message],
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
| None = None,
|
|
702
|
-
format: type[FormattableT]
|
|
703
|
-
| Format[FormattableT]
|
|
704
|
-
| OutputParser[FormattableT]
|
|
705
|
-
| None = None,
|
|
621
|
+
toolkit: ContextToolkit[DepsT],
|
|
622
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
706
623
|
**params: Unpack[Params],
|
|
707
624
|
) -> (
|
|
708
625
|
ContextStreamResponse[DepsT, None] | ContextStreamResponse[DepsT, FormattableT]
|
|
@@ -725,7 +642,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
725
642
|
ctx=ctx,
|
|
726
643
|
model_id=model_id,
|
|
727
644
|
messages=messages,
|
|
728
|
-
|
|
645
|
+
toolkit=toolkit,
|
|
729
646
|
format=format,
|
|
730
647
|
**params,
|
|
731
648
|
)
|
|
@@ -741,13 +658,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
741
658
|
ctx: Context[DepsT],
|
|
742
659
|
model_id: str,
|
|
743
660
|
messages: Sequence[Message],
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
| None = None,
|
|
747
|
-
format: type[FormattableT]
|
|
748
|
-
| Format[FormattableT]
|
|
749
|
-
| OutputParser[FormattableT]
|
|
750
|
-
| None = None,
|
|
661
|
+
toolkit: ContextToolkit[DepsT],
|
|
662
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
751
663
|
**params: Unpack[Params],
|
|
752
664
|
) -> (
|
|
753
665
|
ContextStreamResponse[DepsT, None] | ContextStreamResponse[DepsT, FormattableT]
|
|
@@ -761,7 +673,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
761
673
|
*,
|
|
762
674
|
model_id: str,
|
|
763
675
|
messages: Sequence[Message],
|
|
764
|
-
|
|
676
|
+
toolkit: AsyncToolkit,
|
|
765
677
|
format: None = None,
|
|
766
678
|
**params: Unpack[Params],
|
|
767
679
|
) -> AsyncStreamResponse:
|
|
@@ -774,8 +686,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
774
686
|
*,
|
|
775
687
|
model_id: str,
|
|
776
688
|
messages: Sequence[Message],
|
|
777
|
-
|
|
778
|
-
format:
|
|
689
|
+
toolkit: AsyncToolkit,
|
|
690
|
+
format: FormatSpec[FormattableT],
|
|
779
691
|
**params: Unpack[Params],
|
|
780
692
|
) -> AsyncStreamResponse[FormattableT]:
|
|
781
693
|
"""Stream an `llm.AsyncStreamResponse` with a response format."""
|
|
@@ -787,11 +699,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
787
699
|
*,
|
|
788
700
|
model_id: str,
|
|
789
701
|
messages: Sequence[Message],
|
|
790
|
-
|
|
791
|
-
format:
|
|
792
|
-
| Format[FormattableT]
|
|
793
|
-
| OutputParser[FormattableT]
|
|
794
|
-
| None,
|
|
702
|
+
toolkit: AsyncToolkit,
|
|
703
|
+
format: FormatSpec[FormattableT] | None,
|
|
795
704
|
**params: Unpack[Params],
|
|
796
705
|
) -> AsyncStreamResponse | AsyncStreamResponse[FormattableT]:
|
|
797
706
|
"""Stream an `llm.AsyncStreamResponse` with an optional response format."""
|
|
@@ -802,11 +711,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
802
711
|
*,
|
|
803
712
|
model_id: str,
|
|
804
713
|
messages: Sequence[Message],
|
|
805
|
-
|
|
806
|
-
format:
|
|
807
|
-
| Format[FormattableT]
|
|
808
|
-
| OutputParser[FormattableT]
|
|
809
|
-
| None = None,
|
|
714
|
+
toolkit: AsyncToolkit,
|
|
715
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
810
716
|
**params: Unpack[Params],
|
|
811
717
|
) -> AsyncStreamResponse | AsyncStreamResponse[FormattableT]:
|
|
812
718
|
"""Generate an `llm.AsyncStreamResponse` by asynchronously streaming from this client's LLM provider.
|
|
@@ -825,7 +731,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
825
731
|
stream_response = await self._stream_async(
|
|
826
732
|
model_id=model_id,
|
|
827
733
|
messages=messages,
|
|
828
|
-
|
|
734
|
+
toolkit=toolkit,
|
|
829
735
|
format=format,
|
|
830
736
|
**params,
|
|
831
737
|
)
|
|
@@ -840,11 +746,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
840
746
|
*,
|
|
841
747
|
model_id: str,
|
|
842
748
|
messages: Sequence[Message],
|
|
843
|
-
|
|
844
|
-
format:
|
|
845
|
-
| Format[FormattableT]
|
|
846
|
-
| OutputParser[FormattableT]
|
|
847
|
-
| None = None,
|
|
749
|
+
toolkit: AsyncToolkit,
|
|
750
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
848
751
|
**params: Unpack[Params],
|
|
849
752
|
) -> AsyncStreamResponse | AsyncStreamResponse[FormattableT]:
|
|
850
753
|
"""Implementation for stream_async(). Subclasses override this method."""
|
|
@@ -857,9 +760,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
857
760
|
ctx: Context[DepsT],
|
|
858
761
|
model_id: str,
|
|
859
762
|
messages: Sequence[Message],
|
|
860
|
-
|
|
861
|
-
| AsyncContextToolkit[DepsT]
|
|
862
|
-
| None = None,
|
|
763
|
+
toolkit: AsyncContextToolkit[DepsT],
|
|
863
764
|
format: None = None,
|
|
864
765
|
**params: Unpack[Params],
|
|
865
766
|
) -> AsyncContextStreamResponse[DepsT, None]:
|
|
@@ -873,10 +774,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
873
774
|
ctx: Context[DepsT],
|
|
874
775
|
model_id: str,
|
|
875
776
|
messages: Sequence[Message],
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
| None = None,
|
|
879
|
-
format: type[FormattableT] | Format[FormattableT],
|
|
777
|
+
toolkit: AsyncContextToolkit[DepsT],
|
|
778
|
+
format: FormatSpec[FormattableT],
|
|
880
779
|
**params: Unpack[Params],
|
|
881
780
|
) -> AsyncContextStreamResponse[DepsT, FormattableT]:
|
|
882
781
|
"""Stream an `llm.AsyncContextStreamResponse` with a response format."""
|
|
@@ -889,13 +788,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
889
788
|
ctx: Context[DepsT],
|
|
890
789
|
model_id: str,
|
|
891
790
|
messages: Sequence[Message],
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
| None = None,
|
|
895
|
-
format: type[FormattableT]
|
|
896
|
-
| Format[FormattableT]
|
|
897
|
-
| OutputParser[FormattableT]
|
|
898
|
-
| None,
|
|
791
|
+
toolkit: AsyncContextToolkit[DepsT],
|
|
792
|
+
format: FormatSpec[FormattableT] | None,
|
|
899
793
|
**params: Unpack[Params],
|
|
900
794
|
) -> (
|
|
901
795
|
AsyncContextStreamResponse[DepsT, None]
|
|
@@ -910,13 +804,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
910
804
|
ctx: Context[DepsT],
|
|
911
805
|
model_id: str,
|
|
912
806
|
messages: Sequence[Message],
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
| None = None,
|
|
916
|
-
format: type[FormattableT]
|
|
917
|
-
| Format[FormattableT]
|
|
918
|
-
| OutputParser[FormattableT]
|
|
919
|
-
| None = None,
|
|
807
|
+
toolkit: AsyncContextToolkit[DepsT],
|
|
808
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
920
809
|
**params: Unpack[Params],
|
|
921
810
|
) -> (
|
|
922
811
|
AsyncContextStreamResponse[DepsT, None]
|
|
@@ -940,7 +829,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
940
829
|
ctx=ctx,
|
|
941
830
|
model_id=model_id,
|
|
942
831
|
messages=messages,
|
|
943
|
-
|
|
832
|
+
toolkit=toolkit,
|
|
944
833
|
format=format,
|
|
945
834
|
**params,
|
|
946
835
|
)
|
|
@@ -956,13 +845,8 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
956
845
|
ctx: Context[DepsT],
|
|
957
846
|
model_id: str,
|
|
958
847
|
messages: Sequence[Message],
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
| None = None,
|
|
962
|
-
format: type[FormattableT]
|
|
963
|
-
| Format[FormattableT]
|
|
964
|
-
| OutputParser[FormattableT]
|
|
965
|
-
| None = None,
|
|
848
|
+
toolkit: AsyncContextToolkit[DepsT],
|
|
849
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
966
850
|
**params: Unpack[Params],
|
|
967
851
|
) -> (
|
|
968
852
|
AsyncContextStreamResponse[DepsT, None]
|
|
@@ -1035,7 +919,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1035
919
|
return self.call(
|
|
1036
920
|
model_id=model_id,
|
|
1037
921
|
messages=messages,
|
|
1038
|
-
|
|
922
|
+
toolkit=response.toolkit,
|
|
1039
923
|
format=response.format,
|
|
1040
924
|
**params,
|
|
1041
925
|
)
|
|
@@ -1104,7 +988,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1104
988
|
return await self.call_async(
|
|
1105
989
|
model_id=model_id,
|
|
1106
990
|
messages=messages,
|
|
1107
|
-
|
|
991
|
+
toolkit=response.toolkit,
|
|
1108
992
|
format=response.format,
|
|
1109
993
|
**params,
|
|
1110
994
|
)
|
|
@@ -1179,7 +1063,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1179
1063
|
ctx=ctx,
|
|
1180
1064
|
model_id=model_id,
|
|
1181
1065
|
messages=messages,
|
|
1182
|
-
|
|
1066
|
+
toolkit=response.toolkit,
|
|
1183
1067
|
format=response.format,
|
|
1184
1068
|
**params,
|
|
1185
1069
|
)
|
|
@@ -1256,7 +1140,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1256
1140
|
ctx=ctx,
|
|
1257
1141
|
model_id=model_id,
|
|
1258
1142
|
messages=messages,
|
|
1259
|
-
|
|
1143
|
+
toolkit=response.toolkit,
|
|
1260
1144
|
format=response.format,
|
|
1261
1145
|
**params,
|
|
1262
1146
|
)
|
|
@@ -1325,7 +1209,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1325
1209
|
return self.stream(
|
|
1326
1210
|
model_id=model_id,
|
|
1327
1211
|
messages=messages,
|
|
1328
|
-
|
|
1212
|
+
toolkit=response.toolkit,
|
|
1329
1213
|
format=response.format,
|
|
1330
1214
|
**params,
|
|
1331
1215
|
)
|
|
@@ -1394,7 +1278,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1394
1278
|
return await self.stream_async(
|
|
1395
1279
|
model_id=model_id,
|
|
1396
1280
|
messages=messages,
|
|
1397
|
-
|
|
1281
|
+
toolkit=response.toolkit,
|
|
1398
1282
|
format=response.format,
|
|
1399
1283
|
**params,
|
|
1400
1284
|
)
|
|
@@ -1475,7 +1359,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1475
1359
|
ctx=ctx,
|
|
1476
1360
|
model_id=model_id,
|
|
1477
1361
|
messages=messages,
|
|
1478
|
-
|
|
1362
|
+
toolkit=response.toolkit,
|
|
1479
1363
|
format=response.format,
|
|
1480
1364
|
**params,
|
|
1481
1365
|
)
|
|
@@ -1558,7 +1442,7 @@ class BaseProvider(Generic[ProviderClientT], ABC):
|
|
|
1558
1442
|
ctx=ctx,
|
|
1559
1443
|
model_id=model_id,
|
|
1560
1444
|
messages=messages,
|
|
1561
|
-
|
|
1445
|
+
toolkit=response.toolkit,
|
|
1562
1446
|
format=response.format,
|
|
1563
1447
|
**params,
|
|
1564
1448
|
)
|