From 5d811246bae2c33e1ac8b38ebf0dc9fb7017bc70 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:45:54 +0100 Subject: [PATCH] fix linting --- app/llm/external/ollama.py | 9 +++++---- app/llm/external/openai_chat.py | 2 +- app/llm/request_handler/basic_request_handler.py | 3 ++- .../capability_request_handler.py | 16 +++++++++------- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/llm/external/ollama.py b/app/llm/external/ollama.py index 01e8d0e1..8739262a 100644 --- a/app/llm/external/ollama.py +++ b/app/llm/external/ollama.py @@ -138,19 +138,20 @@ def embed(self, text: str) -> list[float]: return list(response) """Bind tools to the language model for function calling capabilities. - + Note: Tool binding is currently not supported in Ollama models. This feature is only available for OpenAI models. - + Args: tools: A sequence of tools to bind to the model. - + Returns: A runnable that can process inputs with the bound tools. - + Raises: NotImplementedError: Always raised as Ollama does not support tool binding. """ + # TODO: Implement tool binding support for Ollama models def bind_tools( self, diff --git a/app/llm/external/openai_chat.py b/app/llm/external/openai_chat.py index 1b5e475a..e7197314 100644 --- a/app/llm/external/openai_chat.py +++ b/app/llm/external/openai_chat.py @@ -79,7 +79,7 @@ def create_openai_tool_calls(tool_calls): ] -def convert_to_openai_messages( +def convert_to_open_ai_messages( messages: list[PyrisMessage], ) -> list[ChatCompletionMessageParam]: """ diff --git a/app/llm/request_handler/basic_request_handler.py b/app/llm/request_handler/basic_request_handler.py index dafb31a5..0c1c835a 100644 --- a/app/llm/request_handler/basic_request_handler.py +++ b/app/llm/request_handler/basic_request_handler.py @@ -46,7 +46,8 @@ def bind_tools( Binds a sequence of tools to the language model. Args: - tools (Sequence[Union[Dict[str, Any], Type[BaseModel], Callable, BaseTool]]): A sequence of tools to be bound. + tools (Sequence[Union[Dict[str, Any], Type[BaseModel], Callable, BaseTool]]): + A sequence of tools to be bound. Returns: LanguageModel: The language model with tools bound. diff --git a/app/llm/request_handler/capability_request_handler.py b/app/llm/request_handler/capability_request_handler.py index fb04707d..cd8c876b 100644 --- a/app/llm/request_handler/capability_request_handler.py +++ b/app/llm/request_handler/capability_request_handler.py @@ -79,27 +79,29 @@ def bind_tools( tools: Sequence[Union[Dict[str, Any], Type[BaseModel], Callable, BaseTool]], ) -> LanguageModel: """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") - + if not hasattr(llm, "bind_tools"): + raise TypeError( + f"Selected model {llm.description} doesn't support tool binding" + ) + llm.bind_tools(tools) return llm