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.
- Sign up or log in at tzafon.ai to get your API key.
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
389135c92a2b9df2b25f6926cf1f5bcfb73cb11732f7112ef42888ab2211766e
|
|
| MD5 |
d1f0f691201a3643fd2bb120c0f2d836
|
|
| BLAKE2b-256 |
e064995bdbda758dfbcefccd4cde35332c1a78536fd34317346993a097011940
|
File details
Details for the file langchain_tzafon-1.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_tzafon-1.1.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8aa4ef39807b0c43d9f0179726e2724542a20f269e6d352cf5c1aacbd4264b82
|
|
| MD5 |
ea0f82b71d444ffadb5c3de697b652bc
|
|
| BLAKE2b-256 |
161ba99e09bf11de7f45f1cfe9352260635625f24e340d71372ad217b192662d
|