🦜 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.
Metadata
Release files for langchain-tzafon 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langchain_tzafon-1.1.1.tar.gz | 66.2 kB | Without provenance | Details for langchain_tzafon-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_tzafon-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for langchain_tzafon-1.1.1-py3-none-any.whl |
Total release size: 75.2 kB
Release files / langchain_tzafon-1.1.1.tar.gz
| Download URL | langchain_tzafon-1.1.1.tar.gz |
|---|---|
| Size | 66.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8e747427382a8edee2cb6422213bbd50c61080c9ba20911de5f30c0bab64a8f3
|
|
BLAKE2b-256 checksum How to use checksums |
4b001d118df33cef365c7c2ee79b295ef144db267d85f068c7a0933bd908f07e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.20
|
Release files / langchain_tzafon-1.1.1-py3-none-any.whl
| Download URL | langchain_tzafon-1.1.1-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b88956aaa0d3c8ff283e8a1700aee67a7b3b3e29c319583e73ae27bccbd707ad
|
|
BLAKE2b-256 checksum How to use checksums |
a9c48f67cb116e1fb82cd94f7c50322a66f25bb20e4ed9358248ac216628c832
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.20
|
Security for langchain-tzafon 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.