13
13
from typing import Optional , TypeVar , AnyStr , Callable , Awaitable , Coroutine , ClassVar # noqa: F401, F403
14
14
from pydantic import BaseModel , Field
15
15
from pydantic .fields import FieldInfo
16
- from .types import Content , TextContent , ImageContent , FileContent , ResourceContent , BoolContents , ErrorContent
16
+ from .types import Content , TextContent , ImageContent , FileContent , ResourceContent , BoolContent , ErrorContent
17
17
from .models import SimpleInputModel
18
18
from .schema import NoTitleDescriptionJsonSchema
19
19
from .errors import SimpleToolError , ValidationError
20
20
21
21
22
22
def get_valid_content_types () -> Tuple [Type , ...]:
23
23
"""Directly return the types from the TypeVar definition as a tuple"""
24
- return (Content , TextContent , ImageContent , FileContent , ResourceContent , BoolContents , ErrorContent )
24
+ return (Content , TextContent , ImageContent , FileContent , ResourceContent , BoolContent , ErrorContent )
25
25
26
26
27
27
def validate_tool_output (func ):
28
28
@functools .wraps (func )
29
- async def wrapper (* args : Any , ** kwargs : Any ) -> Sequence [Union [Content , TextContent , ImageContent , FileContent , ResourceContent , BoolContents , ErrorContent ]]:
29
+ async def wrapper (* args : Any , ** kwargs : Any ) -> Sequence [Union [Content , TextContent , ImageContent , FileContent , ResourceContent , BoolContent , ErrorContent ]]:
30
30
result = await func (* args , ** kwargs )
31
31
if not isinstance (result , list ):
32
32
raise ValidationError ("output" , "Tool output must be a list" )
@@ -204,7 +204,7 @@ def __repr__(self):
204
204
205
205
@validate_tool_output
206
206
@set_timeout (DEFAULT_TIMEOUT )
207
- async def run (self , arguments : Dict [str , Any ]) -> Sequence [Union [Content , TextContent , ImageContent , FileContent , ResourceContent , BoolContents , ErrorContent ]]:
207
+ async def run (self , arguments : Dict [str , Any ]) -> Sequence [Union [Content , TextContent , ImageContent , FileContent , ResourceContent , BoolContent , ErrorContent ]]:
208
208
"""
209
209
Execute the tool with the given arguments.
210
210
@@ -250,7 +250,7 @@ async def run(self, arguments: Dict[str, Any]) -> Sequence[Union[Content, TextCo
250
250
# No timeout if _timeout is 0 or negative
251
251
return await self ._run_implementation (validated_arguments )
252
252
253
- async def _run_implementation (self , arguments : SimpleInputModel ) -> Sequence [Union [Content , TextContent , ImageContent , FileContent , ResourceContent , BoolContents , ErrorContent ]]:
253
+ async def _run_implementation (self , arguments : SimpleInputModel ) -> Sequence [Union [Content , TextContent , ImageContent , FileContent , ResourceContent , BoolContent , ErrorContent ]]:
254
254
"""
255
255
Actual implementation of the tool's run method.
256
256
Must be implemented by child classes.
@@ -263,7 +263,7 @@ async def _run_implementation(self, arguments: SimpleInputModel) -> Sequence[Uni
263
263
"""
264
264
raise SimpleToolError (f"Subclass { self .__class__ .__name__ } must implement _run_implementation method" )
265
265
266
- async def __call__ (self , arguments : Dict [str , Any ]) -> Sequence [Union [Content , TextContent , ImageContent , FileContent , ResourceContent , BoolContents , ErrorContent ]]:
266
+ async def __call__ (self , arguments : Dict [str , Any ]) -> Sequence [Union [Content , TextContent , ImageContent , FileContent , ResourceContent , BoolContent , ErrorContent ]]:
267
267
"""Alias for run method"""
268
268
return await self .run (arguments )
269
269
0 commit comments