mirascope 2.0.2__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/api/_generated/__init__.py +4 -0
- 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 +72 -0
- mirascope/llm/__init__.py +19 -0
- 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 +5 -13
- 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 +4 -2
- 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/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-2.0.2.dist-info → mirascope-2.1.0.dist-info}/METADATA +96 -68
- {mirascope-2.0.2.dist-info → mirascope-2.1.0.dist-info}/RECORD +64 -54
- {mirascope-2.0.2.dist-info → mirascope-2.1.0.dist-info}/WHEEL +0 -0
- {mirascope-2.0.2.dist-info → mirascope-2.1.0.dist-info}/licenses/LICENSE +0 -0
mirascope/llm/models/models.py
CHANGED
|
@@ -9,7 +9,7 @@ from typing import overload
|
|
|
9
9
|
from typing_extensions import Unpack
|
|
10
10
|
|
|
11
11
|
from ..context import Context, DepsT
|
|
12
|
-
from ..formatting import Format,
|
|
12
|
+
from ..formatting import Format, FormatSpec, FormattableT
|
|
13
13
|
from ..messages import Message, UserContent, promote_to_messages
|
|
14
14
|
from ..providers import (
|
|
15
15
|
ModelId,
|
|
@@ -28,14 +28,14 @@ from ..responses import (
|
|
|
28
28
|
StreamResponse,
|
|
29
29
|
)
|
|
30
30
|
from ..tools import (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
AsyncContextTools,
|
|
32
|
+
AsyncTools,
|
|
33
|
+
ContextTools,
|
|
34
|
+
Tools,
|
|
35
|
+
normalize_async_context_tools,
|
|
36
|
+
normalize_async_tools,
|
|
37
|
+
normalize_context_tools,
|
|
38
|
+
normalize_tools,
|
|
39
39
|
)
|
|
40
40
|
from .params import Params
|
|
41
41
|
|
|
@@ -156,7 +156,7 @@ class Model:
|
|
|
156
156
|
self,
|
|
157
157
|
content: UserContent | Sequence[Message],
|
|
158
158
|
*,
|
|
159
|
-
tools:
|
|
159
|
+
tools: Tools | None = None,
|
|
160
160
|
format: None = None,
|
|
161
161
|
) -> Response:
|
|
162
162
|
"""Generate an `llm.Response` without a response format."""
|
|
@@ -167,7 +167,7 @@ class Model:
|
|
|
167
167
|
self,
|
|
168
168
|
content: UserContent | Sequence[Message],
|
|
169
169
|
*,
|
|
170
|
-
tools:
|
|
170
|
+
tools: Tools | None = None,
|
|
171
171
|
format: type[FormattableT] | Format[FormattableT],
|
|
172
172
|
) -> Response[FormattableT]:
|
|
173
173
|
"""Generate an `llm.Response` with a response format."""
|
|
@@ -178,11 +178,8 @@ class Model:
|
|
|
178
178
|
self,
|
|
179
179
|
content: UserContent | Sequence[Message],
|
|
180
180
|
*,
|
|
181
|
-
tools:
|
|
182
|
-
format:
|
|
183
|
-
| Format[FormattableT]
|
|
184
|
-
| OutputParser[FormattableT]
|
|
185
|
-
| None,
|
|
181
|
+
tools: Tools | None = None,
|
|
182
|
+
format: FormatSpec[FormattableT] | None,
|
|
186
183
|
) -> Response | Response[FormattableT]:
|
|
187
184
|
"""Generate an `llm.Response` with an optional response format."""
|
|
188
185
|
...
|
|
@@ -191,11 +188,8 @@ class Model:
|
|
|
191
188
|
self,
|
|
192
189
|
content: UserContent | Sequence[Message],
|
|
193
190
|
*,
|
|
194
|
-
tools:
|
|
195
|
-
format:
|
|
196
|
-
| Format[FormattableT]
|
|
197
|
-
| OutputParser[FormattableT]
|
|
198
|
-
| None = None,
|
|
191
|
+
tools: Tools | None = None,
|
|
192
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
199
193
|
) -> Response | Response[FormattableT]:
|
|
200
194
|
"""Generate an `llm.Response` by synchronously calling this model's LLM provider.
|
|
201
195
|
|
|
@@ -213,7 +207,7 @@ class Model:
|
|
|
213
207
|
return self.provider.call(
|
|
214
208
|
model_id=self.model_id,
|
|
215
209
|
messages=messages,
|
|
216
|
-
|
|
210
|
+
toolkit=normalize_tools(tools),
|
|
217
211
|
format=format,
|
|
218
212
|
**self.params,
|
|
219
213
|
)
|
|
@@ -223,7 +217,7 @@ class Model:
|
|
|
223
217
|
self,
|
|
224
218
|
content: UserContent | Sequence[Message],
|
|
225
219
|
*,
|
|
226
|
-
tools:
|
|
220
|
+
tools: AsyncTools | None = None,
|
|
227
221
|
format: None = None,
|
|
228
222
|
) -> AsyncResponse:
|
|
229
223
|
"""Generate an `llm.AsyncResponse` without a response format."""
|
|
@@ -234,7 +228,7 @@ class Model:
|
|
|
234
228
|
self,
|
|
235
229
|
content: UserContent | Sequence[Message],
|
|
236
230
|
*,
|
|
237
|
-
tools:
|
|
231
|
+
tools: AsyncTools | None = None,
|
|
238
232
|
format: type[FormattableT] | Format[FormattableT],
|
|
239
233
|
) -> AsyncResponse[FormattableT]:
|
|
240
234
|
"""Generate an `llm.AsyncResponse` with a response format."""
|
|
@@ -245,11 +239,8 @@ class Model:
|
|
|
245
239
|
self,
|
|
246
240
|
content: UserContent | Sequence[Message],
|
|
247
241
|
*,
|
|
248
|
-
tools:
|
|
249
|
-
format:
|
|
250
|
-
| Format[FormattableT]
|
|
251
|
-
| OutputParser[FormattableT]
|
|
252
|
-
| None,
|
|
242
|
+
tools: AsyncTools | None = None,
|
|
243
|
+
format: FormatSpec[FormattableT] | None,
|
|
253
244
|
) -> AsyncResponse | AsyncResponse[FormattableT]:
|
|
254
245
|
"""Generate an `llm.AsyncResponse` with an optional response format."""
|
|
255
246
|
...
|
|
@@ -258,11 +249,8 @@ class Model:
|
|
|
258
249
|
self,
|
|
259
250
|
content: UserContent | Sequence[Message],
|
|
260
251
|
*,
|
|
261
|
-
tools:
|
|
262
|
-
format:
|
|
263
|
-
| Format[FormattableT]
|
|
264
|
-
| OutputParser[FormattableT]
|
|
265
|
-
| None = None,
|
|
252
|
+
tools: AsyncTools | None = None,
|
|
253
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
266
254
|
) -> AsyncResponse | AsyncResponse[FormattableT]:
|
|
267
255
|
"""Generate an `llm.AsyncResponse` by asynchronously calling this model's LLM provider.
|
|
268
256
|
|
|
@@ -280,9 +268,9 @@ class Model:
|
|
|
280
268
|
return await self.provider.call_async(
|
|
281
269
|
model_id=self.model_id,
|
|
282
270
|
messages=messages,
|
|
283
|
-
|
|
284
|
-
**self.params,
|
|
271
|
+
toolkit=normalize_async_tools(tools),
|
|
285
272
|
format=format,
|
|
273
|
+
**self.params,
|
|
286
274
|
)
|
|
287
275
|
|
|
288
276
|
@overload
|
|
@@ -290,7 +278,7 @@ class Model:
|
|
|
290
278
|
self,
|
|
291
279
|
content: UserContent | Sequence[Message],
|
|
292
280
|
*,
|
|
293
|
-
tools:
|
|
281
|
+
tools: Tools | None = None,
|
|
294
282
|
format: None = None,
|
|
295
283
|
) -> StreamResponse:
|
|
296
284
|
"""Stream an `llm.StreamResponse` without a response format."""
|
|
@@ -301,7 +289,7 @@ class Model:
|
|
|
301
289
|
self,
|
|
302
290
|
content: UserContent | Sequence[Message],
|
|
303
291
|
*,
|
|
304
|
-
tools:
|
|
292
|
+
tools: Tools | None = None,
|
|
305
293
|
format: type[FormattableT] | Format[FormattableT],
|
|
306
294
|
) -> StreamResponse[FormattableT]:
|
|
307
295
|
"""Stream an `llm.StreamResponse` with a response format."""
|
|
@@ -312,11 +300,8 @@ class Model:
|
|
|
312
300
|
self,
|
|
313
301
|
content: UserContent | Sequence[Message],
|
|
314
302
|
*,
|
|
315
|
-
tools:
|
|
316
|
-
format:
|
|
317
|
-
| Format[FormattableT]
|
|
318
|
-
| OutputParser[FormattableT]
|
|
319
|
-
| None,
|
|
303
|
+
tools: Tools | None = None,
|
|
304
|
+
format: FormatSpec[FormattableT] | None,
|
|
320
305
|
) -> StreamResponse | StreamResponse[FormattableT]:
|
|
321
306
|
"""Stream an `llm.StreamResponse` with an optional response format."""
|
|
322
307
|
...
|
|
@@ -325,11 +310,8 @@ class Model:
|
|
|
325
310
|
self,
|
|
326
311
|
content: UserContent | Sequence[Message],
|
|
327
312
|
*,
|
|
328
|
-
tools:
|
|
329
|
-
format:
|
|
330
|
-
| Format[FormattableT]
|
|
331
|
-
| OutputParser[FormattableT]
|
|
332
|
-
| None = None,
|
|
313
|
+
tools: Tools | None = None,
|
|
314
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
333
315
|
) -> StreamResponse | StreamResponse[FormattableT]:
|
|
334
316
|
"""Generate an `llm.StreamResponse` by synchronously streaming from this model's LLM provider.
|
|
335
317
|
|
|
@@ -347,7 +329,7 @@ class Model:
|
|
|
347
329
|
return self.provider.stream(
|
|
348
330
|
model_id=self.model_id,
|
|
349
331
|
messages=messages,
|
|
350
|
-
|
|
332
|
+
toolkit=normalize_tools(tools),
|
|
351
333
|
format=format,
|
|
352
334
|
**self.params,
|
|
353
335
|
)
|
|
@@ -357,7 +339,7 @@ class Model:
|
|
|
357
339
|
self,
|
|
358
340
|
content: UserContent | Sequence[Message],
|
|
359
341
|
*,
|
|
360
|
-
tools:
|
|
342
|
+
tools: AsyncTools | None = None,
|
|
361
343
|
format: None = None,
|
|
362
344
|
) -> AsyncStreamResponse:
|
|
363
345
|
"""Stream an `llm.AsyncStreamResponse` without a response format."""
|
|
@@ -368,7 +350,7 @@ class Model:
|
|
|
368
350
|
self,
|
|
369
351
|
content: UserContent | Sequence[Message],
|
|
370
352
|
*,
|
|
371
|
-
tools:
|
|
353
|
+
tools: AsyncTools | None = None,
|
|
372
354
|
format: type[FormattableT] | Format[FormattableT],
|
|
373
355
|
) -> AsyncStreamResponse[FormattableT]:
|
|
374
356
|
"""Stream an `llm.AsyncStreamResponse` with a response format."""
|
|
@@ -379,11 +361,8 @@ class Model:
|
|
|
379
361
|
self,
|
|
380
362
|
content: UserContent | Sequence[Message],
|
|
381
363
|
*,
|
|
382
|
-
tools:
|
|
383
|
-
format:
|
|
384
|
-
| Format[FormattableT]
|
|
385
|
-
| OutputParser[FormattableT]
|
|
386
|
-
| None,
|
|
364
|
+
tools: AsyncTools | None = None,
|
|
365
|
+
format: FormatSpec[FormattableT] | None,
|
|
387
366
|
) -> AsyncStreamResponse | AsyncStreamResponse[FormattableT]:
|
|
388
367
|
"""Stream an `llm.AsyncStreamResponse` with an optional response format."""
|
|
389
368
|
...
|
|
@@ -392,11 +371,8 @@ class Model:
|
|
|
392
371
|
self,
|
|
393
372
|
content: UserContent | Sequence[Message],
|
|
394
373
|
*,
|
|
395
|
-
tools:
|
|
396
|
-
format:
|
|
397
|
-
| Format[FormattableT]
|
|
398
|
-
| OutputParser[FormattableT]
|
|
399
|
-
| None = None,
|
|
374
|
+
tools: AsyncTools | None = None,
|
|
375
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
400
376
|
) -> AsyncStreamResponse | AsyncStreamResponse[FormattableT]:
|
|
401
377
|
"""Generate an `llm.AsyncStreamResponse` by asynchronously streaming from this model's LLM provider.
|
|
402
378
|
|
|
@@ -414,7 +390,7 @@ class Model:
|
|
|
414
390
|
return await self.provider.stream_async(
|
|
415
391
|
model_id=self.model_id,
|
|
416
392
|
messages=messages,
|
|
417
|
-
|
|
393
|
+
toolkit=normalize_async_tools(tools),
|
|
418
394
|
format=format,
|
|
419
395
|
**self.params,
|
|
420
396
|
)
|
|
@@ -425,9 +401,7 @@ class Model:
|
|
|
425
401
|
content: UserContent | Sequence[Message],
|
|
426
402
|
*,
|
|
427
403
|
ctx: Context[DepsT],
|
|
428
|
-
tools:
|
|
429
|
-
| ContextToolkit[DepsT]
|
|
430
|
-
| None = None,
|
|
404
|
+
tools: ContextTools[DepsT] | None = None,
|
|
431
405
|
format: None = None,
|
|
432
406
|
) -> ContextResponse[DepsT, None]:
|
|
433
407
|
"""Generate an `llm.ContextResponse` without a response format."""
|
|
@@ -439,9 +413,7 @@ class Model:
|
|
|
439
413
|
content: UserContent | Sequence[Message],
|
|
440
414
|
*,
|
|
441
415
|
ctx: Context[DepsT],
|
|
442
|
-
tools:
|
|
443
|
-
| ContextToolkit[DepsT]
|
|
444
|
-
| None = None,
|
|
416
|
+
tools: ContextTools[DepsT] | None = None,
|
|
445
417
|
format: type[FormattableT] | Format[FormattableT],
|
|
446
418
|
) -> ContextResponse[DepsT, FormattableT]:
|
|
447
419
|
"""Generate an `llm.ContextResponse` with a response format."""
|
|
@@ -453,13 +425,8 @@ class Model:
|
|
|
453
425
|
content: UserContent | Sequence[Message],
|
|
454
426
|
*,
|
|
455
427
|
ctx: Context[DepsT],
|
|
456
|
-
tools:
|
|
457
|
-
|
|
458
|
-
| None = None,
|
|
459
|
-
format: type[FormattableT]
|
|
460
|
-
| Format[FormattableT]
|
|
461
|
-
| OutputParser[FormattableT]
|
|
462
|
-
| None,
|
|
428
|
+
tools: ContextTools[DepsT] | None = None,
|
|
429
|
+
format: FormatSpec[FormattableT] | None,
|
|
463
430
|
) -> ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT]:
|
|
464
431
|
"""Generate an `llm.ContextResponse` with an optional response format."""
|
|
465
432
|
...
|
|
@@ -469,13 +436,8 @@ class Model:
|
|
|
469
436
|
content: UserContent | Sequence[Message],
|
|
470
437
|
*,
|
|
471
438
|
ctx: Context[DepsT],
|
|
472
|
-
tools:
|
|
473
|
-
|
|
474
|
-
| None = None,
|
|
475
|
-
format: type[FormattableT]
|
|
476
|
-
| Format[FormattableT]
|
|
477
|
-
| OutputParser[FormattableT]
|
|
478
|
-
| None = None,
|
|
439
|
+
tools: ContextTools[DepsT] | None = None,
|
|
440
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
479
441
|
) -> ContextResponse[DepsT, None] | ContextResponse[DepsT, FormattableT]:
|
|
480
442
|
"""Generate an `llm.ContextResponse` by synchronously calling this model's LLM provider.
|
|
481
443
|
|
|
@@ -495,7 +457,7 @@ class Model:
|
|
|
495
457
|
ctx=ctx,
|
|
496
458
|
model_id=self.model_id,
|
|
497
459
|
messages=messages,
|
|
498
|
-
|
|
460
|
+
toolkit=normalize_context_tools(tools),
|
|
499
461
|
format=format,
|
|
500
462
|
**self.params,
|
|
501
463
|
)
|
|
@@ -506,9 +468,7 @@ class Model:
|
|
|
506
468
|
content: UserContent | Sequence[Message],
|
|
507
469
|
*,
|
|
508
470
|
ctx: Context[DepsT],
|
|
509
|
-
tools:
|
|
510
|
-
| AsyncContextToolkit[DepsT]
|
|
511
|
-
| None = None,
|
|
471
|
+
tools: AsyncContextTools[DepsT] | None = None,
|
|
512
472
|
format: None = None,
|
|
513
473
|
) -> AsyncContextResponse[DepsT, None]:
|
|
514
474
|
"""Generate an `llm.AsyncContextResponse` without a response format."""
|
|
@@ -520,9 +480,7 @@ class Model:
|
|
|
520
480
|
content: UserContent | Sequence[Message],
|
|
521
481
|
*,
|
|
522
482
|
ctx: Context[DepsT],
|
|
523
|
-
tools:
|
|
524
|
-
| AsyncContextToolkit[DepsT]
|
|
525
|
-
| None = None,
|
|
483
|
+
tools: AsyncContextTools[DepsT] | None = None,
|
|
526
484
|
format: type[FormattableT] | Format[FormattableT],
|
|
527
485
|
) -> AsyncContextResponse[DepsT, FormattableT]:
|
|
528
486
|
"""Generate an `llm.AsyncContextResponse` with a response format."""
|
|
@@ -534,13 +492,8 @@ class Model:
|
|
|
534
492
|
content: UserContent | Sequence[Message],
|
|
535
493
|
*,
|
|
536
494
|
ctx: Context[DepsT],
|
|
537
|
-
tools:
|
|
538
|
-
|
|
539
|
-
| None = None,
|
|
540
|
-
format: type[FormattableT]
|
|
541
|
-
| Format[FormattableT]
|
|
542
|
-
| OutputParser[FormattableT]
|
|
543
|
-
| None,
|
|
495
|
+
tools: AsyncContextTools[DepsT] | None = None,
|
|
496
|
+
format: FormatSpec[FormattableT] | None,
|
|
544
497
|
) -> AsyncContextResponse[DepsT, None] | AsyncContextResponse[DepsT, FormattableT]:
|
|
545
498
|
"""Generate an `llm.AsyncContextResponse` with an optional response format."""
|
|
546
499
|
...
|
|
@@ -550,13 +503,8 @@ class Model:
|
|
|
550
503
|
content: UserContent | Sequence[Message],
|
|
551
504
|
*,
|
|
552
505
|
ctx: Context[DepsT],
|
|
553
|
-
tools:
|
|
554
|
-
|
|
555
|
-
| None = None,
|
|
556
|
-
format: type[FormattableT]
|
|
557
|
-
| Format[FormattableT]
|
|
558
|
-
| OutputParser[FormattableT]
|
|
559
|
-
| None = None,
|
|
506
|
+
tools: AsyncContextTools[DepsT] | None = None,
|
|
507
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
560
508
|
) -> AsyncContextResponse[DepsT, None] | AsyncContextResponse[DepsT, FormattableT]:
|
|
561
509
|
"""Generate an `llm.AsyncContextResponse` by asynchronously calling this model's LLM provider.
|
|
562
510
|
|
|
@@ -576,7 +524,7 @@ class Model:
|
|
|
576
524
|
ctx=ctx,
|
|
577
525
|
model_id=self.model_id,
|
|
578
526
|
messages=messages,
|
|
579
|
-
|
|
527
|
+
toolkit=normalize_async_context_tools(tools),
|
|
580
528
|
format=format,
|
|
581
529
|
**self.params,
|
|
582
530
|
)
|
|
@@ -587,9 +535,7 @@ class Model:
|
|
|
587
535
|
content: UserContent | Sequence[Message],
|
|
588
536
|
*,
|
|
589
537
|
ctx: Context[DepsT],
|
|
590
|
-
tools:
|
|
591
|
-
| ContextToolkit[DepsT]
|
|
592
|
-
| None = None,
|
|
538
|
+
tools: ContextTools[DepsT] | None = None,
|
|
593
539
|
format: None = None,
|
|
594
540
|
) -> ContextStreamResponse[DepsT, None]:
|
|
595
541
|
"""Stream an `llm.ContextStreamResponse` without a response format."""
|
|
@@ -601,9 +547,7 @@ class Model:
|
|
|
601
547
|
content: UserContent | Sequence[Message],
|
|
602
548
|
*,
|
|
603
549
|
ctx: Context[DepsT],
|
|
604
|
-
tools:
|
|
605
|
-
| ContextToolkit[DepsT]
|
|
606
|
-
| None = None,
|
|
550
|
+
tools: ContextTools[DepsT] | None = None,
|
|
607
551
|
format: type[FormattableT] | Format[FormattableT],
|
|
608
552
|
) -> ContextStreamResponse[DepsT, FormattableT]:
|
|
609
553
|
"""Stream an `llm.ContextStreamResponse` with a response format."""
|
|
@@ -615,13 +559,8 @@ class Model:
|
|
|
615
559
|
content: UserContent | Sequence[Message],
|
|
616
560
|
*,
|
|
617
561
|
ctx: Context[DepsT],
|
|
618
|
-
tools:
|
|
619
|
-
|
|
620
|
-
| None = None,
|
|
621
|
-
format: type[FormattableT]
|
|
622
|
-
| Format[FormattableT]
|
|
623
|
-
| OutputParser[FormattableT]
|
|
624
|
-
| None,
|
|
562
|
+
tools: ContextTools[DepsT] | None = None,
|
|
563
|
+
format: FormatSpec[FormattableT] | None,
|
|
625
564
|
) -> (
|
|
626
565
|
ContextStreamResponse[DepsT, None] | ContextStreamResponse[DepsT, FormattableT]
|
|
627
566
|
):
|
|
@@ -633,13 +572,8 @@ class Model:
|
|
|
633
572
|
content: UserContent | Sequence[Message],
|
|
634
573
|
*,
|
|
635
574
|
ctx: Context[DepsT],
|
|
636
|
-
tools:
|
|
637
|
-
|
|
638
|
-
| None = None,
|
|
639
|
-
format: type[FormattableT]
|
|
640
|
-
| Format[FormattableT]
|
|
641
|
-
| OutputParser[FormattableT]
|
|
642
|
-
| None = None,
|
|
575
|
+
tools: ContextTools[DepsT] | None = None,
|
|
576
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
643
577
|
) -> (
|
|
644
578
|
ContextStreamResponse[DepsT, None] | ContextStreamResponse[DepsT, FormattableT]
|
|
645
579
|
):
|
|
@@ -661,7 +595,7 @@ class Model:
|
|
|
661
595
|
ctx=ctx,
|
|
662
596
|
model_id=self.model_id,
|
|
663
597
|
messages=messages,
|
|
664
|
-
|
|
598
|
+
toolkit=normalize_context_tools(tools),
|
|
665
599
|
format=format,
|
|
666
600
|
**self.params,
|
|
667
601
|
)
|
|
@@ -672,9 +606,7 @@ class Model:
|
|
|
672
606
|
content: UserContent | Sequence[Message],
|
|
673
607
|
*,
|
|
674
608
|
ctx: Context[DepsT],
|
|
675
|
-
tools:
|
|
676
|
-
| AsyncContextToolkit[DepsT]
|
|
677
|
-
| None = None,
|
|
609
|
+
tools: AsyncContextTools[DepsT] | None = None,
|
|
678
610
|
format: None = None,
|
|
679
611
|
) -> AsyncContextStreamResponse[DepsT, None]:
|
|
680
612
|
"""Stream an `llm.AsyncContextStreamResponse` without a response format."""
|
|
@@ -686,9 +618,7 @@ class Model:
|
|
|
686
618
|
content: UserContent | Sequence[Message],
|
|
687
619
|
*,
|
|
688
620
|
ctx: Context[DepsT],
|
|
689
|
-
tools:
|
|
690
|
-
| AsyncContextToolkit[DepsT]
|
|
691
|
-
| None = None,
|
|
621
|
+
tools: AsyncContextTools[DepsT] | None = None,
|
|
692
622
|
format: type[FormattableT] | Format[FormattableT],
|
|
693
623
|
) -> AsyncContextStreamResponse[DepsT, FormattableT]:
|
|
694
624
|
"""Stream an `llm.AsyncContextStreamResponse` with a response format."""
|
|
@@ -700,13 +630,8 @@ class Model:
|
|
|
700
630
|
content: UserContent | Sequence[Message],
|
|
701
631
|
*,
|
|
702
632
|
ctx: Context[DepsT],
|
|
703
|
-
tools:
|
|
704
|
-
|
|
705
|
-
| None = None,
|
|
706
|
-
format: type[FormattableT]
|
|
707
|
-
| Format[FormattableT]
|
|
708
|
-
| OutputParser[FormattableT]
|
|
709
|
-
| None,
|
|
633
|
+
tools: AsyncContextTools[DepsT] | None = None,
|
|
634
|
+
format: FormatSpec[FormattableT] | None,
|
|
710
635
|
) -> (
|
|
711
636
|
AsyncContextStreamResponse[DepsT, None]
|
|
712
637
|
| AsyncContextStreamResponse[DepsT, FormattableT]
|
|
@@ -719,13 +644,8 @@ class Model:
|
|
|
719
644
|
content: UserContent | Sequence[Message],
|
|
720
645
|
*,
|
|
721
646
|
ctx: Context[DepsT],
|
|
722
|
-
tools:
|
|
723
|
-
|
|
724
|
-
| None = None,
|
|
725
|
-
format: type[FormattableT]
|
|
726
|
-
| Format[FormattableT]
|
|
727
|
-
| OutputParser[FormattableT]
|
|
728
|
-
| None = None,
|
|
647
|
+
tools: AsyncContextTools[DepsT] | None = None,
|
|
648
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
729
649
|
) -> (
|
|
730
650
|
AsyncContextStreamResponse[DepsT, None]
|
|
731
651
|
| AsyncContextStreamResponse[DepsT, FormattableT]
|
|
@@ -748,7 +668,7 @@ class Model:
|
|
|
748
668
|
ctx=ctx,
|
|
749
669
|
model_id=self.model_id,
|
|
750
670
|
messages=messages,
|
|
751
|
-
|
|
671
|
+
toolkit=normalize_async_context_tools(tools),
|
|
752
672
|
format=format,
|
|
753
673
|
**self.params,
|
|
754
674
|
)
|
|
@@ -4,7 +4,7 @@ from collections.abc import Sequence
|
|
|
4
4
|
from typing import Generic, cast, overload
|
|
5
5
|
|
|
6
6
|
from ..context import DepsT
|
|
7
|
-
from ..formatting import
|
|
7
|
+
from ..formatting import FormatSpec, FormattableT
|
|
8
8
|
from ..tools import (
|
|
9
9
|
AsyncContextTool,
|
|
10
10
|
AsyncContextToolkit,
|
|
@@ -46,18 +46,13 @@ class PromptDecorator(Generic[ToolT, FormattableT]):
|
|
|
46
46
|
tools: Sequence[ToolT] | None
|
|
47
47
|
"""The tools that are included in the prompt, if any."""
|
|
48
48
|
|
|
49
|
-
format:
|
|
50
|
-
type[FormattableT] | Format[FormattableT] | OutputParser[FormattableT] | None
|
|
51
|
-
)
|
|
49
|
+
format: FormatSpec[FormattableT] | None
|
|
52
50
|
"""The structured output format off the prompt, if any."""
|
|
53
51
|
|
|
54
52
|
def __init__(
|
|
55
53
|
self,
|
|
56
54
|
tools: Sequence[ToolT] | None = None,
|
|
57
|
-
format:
|
|
58
|
-
| Format[FormattableT]
|
|
59
|
-
| OutputParser[FormattableT]
|
|
60
|
-
| None = None,
|
|
55
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
61
56
|
) -> None:
|
|
62
57
|
"""Initialize the decorator with optional tools and format."""
|
|
63
58
|
self.tools = tools
|
|
@@ -173,10 +168,7 @@ def prompt(
|
|
|
173
168
|
def prompt(
|
|
174
169
|
*,
|
|
175
170
|
tools: Sequence[ToolT] | None = None,
|
|
176
|
-
format:
|
|
177
|
-
| Format[FormattableT]
|
|
178
|
-
| OutputParser[FormattableT]
|
|
179
|
-
| None = None,
|
|
171
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
180
172
|
) -> PromptDecorator[ToolT, FormattableT]:
|
|
181
173
|
"""Create a decorator for Prompt functions with tools and format"""
|
|
182
174
|
|
|
@@ -189,10 +181,7 @@ def prompt(
|
|
|
189
181
|
| None = None,
|
|
190
182
|
*,
|
|
191
183
|
tools: Sequence[ToolT] | None = None,
|
|
192
|
-
format:
|
|
193
|
-
| Format[FormattableT]
|
|
194
|
-
| OutputParser[FormattableT]
|
|
195
|
-
| None = None,
|
|
184
|
+
format: FormatSpec[FormattableT] | None = None,
|
|
196
185
|
) -> (
|
|
197
186
|
AsyncContextPrompt[P, DepsT, FormattableT]
|
|
198
187
|
| ContextPrompt[P, DepsT, FormattableT]
|
mirascope/llm/prompts/prompts.py
CHANGED
|
@@ -6,7 +6,7 @@ from typing import Any, Generic, TypeVar, overload
|
|
|
6
6
|
|
|
7
7
|
from ..._utils import copy_function_metadata
|
|
8
8
|
from ..context import Context, DepsT
|
|
9
|
-
from ..formatting import
|
|
9
|
+
from ..formatting import FormatSpec, FormattableT
|
|
10
10
|
from ..messages import Message, promote_to_messages
|
|
11
11
|
from ..models import Model
|
|
12
12
|
from ..providers import ModelId
|
|
@@ -61,9 +61,7 @@ class Prompt(BasePrompt[MessageTemplate[P]], Generic[P, FormattableT]):
|
|
|
61
61
|
toolkit: Toolkit
|
|
62
62
|
"""The toolkit containing this prompt's tools."""
|
|
63
63
|
|
|
64
|
-
format:
|
|
65
|
-
type[FormattableT] | Format[FormattableT] | OutputParser[FormattableT] | None
|
|
66
|
-
)
|
|
64
|
+
format: FormatSpec[FormattableT] | None
|
|
67
65
|
"""The response format for the generated response."""
|
|
68
66
|
|
|
69
67
|
def messages(self, *args: P.args, **kwargs: P.kwargs) -> Sequence[Message]:
|
|
@@ -157,9 +155,7 @@ class AsyncPrompt(BasePrompt[AsyncMessageTemplate[P]], Generic[P, FormattableT])
|
|
|
157
155
|
toolkit: AsyncToolkit
|
|
158
156
|
"""The toolkit containing this prompt's async tools."""
|
|
159
157
|
|
|
160
|
-
format:
|
|
161
|
-
type[FormattableT] | Format[FormattableT] | OutputParser[FormattableT] | None
|
|
162
|
-
)
|
|
158
|
+
format: FormatSpec[FormattableT] | None
|
|
163
159
|
"""The response format for the generated response."""
|
|
164
160
|
|
|
165
161
|
async def messages(self, *args: P.args, **kwargs: P.kwargs) -> Sequence[Message]:
|
|
@@ -258,9 +254,7 @@ class ContextPrompt(
|
|
|
258
254
|
toolkit: ContextToolkit[DepsT]
|
|
259
255
|
"""The toolkit containing this prompt's context-aware tools."""
|
|
260
256
|
|
|
261
|
-
format:
|
|
262
|
-
type[FormattableT] | Format[FormattableT] | OutputParser[FormattableT] | None
|
|
263
|
-
)
|
|
257
|
+
format: FormatSpec[FormattableT] | None
|
|
264
258
|
"""The response format for the generated response."""
|
|
265
259
|
|
|
266
260
|
def messages(
|
|
@@ -383,9 +377,7 @@ class AsyncContextPrompt(
|
|
|
383
377
|
toolkit: AsyncContextToolkit[DepsT]
|
|
384
378
|
"""The toolkit containing this prompt's async context-aware tools."""
|
|
385
379
|
|
|
386
|
-
format:
|
|
387
|
-
type[FormattableT] | Format[FormattableT] | OutputParser[FormattableT] | None
|
|
388
|
-
)
|
|
380
|
+
format: FormatSpec[FormattableT] | None
|
|
389
381
|
"""The response format for the generated response."""
|
|
390
382
|
|
|
391
383
|
async def messages(
|