From eafbb03d29d91f9fa20701aec0bf5b49785c8fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20=C3=87ayl=C4=B1?= <38523756+kaancayli@users.noreply.github.com> Date: Tue, 12 Nov 2024 00:39:34 +0100 Subject: [PATCH] Update app/llm/request_handler/capability_request_handler.py Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../capability_request_handler.py | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/app/llm/request_handler/capability_request_handler.py b/app/llm/request_handler/capability_request_handler.py index a7ef4923..fb04707d 100644 --- a/app/llm/request_handler/capability_request_handler.py +++ b/app/llm/request_handler/capability_request_handler.py @@ -78,7 +78,28 @@ def bind_tools( self, tools: Sequence[Union[Dict[str, Any], Type[BaseModel], Callable, BaseTool]], ) -> LanguageModel: - """Bind the tools to the models""" + """Bind the provided tools to the selected ChatModel. + + Args: + tools: A sequence of tools to bind. Can be one of: + - Dict[str, Any]: Tool configuration dictionary + - Type[BaseModel]: Pydantic model class + - Callable: Function to be used as a tool + - BaseTool: LangChain tool instance + + Returns: + LanguageModel: The selected chat model with tools bound + + Raises: + ValueError: If tools sequence is empty or contains unsupported tool types + TypeError: If selected model doesn't support tool binding + """ + if not tools: + raise ValueError("Tools sequence cannot be empty") + llm = self._select_model(ChatModel) + if not hasattr(llm, 'bind_tools'): + raise TypeError(f"Selected model {llm.description} doesn't support tool binding") + llm.bind_tools(tools) return llm