Skip to main content

An integration package connecting Tzafon and LangChain

Project description

🦜 langchain-tzafon

An integration package connecting Tzafon and LangChain.

langchain-tzafon provides two powerful integrations:

  • ChatTzafon: A LangChain chat model for Tzafon's AI models (chat completions with streaming support)
  • TzafonLoader: A Document Loader using Tzafon's headless browser infrastructure

✨ Features

  • Chat Completions: Access Tzafon's AI models via LangChain's chat model interface
  • Streaming Support: Real-time token streaming for chat responses
  • Headless Browser Rendering: Powered by Tzafon's cloud-based browser instances
  • JavaScript Support: Naturally handles SPAs and dynamically loaded content
  • Sync & Async Support: Features both synchronous and asynchronous APIs
  • Seamless Integration: Fully compatible with LangChain's interfaces

🚀 Installation

pip install langchain-tzafon

Note: This package requires Playwright for connecting to the remote browser.


🔑 Configuration

To use this package, you need a Tzafon API Key.

  1. Sign up or log in at tzafon.ai to get your API key.
  2. Set it as an environment variable (recommended):
export TZAFON_API_KEY="your_api_key_here"

Alternatively, you can pass the API key directly when initializing the loader.


📖 Usage

ChatTzafon - Chat Completions

Use Tzafon's AI models for chat completions:

from langchain_tzafon import ChatTzafon

# Initialize the chat model
chat = ChatTzafon(model="tzafon.sm-1")

# Simple invocation
response = chat.invoke("Hello, how are you?")
print(response.content)

ChatTzafon - Streaming

Stream responses token by token:

from langchain_tzafon import ChatTzafon

chat = ChatTzafon(model="tzafon.sm-1", temperature=0.8)

for chunk in chat.stream("Write a haiku about coding"):
    print(chunk.content, end="", flush=True)

ChatTzafon - With Messages

Use structured messages for conversations:

from langchain_tzafon import ChatTzafon
from langchain_core.messages import HumanMessage, SystemMessage

chat = ChatTzafon()
messages = [
    SystemMessage(content="You are a helpful assistant."),
    HumanMessage(content="What is the capital of France?"),
]
response = chat.invoke(messages)
print(response.content)

TzafonLoader - Text Extraction

Load web pages using Tzafon's headless browser:

from langchain_tzafon import TzafonLoader

loader = TzafonLoader(urls=["https://example.com"])
documents = loader.load()

for doc in documents:
    print(f"Content from {doc.metadata['url']}:")
    print(doc.page_content[:200])

TzafonLoader - Async Loading

For better performance when handling multiple URLs:

import asyncio
from langchain_tzafon import TzafonLoader

async def main():
    loader = TzafonLoader(urls=[
        "https://example.com",
        "https://tzafon.ai"
    ])
    
    async for doc in loader.alazy_load():
        print(f"Loaded {doc.metadata['url']}")

if __name__ == "__main__":
    asyncio.run(main())

🛠️ API Reference

ChatTzafon

Argument Type Description
model str Tzafon model ID. Defaults to "tzafon.sm-1". Options: tzafon.sm-1, tzafon.northstar.cua.sft.
temperature float Sampling temperature (0-1). Defaults to 0.7.
max_tokens Optional[int] Maximum tokens to generate.
stop Optional[List[str]] Stop sequences.
api_key Optional[str] Tzafon API key. Defaults to TZAFON_API_KEY env var.

TzafonLoader

Argument Type Description
urls str | List[str] A single URL or a list of URLs to load.
api_key Optional[str] Your Tzafon API key. Defaults to TZAFON_API_KEY env var.
text_content bool If True (default), extracts visible text. If False, returns raw HTML.

📄 License

This project is licensed under the MIT License.

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_tzafon-1.1.0.tar.gz (65.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_tzafon-1.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file langchain_tzafon-1.1.0.tar.gz.

File metadata

  • Download URL: langchain_tzafon-1.1.0.tar.gz
  • Upload date:
  • Size: 65.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.20

File hashes

Hashes for langchain_tzafon-1.1.0.tar.gz
Algorithm Hash digest
SHA256 389135c92a2b9df2b25f6926cf1f5bcfb73cb11732f7112ef42888ab2211766e
MD5 d1f0f691201a3643fd2bb120c0f2d836
BLAKE2b-256 e064995bdbda758dfbcefccd4cde35332c1a78536fd34317346993a097011940

See more details on using hashes here.

File details

Details for the file langchain_tzafon-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_tzafon-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8aa4ef39807b0c43d9f0179726e2724542a20f269e6d352cf5c1aacbd4264b82
MD5 ea0f82b71d444ffadb5c3de697b652bc
BLAKE2b-256 161ba99e09bf11de7f45f1cfe9352260635625f24e340d71372ad217b192662d

See more details on using hashes here.

Supported by

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