0g-orbit 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -0
- package/LICENSE +21 -0
- package/README.md +151 -0
- package/dist/cli/cli.js +1 -1
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +23 -1
- package/dist/storage.js.map +1 -1
- package/package.json +28 -4
- package/examples/ai-chatbot/index.ts +0 -74
- package/examples/model-registry/index.ts +0 -137
- package/examples/quick-start/index.ts +0 -65
- package/packages/cli/package.json +0 -30
- package/packages/cli/src/cli.ts +0 -69
- package/packages/cli/src/commands/account.ts +0 -29
- package/packages/cli/src/commands/inference.ts +0 -103
- package/packages/cli/src/commands/init.ts +0 -71
- package/packages/cli/src/commands/storage.ts +0 -91
- package/packages/cli/src/utils.ts +0 -21
- package/packages/cli/tsconfig.json +0 -8
- package/packages/core/package.json +0 -35
- package/packages/core/src/errors.test.ts +0 -99
- package/packages/core/src/errors.ts +0 -79
- package/packages/core/src/index.ts +0 -37
- package/packages/core/src/inference.ts +0 -256
- package/packages/core/src/networks.test.ts +0 -62
- package/packages/core/src/networks.ts +0 -62
- package/packages/core/src/orbit.test.ts +0 -153
- package/packages/core/src/orbit.ts +0 -159
- package/packages/core/src/retry.test.ts +0 -99
- package/packages/core/src/retry.ts +0 -99
- package/packages/core/src/storage.test.ts +0 -199
- package/packages/core/src/storage.ts +0 -158
- package/packages/core/src/types.ts +0 -85
- package/packages/core/tsconfig.json +0 -8
- package/packages/core/vitest.config.ts +0 -7
- package/src/cli/cli.ts +0 -95
- package/src/cli/commands/account.ts +0 -29
- package/src/cli/commands/fine-tuning.ts +0 -169
- package/src/cli/commands/inference.ts +0 -103
- package/src/cli/commands/init.ts +0 -71
- package/src/cli/commands/storage.ts +0 -91
- package/src/cli/utils.ts +0 -21
- package/src/errors.test.ts +0 -99
- package/src/errors.ts +0 -90
- package/src/fine-tuning.test.ts +0 -299
- package/src/fine-tuning.ts +0 -330
- package/src/index.ts +0 -45
- package/src/inference.ts +0 -256
- package/src/networks.test.ts +0 -62
- package/src/networks.ts +0 -62
- package/src/orbit.test.ts +0 -153
- package/src/orbit.ts +0 -204
- package/src/retry.test.ts +0 -99
- package/src/retry.ts +0 -99
- package/src/storage.test.ts +0 -199
- package/src/storage.ts +0 -158
- package/src/types.ts +0 -157
- package/tsconfig.json +0 -20
- package/vitest.config.ts +0 -7
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.2.3] - 2026-04-05
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- **Storage dedup**: Skip re-uploading files that already exist on storage nodes (prevents retrieve regression)
|
|
12
|
+
- **Retrieve crash guard**: Catch SDK-internal null crashes and throw descriptive `StorageError` instead of raw `TypeError`
|
|
13
|
+
|
|
14
|
+
## [0.2.2] - 2026-04-04
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
- Version string synced across root, core, and CLI packages
|
|
18
|
+
|
|
19
|
+
## [0.2.1] - 2026-04-04
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- Added axios override recommendations to mitigate transitive vulnerabilities
|
|
23
|
+
|
|
24
|
+
## [0.2.0] - 2026-04-04
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
- **Fine-Tuning Support**: Full `FineTuningClient` with dataset upload, task management, and model download
|
|
28
|
+
- CLI commands: `orbit fine-tune`, `orbit tasks`, `orbit models`
|
|
29
|
+
- `FineTuningError` class with actionable suggestions
|
|
30
|
+
- 19 new tests for fine-tuning functionality (85 total tests passing)
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
- `Orbit` class now exposes `fineTuning` accessor and shortcut methods
|
|
34
|
+
|
|
35
|
+
## [0.1.0] - 2026-04-03
|
|
36
|
+
|
|
37
|
+
### Added
|
|
38
|
+
- Initial release
|
|
39
|
+
- `StorageClient` — file and data upload/download to 0G Storage
|
|
40
|
+
- `InferenceClient` — AI inference on 0G Compute Network
|
|
41
|
+
- `Orbit` unified class combining storage, inference, and chain operations
|
|
42
|
+
- CLI with `orbit store`, `orbit retrieve`, `orbit infer`, `orbit services`, `orbit status`, `orbit init`
|
|
43
|
+
- Automatic retry with exponential backoff for transient errors
|
|
44
|
+
- Testnet and mainnet network configurations
|
|
45
|
+
- 66 tests passing
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 cyber
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# 0G Orbit
|
|
2
|
+
|
|
3
|
+
The developer toolkit for [0G](https://0g.ai). Store, infer, fine-tune — one SDK, one CLI, five minutes.
|
|
4
|
+
|
|
5
|
+
[](https://github.com/cyber/0g-orbit/actions/workflows/ci.yml)
|
|
6
|
+
[](https://www.npmjs.com/package/0g-orbit)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
[](https://nodejs.org)
|
|
9
|
+
|
|
10
|
+
## What is this?
|
|
11
|
+
|
|
12
|
+
0G Orbit wraps the 0G storage SDK, serving broker, and chain interactions into a single unified interface. Instead of juggling `@0gfoundation/0g-ts-sdk`, `@0glabs/0g-serving-broker`, and raw ethers calls, you get one `Orbit` class and one `orbit` CLI.
|
|
13
|
+
|
|
14
|
+
**Storage** — Upload and download files to 0G's decentralized storage network
|
|
15
|
+
**Inference** — Run AI models on 0G's decentralized compute network
|
|
16
|
+
**Fine-Tuning** — Upload datasets, create training tasks, download fine-tuned models
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install 0g-orbit
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
### SDK
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { Orbit } from '0g-orbit'
|
|
30
|
+
|
|
31
|
+
const orbit = await Orbit.connect({
|
|
32
|
+
network: 'testnet',
|
|
33
|
+
privateKey: process.env.PRIVATE_KEY,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
// Upload a file
|
|
37
|
+
const { root, txHash } = await orbit.store('./data.json')
|
|
38
|
+
console.log(`Stored: ${root}`)
|
|
39
|
+
|
|
40
|
+
// Download it back
|
|
41
|
+
await orbit.retrieve(root, './downloaded.json')
|
|
42
|
+
|
|
43
|
+
// Run AI inference
|
|
44
|
+
const response = await orbit.infer('meta-llama/Llama-3.2-3B-Instruct', {
|
|
45
|
+
message: 'Explain zero-knowledge proofs in one sentence.',
|
|
46
|
+
})
|
|
47
|
+
console.log(response.content)
|
|
48
|
+
|
|
49
|
+
// Fine-tune a model
|
|
50
|
+
const dataset = await orbit.uploadDataset('./training-data.jsonl')
|
|
51
|
+
const task = await orbit.createFineTuneTask({
|
|
52
|
+
model: 'base-model',
|
|
53
|
+
dataset: dataset.root,
|
|
54
|
+
providerAddress: '0x...',
|
|
55
|
+
})
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### CLI
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Set your private key
|
|
62
|
+
export PRIVATE_KEY=0x...
|
|
63
|
+
|
|
64
|
+
# Upload a file
|
|
65
|
+
orbit store ./my-file.txt
|
|
66
|
+
|
|
67
|
+
# Download a file
|
|
68
|
+
orbit retrieve <rootHash> ./output.txt
|
|
69
|
+
|
|
70
|
+
# Run inference
|
|
71
|
+
orbit infer meta-llama/Llama-3.2-3B-Instruct -m "Hello, 0G!"
|
|
72
|
+
|
|
73
|
+
# List available AI services
|
|
74
|
+
orbit services
|
|
75
|
+
|
|
76
|
+
# Fine-tune a model
|
|
77
|
+
orbit fine-tune ./dataset.jsonl --model base-model --provider 0x...
|
|
78
|
+
|
|
79
|
+
# Check account status
|
|
80
|
+
orbit status
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## API
|
|
84
|
+
|
|
85
|
+
### `Orbit.connect(config)`
|
|
86
|
+
|
|
87
|
+
Creates a connected Orbit instance.
|
|
88
|
+
|
|
89
|
+
| Option | Type | Description |
|
|
90
|
+
|---|---|---|
|
|
91
|
+
| `network` | `'testnet' \| 'mainnet'` | Network to connect to |
|
|
92
|
+
| `privateKey` | `string?` | Wallet private key (falls back to `PRIVATE_KEY` env var) |
|
|
93
|
+
| `rpcUrl` | `string?` | Custom RPC URL |
|
|
94
|
+
|
|
95
|
+
### Storage
|
|
96
|
+
|
|
97
|
+
| Method | Description |
|
|
98
|
+
|---|---|
|
|
99
|
+
| `orbit.store(path, options?)` | Upload a file, returns `{ root, txHash }` |
|
|
100
|
+
| `orbit.storeData(text, options?)` | Upload a text string |
|
|
101
|
+
| `orbit.retrieve(rootHash, outputPath, options?)` | Download a file by root hash |
|
|
102
|
+
|
|
103
|
+
### Inference
|
|
104
|
+
|
|
105
|
+
| Method | Description |
|
|
106
|
+
|---|---|
|
|
107
|
+
| `orbit.infer(model, options)` | Run AI inference, returns `{ content, tokensUsed }` |
|
|
108
|
+
| `orbit.listServices()` | List available AI services on the network |
|
|
109
|
+
|
|
110
|
+
### Fine-Tuning
|
|
111
|
+
|
|
112
|
+
| Method | Description |
|
|
113
|
+
|---|---|
|
|
114
|
+
| `orbit.uploadDataset(path)` | Upload a training dataset to storage |
|
|
115
|
+
| `orbit.createFineTuneTask(options)` | Create a fine-tuning task |
|
|
116
|
+
| `orbit.getFineTuneTask(provider, taskId)` | Check task status |
|
|
117
|
+
| `orbit.downloadModel(provider, taskId, outputDir)` | Download a fine-tuned model |
|
|
118
|
+
| `orbit.listModels()` | List available base models |
|
|
119
|
+
| `orbit.listProviders()` | List fine-tuning providers |
|
|
120
|
+
|
|
121
|
+
### Direct Client Access
|
|
122
|
+
|
|
123
|
+
For advanced usage, access the underlying clients directly:
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
orbit.storage // StorageClient
|
|
127
|
+
orbit.inference // InferenceClient
|
|
128
|
+
orbit.fineTuning // FineTuningClient
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Security
|
|
132
|
+
|
|
133
|
+
This package has transitive dependencies with known vulnerabilities (from upstream 0G SDKs). To mitigate, add this to your project's `package.json`:
|
|
134
|
+
|
|
135
|
+
```json
|
|
136
|
+
{
|
|
137
|
+
"overrides": {
|
|
138
|
+
"axios": "1.14.0"
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
See [SECURITY.md](SECURITY.md) for details.
|
|
144
|
+
|
|
145
|
+
## Contributing
|
|
146
|
+
|
|
147
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
[MIT](LICENSE)
|
package/dist/cli/cli.js
CHANGED
package/dist/storage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAKpC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAO5E,qBAAa,aAAa;IACtB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,MAAM,CAAQ;gBAEV,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM;IAMlD;;;OAGG;IACG,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;IAkB/E;;;OAGG;IACG,SAAS,CACX,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,EAClC,OAAO,GAAE,YAAiB,GAC3B,OAAO,CAAC,WAAW,CAAC;YAUT,MAAM;
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAKpC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAO5E,qBAAa,aAAa;IACtB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,MAAM,CAAQ;gBAEV,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM;IAMlD;;;OAGG;IACG,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;IAkB/E;;;OAGG;IACG,SAAS,CACX,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,EAClC,OAAO,GAAE,YAAiB,GAC3B,OAAO,CAAC,WAAW,CAAC;YAUT,MAAM;IA0EpB;;OAEG;IACG,QAAQ,CACV,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,eAAoB,GAC9B,OAAO,CAAC,IAAI,CAAC;YAOF,SAAS;CA6B1B"}
|
package/dist/storage.js
CHANGED
|
@@ -59,6 +59,20 @@ export class StorageClient {
|
|
|
59
59
|
if (treeErr || !tree) {
|
|
60
60
|
throw new StorageError(`Failed to compute merkle tree: ${treeErr?.message ?? 'unknown error'}`, 'Ensure the file exists, is readable, and is not empty.');
|
|
61
61
|
}
|
|
62
|
+
// Skip upload if this exact file is already on storage nodes.
|
|
63
|
+
// Re-uploading finalized data creates a conflicting tx that breaks retrieval.
|
|
64
|
+
const rootHash = tree.rootHash();
|
|
65
|
+
if (rootHash) {
|
|
66
|
+
try {
|
|
67
|
+
const locations = await this.indexer.getFileLocations(rootHash);
|
|
68
|
+
if (locations && locations.length > 0) {
|
|
69
|
+
return { root: rootHash, txHash: '' };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// Location check failed — proceed with upload
|
|
74
|
+
}
|
|
75
|
+
}
|
|
62
76
|
// Always enable gas auto-escalation via the SDK's built-in retry.
|
|
63
77
|
// MaxGasPrice sets the ceiling — the SDK starts from the network estimate
|
|
64
78
|
// and bumps 10% on each retry until it hits this cap.
|
|
@@ -107,7 +121,15 @@ export class StorageClient {
|
|
|
107
121
|
return withRetry(() => this._retrieve(rootHash, outputPath, options), { maxAttempts: 3 });
|
|
108
122
|
}
|
|
109
123
|
async _retrieve(rootHash, outputPath, options) {
|
|
110
|
-
|
|
124
|
+
let err;
|
|
125
|
+
try {
|
|
126
|
+
err = await this.indexer.download(rootHash, outputPath, options.proof ?? false);
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
// Catch crashes from SDK internals (e.g. null getFileLocations)
|
|
130
|
+
const msg = e?.message ?? String(e);
|
|
131
|
+
throw new StorageError(`Download failed: ${msg}`, 'The file may not be fully replicated yet. Wait a moment and retry, or verify the root hash.');
|
|
132
|
+
}
|
|
111
133
|
if (err) {
|
|
112
134
|
const msg = err.message;
|
|
113
135
|
let suggestion = 'Verify the root hash is correct and the file was uploaded successfully.';
|
package/dist/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEzD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAExD,MAAM,gBAAgB,GAAG,CAAC,CAAA;AAC1B,MAAM,qBAAqB,GAAG,cAAc,CAAA,CAAC,iDAAiD;AAE9F,MAAM,OAAO,aAAa;IACd,OAAO,CAAS;IAChB,MAAM,CAAQ;I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QACrB,IAAI,CAAC;YACD,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAC7B,QAAQ,EACR,UAAU,EACV,OAAO,CAAC,KAAK,IAAI,KAAK,CACzB,CAAA;QACL,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YACd,gEAAgE;YAChE,MAAM,GAAG,GAAG,CAAC,EAAE,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,CAAA;YACnC,MAAM,IAAI,YAAY,CAClB,oBAAoB,GAAG,EAAE,EACzB,6FAA6F,CAChG,CAAA;QACL,CAAC;QACD,IAAI,GAAG,EAAE,CAAC;YACN,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAA;YACvB,IAAI,UAAU,GAAG,yEAAyE,CAAA;YAC1F,IAAI,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBACnD,UAAU,GAAG,oGAAoG,CAAA;YACrH,CAAC;YACD,MAAM,IAAI,YAAY,CAAC,oBAAoB,GAAG,EAAE,EAAE,UAAU,CAAC,CAAA;QACjE,CAAC;IACL,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "0g-orbit",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "The developer toolkit for 0G. Store, infer, deploy — one SDK, one CLI, five minutes.",
|
|
5
|
+
"author": "cyber",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/cyber/0g-orbit.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/cyber/0g-orbit#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/cyber/0g-orbit/issues"
|
|
14
|
+
},
|
|
5
15
|
"type": "module",
|
|
6
16
|
"main": "./dist/index.js",
|
|
7
17
|
"types": "./dist/index.d.ts",
|
|
@@ -14,12 +24,20 @@
|
|
|
14
24
|
"bin": {
|
|
15
25
|
"orbit": "./dist/cli/cli.js"
|
|
16
26
|
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE",
|
|
31
|
+
"CHANGELOG.md"
|
|
32
|
+
],
|
|
33
|
+
"sideEffects": false,
|
|
17
34
|
"scripts": {
|
|
18
35
|
"build": "tsc",
|
|
19
36
|
"test": "vitest run",
|
|
20
37
|
"test:watch": "vitest",
|
|
21
38
|
"lint": "tsc --noEmit",
|
|
22
|
-
"clean": "rm -rf dist"
|
|
39
|
+
"clean": "rm -rf dist",
|
|
40
|
+
"prepublishOnly": "npm run build"
|
|
23
41
|
},
|
|
24
42
|
"dependencies": {
|
|
25
43
|
"@0gfoundation/0g-ts-sdk": "^1.0.1",
|
|
@@ -36,17 +54,23 @@
|
|
|
36
54
|
},
|
|
37
55
|
"keywords": [
|
|
38
56
|
"0g",
|
|
57
|
+
"zero-gravity",
|
|
39
58
|
"blockchain",
|
|
40
59
|
"ai",
|
|
41
60
|
"storage",
|
|
42
61
|
"inference",
|
|
62
|
+
"fine-tuning",
|
|
43
63
|
"sdk",
|
|
44
|
-
"cli"
|
|
64
|
+
"cli",
|
|
65
|
+
"web3",
|
|
66
|
+
"decentralized"
|
|
45
67
|
],
|
|
46
|
-
"license": "MIT",
|
|
47
68
|
"engines": {
|
|
48
69
|
"node": ">=18.0.0"
|
|
49
70
|
},
|
|
71
|
+
"publishConfig": {
|
|
72
|
+
"access": "public"
|
|
73
|
+
},
|
|
50
74
|
"overrides": {
|
|
51
75
|
"axios": "1.14.0",
|
|
52
76
|
"open-jsonrpc-provider": {
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 0G Orbit — AI Chatbot Example
|
|
3
|
-
*
|
|
4
|
-
* A simple interactive chatbot using 0G Compute Network.
|
|
5
|
-
* Demonstrates multi-turn conversations with TEE verification.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* PRIVATE_KEY=0x... npx tsx index.ts
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { Orbit } from '@0g-orbit/core'
|
|
12
|
-
import { createInterface } from 'node:readline'
|
|
13
|
-
|
|
14
|
-
const MODEL = 'meta-llama/Llama-3.3-70B'
|
|
15
|
-
|
|
16
|
-
async function main() {
|
|
17
|
-
const orbit = await Orbit.connect({
|
|
18
|
-
network: 'testnet',
|
|
19
|
-
privateKey: process.env.PRIVATE_KEY!,
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
const status = await orbit.status()
|
|
23
|
-
console.log(`Connected: ${status.address} (${status.balance} OG)`)
|
|
24
|
-
console.log(`Model: ${MODEL}`)
|
|
25
|
-
console.log('Type "quit" to exit.\n')
|
|
26
|
-
|
|
27
|
-
const history: Array<{ role: 'system' | 'user' | 'assistant'; content: string }> = [
|
|
28
|
-
{
|
|
29
|
-
role: 'system',
|
|
30
|
-
content: 'You are a helpful AI assistant running on 0G decentralized compute. Be concise.',
|
|
31
|
-
},
|
|
32
|
-
]
|
|
33
|
-
|
|
34
|
-
const rl = createInterface({
|
|
35
|
-
input: process.stdin,
|
|
36
|
-
output: process.stdout,
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
const ask = (prompt: string): Promise<string> =>
|
|
40
|
-
new Promise((resolve) => rl.question(prompt, resolve))
|
|
41
|
-
|
|
42
|
-
while (true) {
|
|
43
|
-
const input = await ask('You: ')
|
|
44
|
-
if (input.toLowerCase() === 'quit') break
|
|
45
|
-
if (!input.trim()) continue
|
|
46
|
-
|
|
47
|
-
history.push({ role: 'user', content: input })
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
const result = await orbit.infer(MODEL, {
|
|
51
|
-
messages: history,
|
|
52
|
-
temperature: 0.7,
|
|
53
|
-
maxTokens: 1024,
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
history.push({ role: 'assistant', content: result.content })
|
|
57
|
-
|
|
58
|
-
console.log(`\nAssistant: ${result.content}`)
|
|
59
|
-
|
|
60
|
-
const meta: string[] = []
|
|
61
|
-
if (result.usage) meta.push(`${result.usage.totalTokens} tokens`)
|
|
62
|
-
if (result.verified === true) meta.push('TEE verified')
|
|
63
|
-
if (meta.length) console.log(` (${meta.join(' | ')})`)
|
|
64
|
-
console.log()
|
|
65
|
-
} catch (err) {
|
|
66
|
-
console.error(`Error: ${err instanceof Error ? err.message : err}\n`)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
rl.close()
|
|
71
|
-
console.log('Goodbye!')
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
main().catch(console.error)
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 0G Orbit — Model Registry Example
|
|
3
|
-
*
|
|
4
|
-
* Store AI model weights on 0G Storage and maintain
|
|
5
|
-
* a registry of model versions with their root hashes.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* PRIVATE_KEY=0x... npx tsx index.ts
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { Orbit } from '@0g-orbit/core'
|
|
12
|
-
import { writeFileSync, readFileSync, existsSync } from 'node:fs'
|
|
13
|
-
|
|
14
|
-
const REGISTRY_FILE = './registry.json'
|
|
15
|
-
|
|
16
|
-
interface ModelEntry {
|
|
17
|
-
name: string
|
|
18
|
-
version: string
|
|
19
|
-
rootHash: string
|
|
20
|
-
txHash: string
|
|
21
|
-
uploadedAt: string
|
|
22
|
-
sizeBytes?: number
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface Registry {
|
|
26
|
-
models: ModelEntry[]
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function loadRegistry(): Registry {
|
|
30
|
-
if (existsSync(REGISTRY_FILE)) {
|
|
31
|
-
return JSON.parse(readFileSync(REGISTRY_FILE, 'utf-8'))
|
|
32
|
-
}
|
|
33
|
-
return { models: [] }
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function saveRegistry(registry: Registry) {
|
|
37
|
-
writeFileSync(REGISTRY_FILE, JSON.stringify(registry, null, 2) + '\n')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async function registerModel(
|
|
41
|
-
orbit: Orbit,
|
|
42
|
-
name: string,
|
|
43
|
-
version: string,
|
|
44
|
-
filePath: string
|
|
45
|
-
) {
|
|
46
|
-
console.log(`\nUploading ${name} v${version}...`)
|
|
47
|
-
const { root, txHash } = await orbit.store(filePath)
|
|
48
|
-
|
|
49
|
-
const registry = loadRegistry()
|
|
50
|
-
registry.models.push({
|
|
51
|
-
name,
|
|
52
|
-
version,
|
|
53
|
-
rootHash: root,
|
|
54
|
-
txHash,
|
|
55
|
-
uploadedAt: new Date().toISOString(),
|
|
56
|
-
})
|
|
57
|
-
saveRegistry(registry)
|
|
58
|
-
|
|
59
|
-
console.log(`Registered: ${name} v${version}`)
|
|
60
|
-
console.log(` Root: ${root}`)
|
|
61
|
-
console.log(` Tx: ${txHash}`)
|
|
62
|
-
return root
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async function downloadModel(
|
|
66
|
-
orbit: Orbit,
|
|
67
|
-
name: string,
|
|
68
|
-
version: string,
|
|
69
|
-
outputPath: string
|
|
70
|
-
) {
|
|
71
|
-
const registry = loadRegistry()
|
|
72
|
-
const entry = registry.models.find(
|
|
73
|
-
(m) => m.name === name && m.version === version
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
if (!entry) {
|
|
77
|
-
console.error(`Model ${name} v${version} not found in registry.`)
|
|
78
|
-
return
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
console.log(`\nDownloading ${name} v${version}...`)
|
|
82
|
-
await orbit.retrieve(entry.rootHash, outputPath)
|
|
83
|
-
console.log(`Downloaded to ${outputPath}`)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function listModels() {
|
|
87
|
-
const registry = loadRegistry()
|
|
88
|
-
if (registry.models.length === 0) {
|
|
89
|
-
console.log('No models registered.')
|
|
90
|
-
return
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
console.log('\nRegistered models:')
|
|
94
|
-
for (const m of registry.models) {
|
|
95
|
-
console.log(` ${m.name} v${m.version}`)
|
|
96
|
-
console.log(` root: ${m.rootHash}`)
|
|
97
|
-
console.log(` date: ${m.uploadedAt}`)
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async function main() {
|
|
102
|
-
const orbit = await Orbit.connect({
|
|
103
|
-
network: 'testnet',
|
|
104
|
-
privateKey: process.env.PRIVATE_KEY!,
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
const status = await orbit.status()
|
|
108
|
-
console.log(`Connected: ${status.address} (${status.balance} OG)`)
|
|
109
|
-
|
|
110
|
-
const command = process.argv[2] || 'list'
|
|
111
|
-
|
|
112
|
-
switch (command) {
|
|
113
|
-
case 'register': {
|
|
114
|
-
const [, , , name, version, filePath] = process.argv
|
|
115
|
-
if (!name || !version || !filePath) {
|
|
116
|
-
console.error('Usage: npx tsx index.ts register <name> <version> <file>')
|
|
117
|
-
process.exit(1)
|
|
118
|
-
}
|
|
119
|
-
await registerModel(orbit, name, version, filePath)
|
|
120
|
-
break
|
|
121
|
-
}
|
|
122
|
-
case 'download': {
|
|
123
|
-
const [, , , name, version, outputPath] = process.argv
|
|
124
|
-
if (!name || !version || !outputPath) {
|
|
125
|
-
console.error('Usage: npx tsx index.ts download <name> <version> <output>')
|
|
126
|
-
process.exit(1)
|
|
127
|
-
}
|
|
128
|
-
await downloadModel(orbit, name, version, outputPath)
|
|
129
|
-
break
|
|
130
|
-
}
|
|
131
|
-
case 'list':
|
|
132
|
-
default:
|
|
133
|
-
listModels()
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
main().catch(console.error)
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 0G Orbit — Quick Start
|
|
3
|
-
*
|
|
4
|
-
* Demonstrates the three core operations:
|
|
5
|
-
* 1. Check account status
|
|
6
|
-
* 2. Store a file to 0G Storage
|
|
7
|
-
* 3. Run AI inference on 0G Compute
|
|
8
|
-
*
|
|
9
|
-
* Usage:
|
|
10
|
-
* PRIVATE_KEY=0x... npx tsx index.ts
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { Orbit } from '@0g-orbit/core'
|
|
14
|
-
import { writeFileSync, unlinkSync } from 'node:fs'
|
|
15
|
-
|
|
16
|
-
async function main() {
|
|
17
|
-
// Connect
|
|
18
|
-
const orbit = await Orbit.connect({
|
|
19
|
-
network: 'testnet',
|
|
20
|
-
privateKey: process.env.PRIVATE_KEY!,
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
// 1. Account status
|
|
24
|
-
const status = await orbit.status()
|
|
25
|
-
console.log(`Connected: ${status.address}`)
|
|
26
|
-
console.log(`Balance: ${status.balance} OG on ${status.network}`)
|
|
27
|
-
|
|
28
|
-
// 2. Store a file
|
|
29
|
-
const testFile = '/tmp/orbit-test.txt'
|
|
30
|
-
writeFileSync(testFile, 'Hello from 0G Orbit!')
|
|
31
|
-
|
|
32
|
-
console.log('\nUploading file...')
|
|
33
|
-
const { root, txHash } = await orbit.store(testFile)
|
|
34
|
-
console.log(`Stored! Root: ${root}`)
|
|
35
|
-
console.log(`Tx: ${txHash}`)
|
|
36
|
-
|
|
37
|
-
unlinkSync(testFile)
|
|
38
|
-
|
|
39
|
-
// 3. Retrieve it back
|
|
40
|
-
const outputFile = '/tmp/orbit-test-downloaded.txt'
|
|
41
|
-
console.log('\nDownloading...')
|
|
42
|
-
await orbit.retrieve(root, outputFile)
|
|
43
|
-
console.log(`Downloaded to ${outputFile}`)
|
|
44
|
-
|
|
45
|
-
// 4. AI inference
|
|
46
|
-
console.log('\nRunning inference...')
|
|
47
|
-
const result = await orbit.infer('meta-llama/Llama-3.3-70B', {
|
|
48
|
-
messages: [
|
|
49
|
-
{ role: 'system', content: 'You are a helpful assistant.' },
|
|
50
|
-
{ role: 'user', content: 'Explain what 0G is in one sentence.' },
|
|
51
|
-
],
|
|
52
|
-
temperature: 0.7,
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
console.log(`\nResponse: ${result.content}`)
|
|
56
|
-
console.log(`Model: ${result.model}`)
|
|
57
|
-
if (result.usage) {
|
|
58
|
-
console.log(`Tokens: ${result.usage.totalTokens}`)
|
|
59
|
-
}
|
|
60
|
-
if (result.verified !== null) {
|
|
61
|
-
console.log(`Verified: ${result.verified}`)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
main().catch(console.error)
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "0g-orbit-cli",
|
|
3
|
-
"version": "0.2.2",
|
|
4
|
-
"description": "CLI for 0G Orbit — store, infer, deploy from your terminal.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"bin": {
|
|
7
|
-
"orbit": "./dist/cli.js"
|
|
8
|
-
},
|
|
9
|
-
"scripts": {
|
|
10
|
-
"build": "tsc",
|
|
11
|
-
"dev": "tsc --watch",
|
|
12
|
-
"lint": "tsc --noEmit",
|
|
13
|
-
"clean": "rm -rf dist"
|
|
14
|
-
},
|
|
15
|
-
"dependencies": {
|
|
16
|
-
"0g-orbit-core": "workspace:*",
|
|
17
|
-
"commander": "^12.1.0",
|
|
18
|
-
"ora": "^8.0.1",
|
|
19
|
-
"chalk": "^5.3.0"
|
|
20
|
-
},
|
|
21
|
-
"devDependencies": {
|
|
22
|
-
"typescript": "^5.4.0",
|
|
23
|
-
"@types/node": "^20.12.0"
|
|
24
|
-
},
|
|
25
|
-
"keywords": ["0g", "cli", "blockchain", "ai"],
|
|
26
|
-
"license": "MIT",
|
|
27
|
-
"engines": {
|
|
28
|
-
"node": ">=18.0.0"
|
|
29
|
-
}
|
|
30
|
-
}
|