MCPcopy Create free account
hub / github.com/SqueezeAILab/LLMCompiler / from_function

Method from_function

src/tools/base.py:199–222  ·  view source on GitHub ↗

Initialize tool from a function.

(
        cls,
        func: Optional[Callable],
        name: str,  # We keep these required to support backwards compatibility
        description: str,
        return_direct: bool = False,
        args_schema: Optional[Type[BaseModel]] = None,
        coroutine: Optional[
            Callable[..., Awaitable[Any]]
        ] = None,  # This is last for compatibility, but should be after func
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

197
198 @classmethod
199 def from_function(
200 cls,
201 func: Optional[Callable],
202 name: str, # We keep these required to support backwards compatibility
203 description: str,
204 return_direct: bool = False,
205 args_schema: Optional[Type[BaseModel]] = None,
206 coroutine: Optional[
207 Callable[..., Awaitable[Any]]
208 ] = None, # This is last for compatibility, but should be after func
209 **kwargs: Any,
210 ) -> Tool:
211 """Initialize tool from a function."""
212 if func is None and coroutine is None:
213 raise ValueError("Function and/or coroutine must be provided")
214 return cls(
215 name=name,
216 func=func,
217 coroutine=coroutine,
218 description=description,
219 return_direct=return_direct,
220 args_schema=args_schema,
221 **kwargs,
222 )
223
224
225class StructuredTool(BaseTool):

Callers 1

_make_toolFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected