Skip to content

Commit b1f61e3

Browse files
author
zeyuyuyu
committed
Merge remote-tracking branch 'origin/main' into feature/storage-first-flow-v2
# Conflicts: # cli.commonjs/cli/fine-tuning.d.ts.map # cli.commonjs/cli/fine-tuning.js # cli.commonjs/cli/fine-tuning.js.map # cli.commonjs/cli/inference.d.ts.map # cli.commonjs/cli/inference.js # cli.commonjs/cli/inference.js.map # cli.commonjs/cli/ledger.d.ts.map # cli.commonjs/cli/util.d.ts.map # cli.commonjs/sdk/common/utils/index.d.ts # cli.commonjs/sdk/common/utils/index.d.ts.map # cli.commonjs/sdk/common/utils/index.js # cli.commonjs/sdk/common/utils/index.js.map # cli.commonjs/sdk/fine-tuning/broker/broker.d.ts # cli.commonjs/sdk/fine-tuning/broker/broker.d.ts.map # cli.commonjs/sdk/fine-tuning/broker/broker.js # cli.commonjs/sdk/fine-tuning/broker/broker.js.map # cli.commonjs/sdk/fine-tuning/broker/dataset.d.ts # cli.commonjs/sdk/fine-tuning/broker/dataset.d.ts.map # cli.commonjs/sdk/fine-tuning/broker/dataset.js # cli.commonjs/sdk/fine-tuning/broker/dataset.js.map # cli.commonjs/sdk/fine-tuning/broker/model.d.ts # cli.commonjs/sdk/fine-tuning/broker/model.d.ts.map # cli.commonjs/sdk/fine-tuning/broker/model.js # cli.commonjs/sdk/fine-tuning/broker/model.js.map # cli.commonjs/sdk/fine-tuning/zg-storage/zg-storage.d.ts # cli.commonjs/sdk/fine-tuning/zg-storage/zg-storage.d.ts.map # cli.commonjs/sdk/fine-tuning/zg-storage/zg-storage.js # cli.commonjs/sdk/fine-tuning/zg-storage/zg-storage.js.map # cli.commonjs/sdk/inference/broker/broker.d.ts.map # cli.commonjs/sdk/ledger/broker.d.ts.map # lib.commonjs/common/utils/index.d.ts # lib.commonjs/common/utils/index.d.ts.map # lib.commonjs/common/utils/index.js # lib.commonjs/common/utils/index.js.map # lib.commonjs/fine-tuning/broker/broker.d.ts # lib.commonjs/fine-tuning/broker/broker.d.ts.map # lib.commonjs/fine-tuning/broker/broker.js # lib.commonjs/fine-tuning/broker/broker.js.map # lib.commonjs/fine-tuning/broker/dataset.d.ts # lib.commonjs/fine-tuning/broker/dataset.d.ts.map # lib.commonjs/fine-tuning/broker/dataset.js # lib.commonjs/fine-tuning/broker/dataset.js.map # lib.commonjs/fine-tuning/broker/model.d.ts # lib.commonjs/fine-tuning/broker/model.d.ts.map # lib.commonjs/fine-tuning/broker/model.js # lib.commonjs/fine-tuning/broker/model.js.map # lib.commonjs/fine-tuning/zg-storage/zg-storage.d.ts # lib.commonjs/fine-tuning/zg-storage/zg-storage.d.ts.map # lib.commonjs/fine-tuning/zg-storage/zg-storage.js # lib.commonjs/fine-tuning/zg-storage/zg-storage.js.map # lib.commonjs/inference/broker/broker.d.ts.map # lib.commonjs/ledger/broker.d.ts.map # lib.esm/_commonjsHelpers-0f3c985d.js # lib.esm/adm-zip-0609067e.js # lib.esm/adm-zip-0609067e.js.map # lib.esm/browser-0fd4d439.js # lib.esm/browser-0fd4d439.js.map # lib.esm/common/utils/index.d.ts # lib.esm/common/utils/index.d.ts.map # lib.esm/fine-tuning/broker/broker.d.ts # lib.esm/fine-tuning/broker/broker.d.ts.map # lib.esm/fine-tuning/broker/dataset.d.ts # lib.esm/fine-tuning/broker/dataset.d.ts.map # lib.esm/fine-tuning/broker/model.d.ts # lib.esm/fine-tuning/broker/model.d.ts.map # lib.esm/fine-tuning/zg-storage/zg-storage.d.ts # lib.esm/fine-tuning/zg-storage/zg-storage.d.ts.map # lib.esm/index-291e4713.js # lib.esm/index.d.ts # lib.esm/index.mjs # lib.esm/inference/broker/broker.d.ts.map # lib.esm/ledger/broker.d.ts.map # src.ts/cli/fine-tuning.ts # src.ts/sdk/fine-tuning/broker/dataset.ts # src.ts/sdk/fine-tuning/broker/model.ts # src.ts/sdk/fine-tuning/zg-storage/zg-storage.ts # types/common/utils/index.d.ts # types/common/utils/index.d.ts.map # types/fine-tuning/broker/broker.d.ts # types/fine-tuning/broker/broker.d.ts.map # types/fine-tuning/broker/dataset.d.ts # types/fine-tuning/broker/dataset.d.ts.map # types/fine-tuning/broker/model.d.ts # types/fine-tuning/broker/model.d.ts.map # types/fine-tuning/zg-storage/zg-storage.d.ts # types/fine-tuning/zg-storage/zg-storage.d.ts.map # types/inference/broker/broker.d.ts.map # types/ledger/broker.d.ts.map
2 parents 9d3e8ad + 20716c8 commit b1f61e3

File tree

1,057 files changed

+5578
-134031
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,057 files changed

+5578
-134031
lines changed

.github/workflows/cli-test.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ jobs:
4848
pnpm install --frozen-lockfile
4949
pnpm build
5050
pnpm pack
51+
52+
- name: Run CLI integration tests
53+
run: pnpm test:cli
54+
timeout-minutes: 10
5155

5256
- name: Setup test environment
5357
run: |
@@ -86,16 +90,44 @@ jobs:
8690
# Test CLI commands using local binary
8791
if [ -f "./node_modules/.bin/0g-compute-cli" ]; then
8892
# npm/yarn classic with node_modules/.bin
93+
echo "Testing basic CLI commands..."
8994
./node_modules/.bin/0g-compute-cli --version
9095
./node_modules/.bin/0g-compute-cli --help
9196
./node_modules/.bin/0g-compute-cli inference --help
9297
./node_modules/.bin/0g-compute-cli show-network || echo "Network command tested"
98+
99+
echo "Testing authentication-free commands..."
100+
echo "→ Testing inference list-providers (no auth required)"
101+
./node_modules/.bin/0g-compute-cli inference list-providers --rpc https://evmrpc-testnet.0g.ai
102+
103+
echo "→ Testing inference list-providers-detail (no auth required)"
104+
./node_modules/.bin/0g-compute-cli inference list-providers-detail --rpc https://evmrpc-testnet.0g.ai
105+
106+
echo "→ Testing fine-tuning list-providers (no auth required)"
107+
./node_modules/.bin/0g-compute-cli fine-tuning list-providers --rpc https://evmrpc-testnet.0g.ai
108+
109+
echo "→ Testing fine-tuning list-models (no auth required)"
110+
./node_modules/.bin/0g-compute-cli fine-tuning list-models --rpc https://evmrpc-testnet.0g.ai
93111
elif [ "${{ matrix.pkg-manager }}" = "yarn" ]; then
94112
# yarn 4+ with PnP mode
113+
echo "Testing basic CLI commands..."
95114
yarn run 0g-compute-cli --version
96115
yarn run 0g-compute-cli --help
97116
yarn run 0g-compute-cli inference --help
98117
yarn run 0g-compute-cli show-network || echo "Network command tested"
118+
119+
echo "Testing authentication-free commands..."
120+
echo "→ Testing inference list-providers (no auth required)"
121+
yarn run 0g-compute-cli inference list-providers --rpc https://evmrpc-testnet.0g.ai
122+
123+
echo "→ Testing inference list-providers-detail (no auth required)"
124+
yarn run 0g-compute-cli inference list-providers-detail --rpc https://evmrpc-testnet.0g.ai
125+
126+
echo "→ Testing fine-tuning list-providers (no auth required)"
127+
yarn run 0g-compute-cli fine-tuning list-providers --rpc https://evmrpc-testnet.0g.ai
128+
129+
echo "→ Testing fine-tuning list-models (no auth required)"
130+
yarn run 0g-compute-cli fine-tuning list-models --rpc https://evmrpc-testnet.0g.ai
99131
else
100132
echo "CLI binary not found"
101133
exit 1

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ node_modules
77
token_counter
88
token_counter.*
99

10+
# Build outputs (generated files)
11+
lib.commonjs/
12+
lib.esm/
13+
cli.commonjs/
14+
types/
15+
1016
# Next.js build outputs
1117
.next
1218
out
@@ -19,3 +25,4 @@ ack_tee.cjs
1925
*.secret.cjs
2026

2127
.pnpm-store
28+
.vscode/

README.md

Lines changed: 93 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ Access decentralized AI computing through the 0G Compute Network - a GPU marketp
44

55
## Features
66

7-
- **AI Inference**: Run LLMs, text-to-image, and speech-to-text models
7+
- **AI Inference**: Run LLMs, text-to-image, image editing, and speech-to-text models — with both sync and async modes
88
- **Fine-tuning**: Customize models with your own data
99
- **OpenAI Compatible**: Works with existing OpenAI SDK clients
1010
- **Web UI**: Built-in interface for easy service discovery and testing
1111
- **CLI Tools**: Command-line interface for automation
1212

1313
## Requirements
1414

15-
- Node.js >= 22.0.0
15+
- Node.js >= 20.0.0
1616
- A wallet with 0G tokens
1717

1818
## Installation
@@ -43,6 +43,7 @@ The fastest way to get started:
4343
```
4444

4545
Open `http://localhost:3090` in your browser to:
46+
4647
- Connect your wallet (MetaMask)
4748
- Browse available AI services
4849
- Chat with AI models directly
@@ -79,56 +80,104 @@ Open `http://localhost:3090` in your browser to:
7980
### SDK
8081

8182
```typescript
82-
import { ethers } from "ethers";
83-
import { createZGComputeNetworkBroker } from "@0glabs/0g-serving-broker";
83+
import { ethers } from 'ethers'
84+
import { createZGComputeNetworkBroker } from '@0glabs/0g-serving-broker'
8485

8586
// Initialize
86-
const provider = new ethers.JsonRpcProvider("https://evmrpc-testnet.0g.ai");
87-
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);
88-
const broker = await createZGComputeNetworkBroker(wallet);
87+
const provider = new ethers.JsonRpcProvider('https://evmrpc-testnet.0g.ai')
88+
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider)
89+
const broker = await createZGComputeNetworkBroker(wallet)
8990

9091
// Discover services
91-
const services = await broker.inference.listService();
92+
const services = await broker.inference.listService()
9293

9394
// Fund your account
94-
await broker.ledger.depositFund(10);
95+
await broker.ledger.depositFund(10)
9596

9697
// Acknowledge provider
97-
await broker.inference.acknowledgeProviderSigner(providerAddress);
98+
await broker.inference.acknowledgeProviderSigner(providerAddress)
9899

99100
// Get service metadata
100-
const { endpoint, model } = await broker.inference.getServiceMetadata(providerAddress);
101+
const { endpoint, model } =
102+
await broker.inference.getServiceMetadata(providerAddress)
101103

102104
// Generate auth headers
103-
const headers = await broker.inference.getRequestHeaders(providerAddress);
105+
const headers = await broker.inference.getRequestHeaders(providerAddress)
104106

105107
// Make request (OpenAI compatible)
106108
const response = await fetch(`${endpoint}/chat/completions`, {
107-
method: "POST",
108-
headers: { "Content-Type": "application/json", ...headers },
109-
body: JSON.stringify({
109+
method: 'POST',
110+
headers: { 'Content-Type': 'application/json', ...headers },
111+
body: JSON.stringify({
112+
model,
113+
messages: [{ role: 'user', content: 'Hello!' }],
114+
}),
115+
})
116+
117+
// Or make async request (support images-generations and images-edits)
118+
119+
// Async endpoints live under /v1/async instead of /v1/proxy
120+
const asyncBase = endpoint.replace('/v1/proxy', '/v1/async')
121+
const requestBody = {
110122
model,
111-
messages: [{ role: "user", content: "Hello!" }]
112-
})
113-
});
123+
prompt: 'A cute baby sea otter',
124+
n: 1,
125+
size: '512x512',
126+
response_format: 'b64_json',
127+
}
128+
129+
// Step 1 — submit the job
130+
const submitHeaders = await broker.inference.getRequestHeaders(
131+
providerAddress,
132+
JSON.stringify(requestBody)
133+
)
134+
const submitRes = await fetch(`${asyncBase}/images/generations`, {
135+
method: 'POST',
136+
headers: { 'Content-Type': 'application/json', ...submitHeaders },
137+
body: JSON.stringify(requestBody),
138+
})
139+
// 202 Accepted → { jobId: "uuid", status: "pending" }
140+
const { jobId } = await submitRes.json()
141+
142+
// Step 2 — poll until done
143+
let job
144+
do {
145+
const retryAfter = job?.retryAfter ?? 5
146+
await new Promise((r) => setTimeout(r, retryAfter * 1000))
147+
148+
const pollHeaders =
149+
await broker.inference.getRequestHeaders(providerAddress)
150+
const pollRes = await fetch(`${asyncBase}/jobs/${jobId}`, {
151+
headers: pollHeaders,
152+
})
153+
const retryAfterHeader = pollRes.headers.get('Retry-After')
154+
job = {
155+
...(await pollRes.json()),
156+
retryAfter: retryAfterHeader ? Number(retryAfterHeader) : 5,
157+
}
158+
} while (job.status === 'pending' || job.status === 'processing')
159+
160+
if (job.status === 'failed') throw new Error(job.errorMessage)
161+
162+
// job.data — raw provider response, e.g. { data: [{ b64_json: "..." }] }
114163
```
115164

116165
## Direct API Access
117166

118167
After obtaining a secret with `0g-compute-cli inference get-secret`, use any OpenAI-compatible client:
119168

120169
```typescript
121-
import OpenAI from 'openai';
170+
import OpenAI from 'openai'
122171

123172
const client = new OpenAI({
124-
baseURL: `${serviceUrl}/v1/proxy`,
125-
apiKey: 'app-sk-<YOUR_SECRET>'
126-
});
173+
baseURL: `${serviceUrl}/v1/proxy`,
174+
apiKey: 'app-sk-<YOUR_SECRET>',
175+
})
127176

128177
const completion = await client.chat.completions.create({
129-
model: 'model-name',
130-
messages: [{ role: 'user', content: 'Hello!' }]
131-
});
178+
model: 'model-name',
179+
messages: [{ role: 'user', content: 'Hello!' }],
180+
})
132181
```
133182

134183
## Account Management
@@ -214,11 +263,11 @@ Service providers can manage their deployed containers and configurations remote
214263

215264
The controller manages three types of configurations:
216265

217-
| Type | Description | Format |
218-
|------|-------------|--------|
219-
| `core` | Broker + Event shared config | YAML |
220-
| `ingress` | Nginx ingress environment variables | JSON |
221-
| `prometheus` | Prometheus monitoring config | YAML (auto base64 encoded) |
266+
| Type | Description | Format |
267+
| ------------ | ----------------------------------- | -------------------------- |
268+
| `core` | Broker + Event shared config | YAML |
269+
| `ingress` | Nginx ingress environment variables | JSON |
270+
| `prometheus` | Prometheus monitoring config | YAML (auto base64 encoded) |
222271

223272
```bash
224273
# Get configuration
@@ -265,10 +314,10 @@ The controller manages three types of configurations:
265314

266315
## Network Configuration
267316

268-
| Network | RPC Endpoint |
269-
|---------|--------------|
317+
| Network | RPC Endpoint |
318+
| ------- | ---------------------------- |
270319
| Testnet | https://evmrpc-testnet.0g.ai |
271-
| Mainnet | https://evmrpc.0g.ai |
320+
| Mainnet | https://evmrpc.0g.ai |
272321

273322
## Browser Usage
274323

@@ -280,21 +329,22 @@ pnpm add -D vite-plugin-node-polyfills
280329

281330
```javascript
282331
// vite.config.js
283-
import { nodePolyfills } from 'vite-plugin-node-polyfills';
332+
import { nodePolyfills } from 'vite-plugin-node-polyfills'
284333

285334
export default {
286-
plugins: [
287-
nodePolyfills({
288-
include: ['crypto', 'stream', 'util', 'buffer', 'process'],
289-
globals: { Buffer: true, global: true, process: true }
290-
})
291-
]
292-
};
335+
plugins: [
336+
nodePolyfills({
337+
include: ['crypto', 'stream', 'util', 'buffer', 'process'],
338+
globals: { Buffer: true, global: true, process: true },
339+
}),
340+
],
341+
}
293342
```
294343

295344
## Troubleshooting
296345

297346
### Insufficient Balance
347+
298348
```bash
299349
# Check which account needs funds
300350
0g-compute-cli get-account
@@ -307,11 +357,13 @@ export default {
307357
```
308358

309359
### Provider Not Acknowledged
360+
310361
```bash
311362
0g-compute-cli inference acknowledge-provider --provider <PROVIDER_ADDRESS>
312363
```
313364

314365
### Web UI Port Conflict
366+
315367
```bash
316368
0g-compute-cli ui start-web --port 3091
317369
```
@@ -322,5 +374,3 @@ export default {
322374
- [Inference Guide](https://docs.0g.ai/developer-hub/building-on-0g/compute-network/inference)
323375
- [Fine-tuning Guide](https://docs.0g.ai/developer-hub/building-on-0g/compute-network/fine-tuning)
324376
- [Account Management](https://docs.0g.ai/developer-hub/building-on-0g/compute-network/account-management)
325-
326-

cli.commonjs/cli/__tests__/cli.integration.test.d.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

cli.commonjs/cli/__tests__/cli.integration.test.d.ts.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)