From d8ae2e4f96242a531f6f5a4b9c39e0fba73821ca Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 9 Jul 2025 08:16:47 +0800 Subject: [PATCH 1/2] feat: enhance SDK documentation with CLI quick start and improved structure - Add CLI quick start guide with installation and usage instructions - Rename section from 'SDK Usage' to 'Getting Started with 0G Serving SDK' - Reorganize content with clear sections for CLI and programmatic usage - Add comprehensive troubleshooting section --- .../building-on-0g/compute-network/sdk.md | 115 ++++++++++++++++-- 1 file changed, 108 insertions(+), 7 deletions(-) diff --git a/docs/developer-hub/building-on-0g/compute-network/sdk.md b/docs/developer-hub/building-on-0g/compute-network/sdk.md index f834313a..7e77f9a8 100644 --- a/docs/developer-hub/building-on-0g/compute-network/sdk.md +++ b/docs/developer-hub/building-on-0g/compute-network/sdk.md @@ -1,26 +1,97 @@ --- id: sdk -title: Inference SDK +title: Inference & CLI Tools sidebar_position: 3 --- import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; -# 0G Compute SDK +# 0G Compute Network Tools + +The 0G Compute Network provides multiple ways to interact with inference services. You can use the CLI for quick setup and testing, or integrate the SDK for programmatic access in your applications. + +## Quick Start (CLI) + +The 0G Compute CLI (`0g-compute-cli`) provides a command-line interface for quickly setting up and using inference services. This is the fastest way to get started with 0G Compute Network. + +### Prerequisites + +- Node.js 18+ and pnpm installed +- A wallet with some ETH for gas fees +- Access to an Ethereum RPC endpoint + +### Installation + +```bash +# Install the CLI globally +pnpm install -g @0glabs/0g-serving-broker + +# Note: If you encounter chalk@5 compatibility issues, run: +pnpm add -g chalk@4 +``` + +### Create Account and Add Funds + +1. **Set up environment variables:** +```bash +export LEDGER_CA=0x8A791620dd6260079BF849Dc5567aDC3F2FdC318 +export FINE_TUNING_CA=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 +export INFERENCE_CA=0x0165878A594ca255338adfa4d48449f69242Eb8F +export RPC_ENDPOINT=http://localhost:8545 +export ZG_PRIVATE_KEY=your_private_key_here +``` + +2. **Create an account:** +```bash +0g-compute-cli add-account --amount 1 +``` + +3. **Add funds to your account:** +```bash +0g-compute-cli deposit --amount 0.5 +``` + +### Start Local Inference Service + +Use the CLI to start a local inference service that connects to the 0G Compute Network: + +```bash +0g-compute-cli serve \ + --provider 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 \ + --ledger-ca=0x8A791620dd6260079BF849Dc5567aDC3F2FdC318 \ + --inference-ca=0x0165878A594ca255338adfa4d48449f69242Eb8F \ + --rpc=http://localhost:8545 \ + --key=your_private_key_here +``` + +### Available CLI Commands + +- `add-account`: Create a new account +- `deposit`: Add funds to your account +- `serve`: Start local inference service +- `list-models`: List available models +- `get-account`: Retrieve account information +- `list-providers`: List available providers + +For a complete list of commands: +```bash +0g-compute-cli --help +``` + +## Programmatic Usage (SDK) The 0G Compute Network SDK enables developers to integrate AI inference services from the 0G Compute Network into their applications. Currently, the 0G Compute Network SDK supports Large Language Model (LLM) inference services, with fine-tuning and additional features planned for future releases. In just five minutes, you can initialize your broker to manage operations, set up and fund your account to pay for inference services, and learn how to send inference requests and handle responses. -## Quick Start - ### Installation ```bash pnpm add @0glabs/0g-serving-broker @types/crypto-js@4.2.2 crypto-js@4.2.0 ``` -## Core Concepts + +### Core Concepts ### 1. The Broker Your interface to the 0G Compute Network: @@ -39,7 +110,7 @@ GPU owners offering AI services: - Automatic micropayments - No surprise bills -## Step-by-Step Guide +### Step-by-Step Guide ### Initialize the Broker @@ -226,7 +297,37 @@ await broker.ledger.retrieveFund("inference", amount); ## Troubleshooting -### Common Issues +### CLI Issues + +
+Error: Chalk compatibility issue + +If you encounter this error: +``` +Error [ERR_REQUIRE_ESM]: require() of ES Module chalk@5.x +``` + +**Solution**: Install chalk@4 globally +```bash +pnpm add -g chalk@4 +``` +
+ +
+Error: CLI command not found + +Make sure the CLI is installed globally: +```bash +pnpm install -g @0glabs/0g-serving-broker +``` + +If using npm: +```bash +npm install -g @0glabs/0g-serving-broker +``` +
+ +### SDK Issues
Error: Insufficient balance From f13fe46e253d1760076cf503267c5b218bfc46dc Mon Sep 17 00:00:00 2001 From: Richard Date: Tue, 15 Jul 2025 07:43:57 +0800 Subject: [PATCH 2/2] docs: enhance SDK documentation with simplified CLI setup and improved structure --- .../building-on-0g/compute-network/sdk.md | 48 +++++-------------- 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/docs/developer-hub/building-on-0g/compute-network/sdk.md b/docs/developer-hub/building-on-0g/compute-network/sdk.md index 7e77f9a8..9fb0fece 100644 --- a/docs/developer-hub/building-on-0g/compute-network/sdk.md +++ b/docs/developer-hub/building-on-0g/compute-network/sdk.md @@ -13,48 +13,28 @@ The 0G Compute Network provides multiple ways to interact with inference service ## Quick Start (CLI) -The 0G Compute CLI (`0g-compute-cli`) provides a command-line interface for quickly setting up and using inference services. This is the fastest way to get started with 0G Compute Network. - -### Prerequisites - -- Node.js 18+ and pnpm installed -- A wallet with some ETH for gas fees -- Access to an Ethereum RPC endpoint +The 0G Compute CLI provides a simple way to get started with inference services in just a few steps. ### Installation ```bash -# Install the CLI globally pnpm install -g @0glabs/0g-serving-broker - -# Note: If you encounter chalk@5 compatibility issues, run: -pnpm add -g chalk@4 ``` -### Create Account and Add Funds +### Step 1: Add Funds -1. **Set up environment variables:** -```bash -export LEDGER_CA=0x8A791620dd6260079BF849Dc5567aDC3F2FdC318 -export FINE_TUNING_CA=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 -export INFERENCE_CA=0x0165878A594ca255338adfa4d48449f69242Eb8F -export RPC_ENDPOINT=http://localhost:8545 -export ZG_PRIVATE_KEY=your_private_key_here -``` +> **Note:** For normal use on the 0G testnet, you only need to set your private key as an environment variable. All other parameters are pre-configured for the testnet. -2. **Create an account:** ```bash -0g-compute-cli add-account --amount 1 -``` +export ZG_PRIVATE_KEY=your_private_key -3. **Add funds to your account:** -```bash +# Add funds to your account 0g-compute-cli deposit --amount 0.5 ``` ### Start Local Inference Service -Use the CLI to start a local inference service that connects to the 0G Compute Network: +### Step 2: Start Service ```bash 0g-compute-cli serve \ @@ -65,19 +45,15 @@ Use the CLI to start a local inference service that connects to the 0G Compute N --key=your_private_key_here ``` -### Available CLI Commands +That's it! Your inference service is now running and ready to accept requests. + +### Available Commands -- `add-account`: Create a new account -- `deposit`: Add funds to your account +- `deposit --amount `: Add funds to your account - `serve`: Start local inference service - `list-models`: List available models -- `get-account`: Retrieve account information -- `list-providers`: List available providers - -For a complete list of commands: -```bash -0g-compute-cli --help -``` +- `get-account`: Check account balance +- `--help`: Show all available commands ## Programmatic Usage (SDK)