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.1.tar.gz (66.2 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.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for langchain_tzafon-1.1.1.tar.gz
Algorithm Hash digest
SHA256 8e747427382a8edee2cb6422213bbd50c61080c9ba20911de5f30c0bab64a8f3
MD5 8468524aac26b1d2e2cf48306892ea30
BLAKE2b-256 4b001d118df33cef365c7c2ee79b295ef144db267d85f068c7a0933bd908f07e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for langchain_tzafon-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b88956aaa0d3c8ff283e8a1700aee67a7b3b3e29c319583e73ae27bccbd707ad
MD5 a83f488f61c8d4f164562eaf03a10ddd
BLAKE2b-256 a9c48f67cb116e1fb82cd94f7c50322a66f25bb20e4ed9358248ac216628c832

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