-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathimage_generation.py
More file actions
37 lines (28 loc) · 1.13 KB
/
image_generation.py
File metadata and controls
37 lines (28 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from __future__ import annotations
from collections.abc import Awaitable, Callable
from dataclasses import dataclass
from typing import Any, Literal
from pydantic_ai.builtin_tools import ImageGenerationTool
from pydantic_ai.tools import AgentDepsT, RunContext, Tool
from .builtin_or_local import BuiltinOrLocalTool
@dataclass(init=False)
class ImageGeneration(BuiltinOrLocalTool[AgentDepsT]):
"""Image generation capability.
Uses the model's builtin image generation when available. No default local
fallback — provide a custom `local` tool if needed.
"""
def __init__(
self,
*,
builtin: ImageGenerationTool
| Callable[[RunContext[AgentDepsT]], Awaitable[ImageGenerationTool | None] | ImageGenerationTool | None]
| bool = True,
local: Tool[AgentDepsT] | Callable[..., Any] | Literal[False] | None = None,
) -> None:
self.builtin = builtin
self.local = local
self.__post_init__()
def _default_builtin(self) -> ImageGenerationTool:
return ImageGenerationTool()
def _builtin_unique_id(self) -> str:
return ImageGenerationTool.kind