Skip to main content

This package contains tools to work with Tilores entity resolution database within Langchain.

Project description

LangChain Using Tilores

This repository provides the building blocks for integrating LangChain, LangGraph, and the Tilores entity resolution system.

Developers can use these tools to create powerful systems that leverage entity resolution for record retrieval, search, and entity resolution.

Examples

  • Human-in-the-Loop Chat: examples/chat

    This example demonstrates how to build a chat application using Chainlit and LangGraph to explore a Tilores instance through natural language. It guides users through search functionality and explains the search results.

  • Basic Usage: examples/basic

    This example shows how to use tools with an LLM model in a basic setup.

Usage

from tilores import TiloresAPI
from langchain_tilores import TiloresTools
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage

# Initialize the Tilores API.
tilores = TiloresAPI.from_environ()
# TiloresTools helps you build typed tools from a specific Tilores instance, typed according to
# the schema of the instance.
tilores_tools = TiloresTools(tilores)

# Setup a LLM model for inference bound with a set of tools.
tools = [tilores_tools.search_tool]
tools_dict = {tool.name: tool for tool in tools}
model = ChatOpenAI(temperature=0, streaming=True, model_name="gpt-4o")
model = model.bind_tools(tools)

# The basic loop works like this, that a list of messages is passed to the LLM
messages = [
    HumanMessage("Find me an entity by the first name Emma, surname Schulz, born on 1988-03-12")
]
ai_message = model.invoke(messages)
messages.append(ai_message)

# And for each AiMessage, you must check if it wants to invoke tools.
for tool_call in ai_message.tool_calls:
    # Perform the tool call and append the ToolMessage to the list of messages
    selected_tool = tools_dict[tool_call['name']]
    tool_message = selected_tool.invoke(tool_call)
    messages.append(tool_message)

# Then continue the basic loop by invoking the LLM with the current state, passing the list of messages.
ai_response = model.invoke(messages)
print(ai_response.content)
$ cd examples/basic/
$ pip install -r requirements.txt
$ python llm_with_tools.py
I found multiple records for an entity with the first name Emma, surname Schulz, born on 1988-03-12. Here are the details:

1. **Record ID:** cc001001-0006-4000-c000-000000000006
   - **First Name:** Emma
   - **Last Name:** Schulz
   - **Date of Birth:** 1988-03-12

2. **Record ID:** cc001001-0002-4000-c000-000000000002
   - **First Name:** Emma
   - **Last Name:** Schulz
   - **Date of Birth:** 1988-03-12

[... snip ...]

If you need more specific information or further assistance, please let me know!

Provided tools

  • tilores_search

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_tilores-0.2.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

langchain_tilores-0.2.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file langchain_tilores-0.2.1.tar.gz.

File metadata

  • Download URL: langchain_tilores-0.2.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for langchain_tilores-0.2.1.tar.gz
Algorithm Hash digest
SHA256 22fac4404437a41488451ee28c817ab57629c3bf35c01de6b5a7c3cbe622b599
MD5 cfdced026ef80b76e5a0b6c16c51a7a9
BLAKE2b-256 2857436d7d905839413613f894a1b1e7a7e8957fe06b25ad20772f7cce6045cd

See more details on using hashes here.

File details

Details for the file langchain_tilores-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_tilores-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c87f98086cdc638e0e4b788183a82201fc8d7d2fd19293dcffd1c8c53ede850a
MD5 bc5f342cc519d1efd58510681eb100d9
BLAKE2b-256 541c3af61ba39a8b880c82877cf454251c427da19d8404d1f36a3eaf4da4b01b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page