Skip to main content

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)
  • provider is the ENS address of the 0G.ai model.
  • private_key is optional if you have A0G_PRIVATE_KEY in 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)
  • provider specifies the 0G.ai model.
  • Use private_key to 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 (client and async_client) handle authentication using your wallet private key instead of traditional OpenAI API keys.
  • The ENS provider identifies which LLM to query.
  • All requests go through 0G.ai smart contracts for on-chain verification.

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_0g-0.1.0.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_0g-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

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

Hashes for langchain_0g-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b2f413efa2e52e32e3c85af73cbd148db5619c36c95f92181b108df39a0b4c16
MD5 7725bf465a42a0341a6d7256dec88286
BLAKE2b-256 f08486cda6f40cea10ea5b9b1da8fa1ae745688921bd154b7584273d2101fbcb

See more details on using hashes here.

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

Hashes for langchain_0g-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2aaafb1b646e9989d04d6c79519f83cfca698951356650a5a0d58acae6b75f23
MD5 5db6518cef44b64057a31f859659dcc8
BLAKE2b-256 a176f69ab884397b538429f4e9fbbadb03c695f8a4e108864ee64816a3d72039

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