|
20 | 20 | from mellea.backends.aloras import Alora, AloraBackendMixin |
21 | 21 | from mellea.backends.formatter import Formatter, FormatterBackend, TemplateFormatter |
22 | 22 | from mellea.backends.model_ids import ModelIdentifier |
23 | | -from mellea.backends.tools import convert_tools_to_json, get_tools_from_action |
| 23 | +from mellea.backends.tools import ( |
| 24 | + add_tools_from_model_options, |
| 25 | + convert_tools_to_json, |
| 26 | + get_tools_from_action, |
| 27 | +) |
24 | 28 | from mellea.backends.types import ModelOption |
25 | 29 | from mellea.helpers.fancy_logger import FancyLogger |
26 | 30 | from mellea.stdlib.base import ( |
@@ -409,23 +413,8 @@ def _generate_from_chat_context_standard( |
409 | 413 | ): |
410 | 414 | tools = get_tools_from_action(action) |
411 | 415 |
|
412 | | - model_options_tools = model_opts.get(ModelOption.TOOLS, None) |
413 | | - if model_options_tools is not None: |
414 | | - assert isinstance(model_options_tools, dict) |
415 | | - for fn_name in model_options_tools: |
416 | | - # invariant re: relationship between the model_options set of tools and the TemplateRepresentation set of tools |
417 | | - assert fn_name not in tools.keys(), ( |
418 | | - f"Cannot add tool {fn_name} because that tool was already defined in the TemplateRepresentation for the action." |
419 | | - ) |
420 | | - # type checking because ModelOptions is an untyped dict and the calling convention for tools isn't clearly documented at our abstraction boundaries. |
421 | | - assert type(fn_name) is str, ( |
422 | | - "When providing a `ModelOption.TOOLS` parameter to `model_options`, always used the type Dict[str, Callable] where `str` is the function name and the callable is the function." |
423 | | - ) |
424 | | - assert callable(model_options_tools[fn_name]), ( |
425 | | - "When providing a `ModelOption.TOOLS` parameter to `model_options`, always used the type Dict[str, Callable] where `str` is the function name and the callable is the function." |
426 | | - ) |
427 | | - # Add the model_options tool to the existing set of tools. |
428 | | - tools[fn_name] = model_options_tools[fn_name] |
| 416 | + add_tools_from_model_options(tools, model_opts) |
| 417 | + FancyLogger.get_logger().info(f"Tools for call: {tools.keys()}") |
429 | 418 |
|
430 | 419 | thinking = model_opts.get(ModelOption.THINKING, None) |
431 | 420 | if type(thinking) is bool and thinking: |
|
0 commit comments