tool
Adapted from the Griptape AI Framework documentation.
Bases:
BaseTool
Source Code in griptape/tools/calculator/tool.py
class CalculatorTool(BaseTool): @activity( config={ "description": "Can be used for computing simple numerical or algebraic calculations in Python", "schema": Schema( { Literal( "expression", description="Arithmetic expression parsable in pure Python. Single line only. " "Don't use variables. Don't use any imports or external libraries", ): str, }, ), }, ) def calculate(self, params: dict) -> BaseArtifact: import numexpr # pyright: ignore[reportMissingImports] try: expression = params["values"]["expression"] return TextArtifact(numexpr.evaluate(expression)) except Exception as e: return ErrorArtifact(f"error calculating: {e}")
calculate(params)
Source Code in griptape/tools/calculator/tool.py
@activity( config={ "description": "Can be used for computing simple numerical or algebraic calculations in Python", "schema": Schema( { Literal( "expression", description="Arithmetic expression parsable in pure Python. Single line only. " "Don't use variables. Don't use any imports or external libraries", ): str, }, ), }, ) def calculate(self, params: dict) -> BaseArtifact: import numexpr # pyright: ignore[reportMissingImports] try: expression = params["values"]["expression"] return TextArtifact(numexpr.evaluate(expression)) except Exception as e: return ErrorArtifact(f"error calculating: {e}")
- On this page
- calculate(params)
Could this page be better? Report a problem or suggest an addition!