|
8 | 8 | import datetime
|
9 | 9 | import functools
|
10 | 10 | import operator
|
11 |
| -from typing import Any, List |
| 11 | +from typing import Any, List, Dict, Tuple |
12 | 12 | from langchain.schema.prompt import PromptValue
|
13 | 13 | from langchain.tools.base import BaseTool, ToolException
|
14 | 14 | from langchain.pydantic_v1 import BaseModel, root_validator
|
@@ -217,6 +217,12 @@ def _preprocess(self, input: Any) -> str:
|
217 | 217 | return input.to_string()
|
218 | 218 | return str(input)
|
219 | 219 |
|
| 220 | + def _to_args_and_kwargs(self, tool_input: Any) -> Tuple[Tuple, Dict]: |
| 221 | + if isinstance(tool_input, dict): |
| 222 | + return (), tool_input |
| 223 | + else: |
| 224 | + return (tool_input,), {} |
| 225 | + |
220 | 226 | def _run(self, query: Any, run_manager=None) -> Any:
|
221 | 227 | """Runs the guardrail.
|
222 | 228 |
|
@@ -247,7 +253,11 @@ def _run(self, query: Any, run_manager=None) -> Any:
|
247 | 253 | # containing the ``kwargs`` used to initialize the object.
|
248 | 254 | # The ``kwargs`` does not contain the defaults.
|
249 | 255 | # Here the ``dict()`` method is used to return a dictionary containing the defaults.
|
250 |
| - info.parameters = self.dict() |
| 256 | + info.parameters = { |
| 257 | + "class": self.__class__.__name__, |
| 258 | + "path": self.__module__, |
| 259 | + "spec": self.dict(), |
| 260 | + } |
251 | 261 | info.metrics = self.compute(data, **kwargs)
|
252 | 262 | info.output = self.moderate(info.metrics, data, **kwargs)
|
253 | 263 |
|
|
0 commit comments