Tool Calling LLM
Tool Calling LLM is a python mixin that lets you add tool calling capabilities effortlessly to LangChain's Chat Models that don't yet support tool/function calling natively. Simply create a new chat model class with ToolCallingLLM and your favorite chat model to get started.
With ToolCallingLLM you also get access to the following functions:
.bind_tools()allows you to bind tool definitions with a llm..with_structured_output()allows you to return structured data from your model. This is now being provided by LangChain'sBaseChatModelclass.
At this time, ToolCallingLLM has been tested to work with ChatOllama, ChatNVIDIA, and ChatLiteLLM with Ollama provider.
The OllamaFunctions was the original inspiration for this effort. The code for ToolCallingLLM was abstracted out of OllamaFunctions to allow it to be reused with other non tool calling Chat Models.
Installation
pip install --upgrade tool_calling_llm
Usage
Creating a Tool Calling LLM is as simple as creating a new sub class of the original ChatModel you wish to add tool calling features to.
Below sample code demonstrates how you might enhance ChatOllama chat model from langchain-ollama package with tool calling capabilities.
from tool_calling_llm import ToolCallingLLM
from langchain_ollama import ChatOllama
from langchain_community.tools import DuckDuckGoSearchRun
class OllamaWithTools(ToolCallingLLM, ChatOllama):
def __init__(self, **kwargs):
super().__init__(**kwargs)
@property
def _llm_type(self):
return "ollama_with_tools"
llm = OllamaWithTools(model="llama3.1",format="json")
tools = [DuckDuckGoSearchRun()]
llm_tools = llm.bind_tools(tools=tools)
llm_tools.invoke("Who won the silver medal in shooting in the Paris Olympics in 2024?")
This yields output as follows:
AIMessage(content='', id='run-9c3c7a78-97af-4d06-835e-aa81174fd7e8-0', tool_calls=[{'name': 'duckduckgo_search', 'args': {'query': 'Paris Olympics 2024 shooting silver medal winner'}, 'id': 'call_67b06088e208482497f6f8314e0f1a0e', 'type': 'tool_call'}])
For more comprehensive examples, refer to ToolCallingLLM-Tutorial.ipynb jupyter notebook.
Metadata
Release files for tool-calling-llm 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tool_calling_llm-0.1.2.tar.gz | 6.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tool_calling_llm-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.1 kB
Release files / tool_calling_llm-0.1.2.tar.gz
| Download URL | tool_calling_llm-0.1.2.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b558d0229b6cee840ca3b123673067c2c5fa9323590ed1dcbb5e2c06432c5d8a
|
|
BLAKE2b-256 checksum How to use checksums |
2abe0e7d3f4d75c49cfe672f408b5ca8e0bb24a4415570cd14c46e968958b5fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.6
|
Release files / tool_calling_llm-0.1.2-py3-none-any.whl
| Download URL | tool_calling_llm-0.1.2-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bc0aa3a1f9f522a0ca9d131e8241be6861233d5ebfb649a04ccf2a00f2ade50c
|
|
BLAKE2b-256 checksum How to use checksums |
75bb21d50be4cb02e64e2700bc2dbe26a0646bf74534f0b11c858d5bbc2fefad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.6
|