Official Langchain client for 0g.ai Inference SDK
Project description
langchain-0g
This package contains the LangChain integrations for 0G.ai through their a0g SDK.
Installation and Setup
- Install the 0G.ai Python package:
pip install python-0g langchain_0g
- Set your 0G.ai wallet private key as an environment variable:
export A0G_PRIVATE_KEY="your_wallet_private_key"
Chat model
ZGChat is a wrapper around 0G.ai chat models. It allows you to interact with 0G.ai-hosted LLMs in a LangChain-compatible way.
from langchain_0g import ZGChat
chat = ZGChat(provider="0xf07240Efa67755B5311bc75784a061eDB47165Dd")
response = chat.invoke("Hello 0G!")
print(response)
provideris the ENS address of the 0G.ai model.private_keyis optional if you haveA0G_PRIVATE_KEYin the environment.
Asynchronous Usage
import asyncio
from langchain_0g import ZGChat
async def main():
chat = ZGChat(provider="0xf07240Efa67755B5311bc75784a061eDB47165Dd")
response = await chat.ainvoke("Hi!")
print(response)
asyncio.run(main())
LLM (Legacy)
ZGLLM refers to legacy text-completion models hosted on 0G.ai.
from langchain_0g import ZGLLM
llm = ZGLLM(provider="0xf07240Efa67755B5311bc75784a061eDB47165Dd")
text = llm.invoke("Summarize the following article...")
print(text)
providerspecifies the 0G.ai model.- Use
private_keyto sign requests via your wallet.
List available models
from langchain_0g import ZGChat
llm = ZGChat(provider="0xf07240Efa67755B5311bc75784a061eDB47165Dd")
print(llm.zg_client.get_all_services())
Notes
- 0G.ai clients (
clientandasync_client) handle authentication using your wallet private key instead of traditional OpenAI API keys. - The ENS
provideridentifies which LLM to query. - All requests go through 0G.ai smart contracts for on-chain verification.
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 langchain_0g-0.1.0.tar.gz.
File metadata
- Download URL: langchain_0g-0.1.0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2f413efa2e52e32e3c85af73cbd148db5619c36c95f92181b108df39a0b4c16
|
|
| MD5 |
7725bf465a42a0341a6d7256dec88286
|
|
| BLAKE2b-256 |
f08486cda6f40cea10ea5b9b1da8fa1ae745688921bd154b7584273d2101fbcb
|
File details
Details for the file langchain_0g-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_0g-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2aaafb1b646e9989d04d6c79519f83cfca698951356650a5a0d58acae6b75f23
|
|
| MD5 |
5db6518cef44b64057a31f859659dcc8
|
|
| BLAKE2b-256 |
a176f69ab884397b538429f4e9fbbadb03c695f8a4e108864ee64816a3d72039
|