0g-orbit 0.1.0 → 0.2.0
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/dist/cli/cli.js +23 -0
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/commands/fine-tuning.d.ts +21 -0
- package/dist/cli/commands/fine-tuning.d.ts.map +1 -0
- package/dist/cli/commands/fine-tuning.js +142 -0
- package/dist/cli/commands/fine-tuning.js.map +1 -0
- package/dist/errors.d.ts +3 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +6 -0
- package/dist/errors.js.map +1 -1
- package/dist/fine-tuning.d.ts +50 -0
- package/dist/fine-tuning.d.ts.map +1 -0
- package/dist/fine-tuning.js +240 -0
- package/dist/fine-tuning.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/orbit.d.ts +11 -1
- package/dist/orbit.d.ts.map +1 -1
- package/dist/orbit.js +28 -0
- package/dist/orbit.js.map +1 -1
- package/dist/storage.js +4 -4
- package/dist/storage.js.map +1 -1
- package/dist/types.d.ts +54 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +10 -2
- package/src/cli/cli.ts +26 -0
- package/src/cli/commands/fine-tuning.ts +169 -0
- package/src/errors.ts +11 -0
- package/src/fine-tuning.test.ts +299 -0
- package/src/fine-tuning.ts +330 -0
- package/src/index.ts +8 -0
- package/src/orbit.ts +45 -0
- package/src/storage.ts +3 -3
- package/src/types.ts +72 -0
package/src/orbit.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { NetworkName, NetworkConfig } from './networks.js'
|
|
|
3
3
|
import { getNetwork, NETWORKS } from './networks.js'
|
|
4
4
|
import { StorageClient } from './storage.js'
|
|
5
5
|
import { InferenceClient } from './inference.js'
|
|
6
|
+
import { FineTuningClient } from './fine-tuning.js'
|
|
6
7
|
import type {
|
|
7
8
|
OrbitConfig,
|
|
8
9
|
StoreResult,
|
|
@@ -12,6 +13,11 @@ import type {
|
|
|
12
13
|
InferOptions,
|
|
13
14
|
ServiceInfo,
|
|
14
15
|
AccountStatus,
|
|
16
|
+
DatasetUploadResult,
|
|
17
|
+
CreateTaskOptions,
|
|
18
|
+
FineTuneTask,
|
|
19
|
+
FineTuneModel,
|
|
20
|
+
FineTuneProvider,
|
|
15
21
|
} from './types.js'
|
|
16
22
|
import { ConnectionError } from './errors.js'
|
|
17
23
|
|
|
@@ -19,6 +25,7 @@ export class Orbit {
|
|
|
19
25
|
readonly network: NetworkConfig
|
|
20
26
|
readonly storage: StorageClient
|
|
21
27
|
readonly inference: InferenceClient
|
|
28
|
+
private _fineTuning: FineTuningClient | null = null
|
|
22
29
|
private wallet: Wallet
|
|
23
30
|
private provider: JsonRpcProvider
|
|
24
31
|
|
|
@@ -34,6 +41,14 @@ export class Orbit {
|
|
|
34
41
|
this.inference = new InferenceClient(network, wallet)
|
|
35
42
|
}
|
|
36
43
|
|
|
44
|
+
/** Lazy-initialized fine-tuning client */
|
|
45
|
+
get fineTuning(): FineTuningClient {
|
|
46
|
+
if (!this._fineTuning) {
|
|
47
|
+
this._fineTuning = new FineTuningClient(this.network, this.wallet, this.storage)
|
|
48
|
+
}
|
|
49
|
+
return this._fineTuning
|
|
50
|
+
}
|
|
51
|
+
|
|
37
52
|
/**
|
|
38
53
|
* Connect to the 0G network. This is the primary entry point.
|
|
39
54
|
*
|
|
@@ -140,6 +155,36 @@ export class Orbit {
|
|
|
140
155
|
return this.inference.listServices()
|
|
141
156
|
}
|
|
142
157
|
|
|
158
|
+
// --- Fine-Tuning shortcuts ---
|
|
159
|
+
|
|
160
|
+
async uploadDataset(filePath: string): Promise<DatasetUploadResult> {
|
|
161
|
+
return this.fineTuning.uploadDataset(filePath)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async createFineTuneTask(options: CreateTaskOptions): Promise<FineTuneTask> {
|
|
165
|
+
return this.fineTuning.createTask(options)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async getFineTuneTask(providerAddress: string, taskId: string): Promise<FineTuneTask> {
|
|
169
|
+
return this.fineTuning.getTask(providerAddress, taskId)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async downloadModel(
|
|
173
|
+
providerAddress: string,
|
|
174
|
+
taskId: string,
|
|
175
|
+
outputPath: string
|
|
176
|
+
): Promise<void> {
|
|
177
|
+
return this.fineTuning.downloadModel(providerAddress, taskId, outputPath)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async listModels(): Promise<FineTuneModel[]> {
|
|
181
|
+
return this.fineTuning.listModels()
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async listProviders(): Promise<FineTuneProvider[]> {
|
|
185
|
+
return this.fineTuning.listProviders()
|
|
186
|
+
}
|
|
187
|
+
|
|
143
188
|
// --- Account ---
|
|
144
189
|
|
|
145
190
|
async status(): Promise<AccountStatus> {
|
package/src/storage.ts
CHANGED
|
@@ -95,12 +95,12 @@ export class StorageClient {
|
|
|
95
95
|
if (uploadErr) {
|
|
96
96
|
const msg = uploadErr.message
|
|
97
97
|
let suggestion = 'Check your OG balance and try again.'
|
|
98
|
-
if (msg.includes('
|
|
98
|
+
if (msg.includes('insufficient funds') || msg.includes('INSUFFICIENT_FUNDS')) {
|
|
99
|
+
suggestion = 'Your wallet needs more OG for gas. Get testnet OG from: https://faucet.0g.ai'
|
|
100
|
+
} else if (msg.includes('underpriced') || msg.includes('gas required exceeds')) {
|
|
99
101
|
suggestion = `Gas auto-escalation hit the ceiling (${maxGas} wei). Try a higher maxGasPrice, e.g. { maxGasPrice: ${maxGas * 2}n }`
|
|
100
102
|
} else if (msg.includes('timeout') || msg.includes('ETIMEDOUT')) {
|
|
101
103
|
suggestion = 'The RPC endpoint timed out. Try a different RPC URL with the rpcUrl option.'
|
|
102
|
-
} else if (msg.includes('insufficient funds')) {
|
|
103
|
-
suggestion = 'Your wallet needs more OG for gas. Get testnet OG from: https://faucet.0g.ai'
|
|
104
104
|
}
|
|
105
105
|
throw new StorageError(`Upload failed: ${msg}`, suggestion)
|
|
106
106
|
}
|
package/src/types.ts
CHANGED
|
@@ -83,3 +83,75 @@ export interface AccountStatus {
|
|
|
83
83
|
/** Wallet address */
|
|
84
84
|
address: string
|
|
85
85
|
}
|
|
86
|
+
|
|
87
|
+
// --- Fine-Tuning ---
|
|
88
|
+
|
|
89
|
+
export interface DatasetUploadResult {
|
|
90
|
+
/** Merkle root hash of the uploaded dataset in 0G Storage */
|
|
91
|
+
root: string
|
|
92
|
+
/** On-chain transaction hash */
|
|
93
|
+
txHash: string
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface CreateTaskOptions {
|
|
97
|
+
/** Name of the base model to fine-tune (e.g. 'Qwen2.5-0.5B-Instruct') */
|
|
98
|
+
model: string
|
|
99
|
+
/** Root hash of the dataset in 0G Storage (from uploadDataset) */
|
|
100
|
+
dataset: string
|
|
101
|
+
/** Provider wallet address */
|
|
102
|
+
providerAddress: string
|
|
103
|
+
/** Training hyperparameters (JSON object or file path) */
|
|
104
|
+
trainingParams?: {
|
|
105
|
+
nEpochs?: number
|
|
106
|
+
batchSize?: number
|
|
107
|
+
learningRate?: number
|
|
108
|
+
loraRank?: number
|
|
109
|
+
loraAlpha?: number
|
|
110
|
+
[key: string]: unknown
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export type FineTuneStatus =
|
|
115
|
+
| 'init'
|
|
116
|
+
| 'setting-up'
|
|
117
|
+
| 'set-up'
|
|
118
|
+
| 'training'
|
|
119
|
+
| 'trained'
|
|
120
|
+
| 'delivering'
|
|
121
|
+
| 'delivered'
|
|
122
|
+
| 'acknowledged'
|
|
123
|
+
| 'finished'
|
|
124
|
+
| 'failed'
|
|
125
|
+
|
|
126
|
+
export interface FineTuneTask {
|
|
127
|
+
/** Task ID */
|
|
128
|
+
id: string
|
|
129
|
+
/** Base model name or hash */
|
|
130
|
+
model: string
|
|
131
|
+
/** Dataset root hash */
|
|
132
|
+
dataset: string
|
|
133
|
+
/** Provider address */
|
|
134
|
+
provider: string
|
|
135
|
+
/** Current task status */
|
|
136
|
+
status: FineTuneStatus
|
|
137
|
+
/** Task creation time */
|
|
138
|
+
createdAt?: string
|
|
139
|
+
/** Last update time */
|
|
140
|
+
updatedAt?: string
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface FineTuneModel {
|
|
144
|
+
/** Model name */
|
|
145
|
+
name: string
|
|
146
|
+
/** Model configuration (hash, description, etc.) */
|
|
147
|
+
config: Record<string, string>
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface FineTuneProvider {
|
|
151
|
+
/** Provider wallet address */
|
|
152
|
+
address: string
|
|
153
|
+
/** Provider endpoint URL */
|
|
154
|
+
url: string
|
|
155
|
+
/** Customized models offered by this provider */
|
|
156
|
+
models: string[]
|
|
157
|
+
}
|