LangChain integration for the Synapse decentralized AI model marketplace. Wraps the Synapse orchestrator's /api/infer endpoint as a standard LangChain LLM.
Project description
langchain-synapse
Dead-simple LangChain integration for the
Synapse decentralized inference network. Wraps the orchestrator's
POST /api/infer endpoint as a standard LangChain LLM so Synapse plugs into
any chain, agent, or RAG pipeline.
Install
From PyPI:
pip install synapse-langchain
From source:
cd integrations/langchain-synapse
pip install -e .
Distribution name on PyPI is
synapse-langchain; the Python import name islangchain_synapse(unchanged).
Use
from langchain_synapse import SynapseLLM
llm = SynapseLLM(
token_id="1", # model NFT id
user="0x0000000000000000000000000000000000000001", # your wallet
base_url="http://localhost:8000", # orchestrator
max_tokens=128,
)
print(llm.invoke("Hello from LangChain!"))
Works with LCEL out of the box:
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
chain = ChatPromptTemplate.from_template("Q: {q}\nA:") | llm | StrOutputParser()
chain.invoke({"q": "What is decentralized inference?"})
Demos
# Make sure the orchestrator is running:
# ROLE=orchestrator uvicorn backend.main:app --port 8000
python examples/demo.py
python examples/chain_demo.py
Config
| Param | Env var | Default |
|---|---|---|
base_url |
SYNAPSE_API_URL |
http://localhost:8000 |
token_id |
— | required |
user |
— | required |
session_id |
— | random bytes32 (demo) |
max_tokens |
— | 128 |
parameters |
— | None (pipeline kwargs) |
session_idmust come fromMarketplace.openSessionfor real paid runs. Leave itNoneonly when demoing against a dev orchestrator.
How it works
SynapseLLM._call just POSTs to /api/infer with the Synapse
InferenceRequest shape and returns
outputStr from the response. That's the entire integration — 60-ish lines.
Project details
Release history Release notifications | RSS feed
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 synapse_langchain-0.1.0.tar.gz.
File metadata
- Download URL: synapse_langchain-0.1.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08bf4e8d6b34d51f04d110640d00faea16304b246a6eb6f1c44da4ee1b1a6bf3
|
|
| MD5 |
1a7b6ddaddfc6f6e6d80eb2226b1d386
|
|
| BLAKE2b-256 |
fb318ac6228d372b888a423b9a5e6885a74c9b96fe768e5174d5c38ee1ab609e
|
File details
Details for the file synapse_langchain-0.1.0-py3-none-any.whl.
File metadata
- Download URL: synapse_langchain-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
008ce93f3b4480bb5fe8db1aef142f605c9e94bf8b1ea6131c621b459bb5d7bc
|
|
| MD5 |
d6aa868bf33812add901df6df5c1eba8
|
|
| BLAKE2b-256 |
caf234de1b4c75c350e32d0294111e007c6fda016ecf18cb745892b831c38929
|