langtrain 0.1.9 → 0.1.10
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.js +33 -37
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +33 -37
- package/dist/cli.mjs.map +1 -1
- package/package.json +1 -1
- package/src/cli.ts +38 -48
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -28,16 +28,16 @@ function saveConfig(config: any) {
|
|
|
28
28
|
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
// Clients are initialized inside main loop to support re-login
|
|
31
|
+
const packageJson = require(path.join(__dirname, '../package.json'));
|
|
33
32
|
|
|
34
33
|
async function main() {
|
|
35
34
|
const program = new Command();
|
|
35
|
+
const version = packageJson.version;
|
|
36
36
|
|
|
37
37
|
program
|
|
38
38
|
.name('langtrain')
|
|
39
|
-
.description('Langtrain CLI for AI Model Fine-tuning and Generation')
|
|
40
|
-
.version(
|
|
39
|
+
.description(packageJson.description || 'Langtrain CLI for AI Model Fine-tuning and Generation')
|
|
40
|
+
.version(version);
|
|
41
41
|
|
|
42
42
|
program.action(async () => {
|
|
43
43
|
console.clear();
|
|
@@ -52,28 +52,26 @@ async function main() {
|
|
|
52
52
|
╚══════╝╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝
|
|
53
53
|
`;
|
|
54
54
|
console.log(gradient(['#00DC82', '#36E4DA', '#0047E1'])(banner)); // Custom Langtrain Green-Cyan-Blue gradient
|
|
55
|
-
intro(`${bgCyan(black(
|
|
55
|
+
intro(`${bgCyan(black(` Langtrain SDK v${version} `))}`);
|
|
56
56
|
|
|
57
|
-
// Check auth
|
|
57
|
+
// Check auth (only show login if missing)
|
|
58
58
|
const config = getConfig();
|
|
59
59
|
if (!config.apiKey) {
|
|
60
60
|
intro(yellow('Authentication required'));
|
|
61
|
-
|
|
62
|
-
message: 'Enter your Langtrain API Key:',
|
|
63
|
-
validate(value) {
|
|
64
|
-
if (!value || value.length === 0) return 'API Key is required';
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
if (isCancel(apiKey)) {
|
|
69
|
-
cancel('Operation cancelled');
|
|
70
|
-
process.exit(0);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
saveConfig({ ...config, apiKey });
|
|
74
|
-
intro(green('Successfully logged in!'));
|
|
61
|
+
await handleLogin();
|
|
75
62
|
}
|
|
76
63
|
|
|
64
|
+
// Operation Handlers Map (O(1) lookup)
|
|
65
|
+
const handlers: Record<string, (clients?: any) => Promise<void>> = {
|
|
66
|
+
'login': handleLogin,
|
|
67
|
+
'tune-finetune': (c) => handleTuneFinetune(c.tune),
|
|
68
|
+
'tune-generate': (c) => handleTuneGenerate(c.tune),
|
|
69
|
+
'vision-finetune': (c) => handleVisionFinetune(c.vision),
|
|
70
|
+
'vision-generate': (c) => handleVisionGenerate(c.vision),
|
|
71
|
+
'agent-list': (c) => handleAgentList(c.agent),
|
|
72
|
+
'exit': async () => { outro('Goodbye!'); process.exit(0); },
|
|
73
|
+
};
|
|
74
|
+
|
|
77
75
|
while (true) {
|
|
78
76
|
const operation = await select({
|
|
79
77
|
message: 'Select an operation:',
|
|
@@ -95,39 +93,31 @@ async function main() {
|
|
|
95
93
|
],
|
|
96
94
|
});
|
|
97
95
|
|
|
98
|
-
if (isCancel(operation)
|
|
96
|
+
if (isCancel(operation)) {
|
|
99
97
|
outro('Goodbye!');
|
|
100
98
|
process.exit(0);
|
|
101
99
|
}
|
|
102
100
|
|
|
103
|
-
if (typeof operation === 'string'
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
await handleVisionFinetune(currentVision);
|
|
123
|
-
} else if (operation === 'vision-generate') {
|
|
124
|
-
await handleVisionGenerate(currentVision);
|
|
125
|
-
} else if (operation === 'agent-list') {
|
|
126
|
-
await handleAgentList(currentAgent);
|
|
101
|
+
if (typeof operation === 'string') {
|
|
102
|
+
if (operation.startsWith('group-')) continue;
|
|
103
|
+
|
|
104
|
+
// Execute handler via map lookup
|
|
105
|
+
const handler = handlers[operation];
|
|
106
|
+
if (handler) {
|
|
107
|
+
try {
|
|
108
|
+
// Re-read config & re-init clients freshly for each operation
|
|
109
|
+
const currentConfig = getConfig();
|
|
110
|
+
const clients = {
|
|
111
|
+
vision: new Langvision({ apiKey: currentConfig.apiKey }),
|
|
112
|
+
tune: new Langtune({ apiKey: currentConfig.apiKey }),
|
|
113
|
+
agent: new AgentClient({ apiKey: currentConfig.apiKey, baseUrl: currentConfig.baseUrl })
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
await handler(clients);
|
|
117
|
+
} catch (error: any) {
|
|
118
|
+
outro(red(`Error: ${error.message}`));
|
|
119
|
+
}
|
|
127
120
|
}
|
|
128
|
-
} catch (error: any) {
|
|
129
|
-
outro(red(`Error: ${error.message}`));
|
|
130
|
-
// Don't exit, just loop back to menu
|
|
131
121
|
}
|
|
132
122
|
}
|
|
133
123
|
});
|