Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
kaancayli committed Nov 11, 2024
1 parent daa969a commit 5d81124
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
9 changes: 5 additions & 4 deletions app/llm/external/ollama.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/llm/external/openai_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
"""
Expand Down
3 changes: 2 additions & 1 deletion app/llm/request_handler/basic_request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 9 additions & 7 deletions app/llm/request_handler/capability_request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5d81124

Please sign in to comment.