langtrain 0.1.6 → 0.1.9

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.mjs CHANGED
@@ -51,8 +51,8 @@ var require_windows = __commonJS({
51
51
  "use strict";
52
52
  module.exports = isexe;
53
53
  isexe.sync = sync;
54
- var fs = __require("fs");
55
- function checkPathExt(path5, options) {
54
+ var fs2 = __require("fs");
55
+ function checkPathExt(path6, options) {
56
56
  var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT;
57
57
  if (!pathext) {
58
58
  return true;
@@ -63,25 +63,25 @@ var require_windows = __commonJS({
63
63
  }
64
64
  for (var i = 0; i < pathext.length; i++) {
65
65
  var p = pathext[i].toLowerCase();
66
- if (p && path5.substr(-p.length).toLowerCase() === p) {
66
+ if (p && path6.substr(-p.length).toLowerCase() === p) {
67
67
  return true;
68
68
  }
69
69
  }
70
70
  return false;
71
71
  }
72
- function checkStat(stat, path5, options) {
72
+ function checkStat(stat, path6, options) {
73
73
  if (!stat.isSymbolicLink() && !stat.isFile()) {
74
74
  return false;
75
75
  }
76
- return checkPathExt(path5, options);
76
+ return checkPathExt(path6, options);
77
77
  }
78
- function isexe(path5, options, cb) {
79
- fs.stat(path5, function(er, stat) {
80
- cb(er, er ? false : checkStat(stat, path5, options));
78
+ function isexe(path6, options, cb) {
79
+ fs2.stat(path6, function(er, stat) {
80
+ cb(er, er ? false : checkStat(stat, path6, options));
81
81
  });
82
82
  }
83
- function sync(path5, options) {
84
- return checkStat(fs.statSync(path5), path5, options);
83
+ function sync(path6, options) {
84
+ return checkStat(fs2.statSync(path6), path6, options);
85
85
  }
86
86
  }
87
87
  });
@@ -92,14 +92,14 @@ var require_mode = __commonJS({
92
92
  "use strict";
93
93
  module.exports = isexe;
94
94
  isexe.sync = sync;
95
- var fs = __require("fs");
96
- function isexe(path5, options, cb) {
97
- fs.stat(path5, function(er, stat) {
95
+ var fs2 = __require("fs");
96
+ function isexe(path6, options, cb) {
97
+ fs2.stat(path6, function(er, stat) {
98
98
  cb(er, er ? false : checkStat(stat, options));
99
99
  });
100
100
  }
101
- function sync(path5, options) {
102
- return checkStat(fs.statSync(path5), options);
101
+ function sync(path6, options) {
102
+ return checkStat(fs2.statSync(path6), options);
103
103
  }
104
104
  function checkStat(stat, options) {
105
105
  return stat.isFile() && checkMode(stat, options);
@@ -124,7 +124,7 @@ var require_mode = __commonJS({
124
124
  var require_isexe = __commonJS({
125
125
  "../langvision/js/node_modules/isexe/index.js"(exports, module) {
126
126
  "use strict";
127
- var fs = __require("fs");
127
+ var fs2 = __require("fs");
128
128
  var core;
129
129
  if (process.platform === "win32" || global.TESTING_WINDOWS) {
130
130
  core = require_windows();
@@ -133,7 +133,7 @@ var require_isexe = __commonJS({
133
133
  }
134
134
  module.exports = isexe;
135
135
  isexe.sync = sync;
136
- function isexe(path5, options, cb) {
136
+ function isexe(path6, options, cb) {
137
137
  if (typeof options === "function") {
138
138
  cb = options;
139
139
  options = {};
@@ -143,7 +143,7 @@ var require_isexe = __commonJS({
143
143
  throw new TypeError("callback not provided");
144
144
  }
145
145
  return new Promise(function(resolve, reject) {
146
- isexe(path5, options || {}, function(er, is) {
146
+ isexe(path6, options || {}, function(er, is) {
147
147
  if (er) {
148
148
  reject(er);
149
149
  } else {
@@ -152,7 +152,7 @@ var require_isexe = __commonJS({
152
152
  });
153
153
  });
154
154
  }
155
- core(path5, options || {}, function(er, is) {
155
+ core(path6, options || {}, function(er, is) {
156
156
  if (er) {
157
157
  if (er.code === "EACCES" || options && options.ignoreErrors) {
158
158
  er = null;
@@ -162,9 +162,9 @@ var require_isexe = __commonJS({
162
162
  cb(er, is);
163
163
  });
164
164
  }
165
- function sync(path5, options) {
165
+ function sync(path6, options) {
166
166
  try {
167
- return core.sync(path5, options || {});
167
+ return core.sync(path6, options || {});
168
168
  } catch (er) {
169
169
  if (options && options.ignoreErrors || er.code === "EACCES") {
170
170
  return false;
@@ -181,7 +181,7 @@ var require_which = __commonJS({
181
181
  "../langvision/js/node_modules/which/which.js"(exports, module) {
182
182
  "use strict";
183
183
  var isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
184
- var path5 = __require("path");
184
+ var path6 = __require("path");
185
185
  var COLON = isWindows ? ";" : ":";
186
186
  var isexe = require_isexe();
187
187
  var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" });
@@ -219,7 +219,7 @@ var require_which = __commonJS({
219
219
  return opt.all && found.length ? resolve(found) : reject(getNotFoundError(cmd));
220
220
  const ppRaw = pathEnv[i];
221
221
  const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
222
- const pCmd = path5.join(pathPart, cmd);
222
+ const pCmd = path6.join(pathPart, cmd);
223
223
  const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
224
224
  resolve(subStep(p, i, 0));
225
225
  });
@@ -246,7 +246,7 @@ var require_which = __commonJS({
246
246
  for (let i = 0; i < pathEnv.length; i++) {
247
247
  const ppRaw = pathEnv[i];
248
248
  const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
249
- const pCmd = path5.join(pathPart, cmd);
249
+ const pCmd = path6.join(pathPart, cmd);
250
250
  const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
251
251
  for (let j = 0; j < pathExt.length; j++) {
252
252
  const cur = p + pathExt[j];
@@ -294,7 +294,7 @@ var require_path_key = __commonJS({
294
294
  var require_resolveCommand = __commonJS({
295
295
  "../langvision/js/node_modules/cross-spawn/lib/util/resolveCommand.js"(exports, module) {
296
296
  "use strict";
297
- var path5 = __require("path");
297
+ var path6 = __require("path");
298
298
  var which = require_which();
299
299
  var getPathKey = require_path_key();
300
300
  function resolveCommandAttempt(parsed, withoutPathExt) {
@@ -312,7 +312,7 @@ var require_resolveCommand = __commonJS({
312
312
  try {
313
313
  resolved = which.sync(parsed.command, {
314
314
  path: env[getPathKey({ env })],
315
- pathExt: withoutPathExt ? path5.delimiter : void 0
315
+ pathExt: withoutPathExt ? path6.delimiter : void 0
316
316
  });
317
317
  } catch (e) {
318
318
  } finally {
@@ -321,7 +321,7 @@ var require_resolveCommand = __commonJS({
321
321
  }
322
322
  }
323
323
  if (resolved) {
324
- resolved = path5.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
324
+ resolved = path6.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
325
325
  }
326
326
  return resolved;
327
327
  }
@@ -375,8 +375,8 @@ var require_shebang_command = __commonJS({
375
375
  if (!match) {
376
376
  return null;
377
377
  }
378
- const [path5, argument] = match[0].replace(/#! ?/, "").split(" ");
379
- const binary = path5.split("/").pop();
378
+ const [path6, argument] = match[0].replace(/#! ?/, "").split(" ");
379
+ const binary = path6.split("/").pop();
380
380
  if (binary === "env") {
381
381
  return argument;
382
382
  }
@@ -389,16 +389,16 @@ var require_shebang_command = __commonJS({
389
389
  var require_readShebang = __commonJS({
390
390
  "../langvision/js/node_modules/cross-spawn/lib/util/readShebang.js"(exports, module) {
391
391
  "use strict";
392
- var fs = __require("fs");
392
+ var fs2 = __require("fs");
393
393
  var shebangCommand = require_shebang_command();
394
394
  function readShebang(command) {
395
395
  const size = 150;
396
396
  const buffer = Buffer.alloc(size);
397
397
  let fd;
398
398
  try {
399
- fd = fs.openSync(command, "r");
400
- fs.readSync(fd, buffer, 0, size, 0);
401
- fs.closeSync(fd);
399
+ fd = fs2.openSync(command, "r");
400
+ fs2.readSync(fd, buffer, 0, size, 0);
401
+ fs2.closeSync(fd);
402
402
  } catch (e) {
403
403
  }
404
404
  return shebangCommand(buffer.toString());
@@ -411,7 +411,7 @@ var require_readShebang = __commonJS({
411
411
  var require_parse = __commonJS({
412
412
  "../langvision/js/node_modules/cross-spawn/lib/parse.js"(exports, module) {
413
413
  "use strict";
414
- var path5 = __require("path");
414
+ var path6 = __require("path");
415
415
  var resolveCommand = require_resolveCommand();
416
416
  var escape = require_escape();
417
417
  var readShebang = require_readShebang();
@@ -436,7 +436,7 @@ var require_parse = __commonJS({
436
436
  const needsShell = !isExecutableRegExp.test(commandFile);
437
437
  if (parsed.options.forceShell || needsShell) {
438
438
  const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
439
- parsed.command = path5.normalize(parsed.command);
439
+ parsed.command = path6.normalize(parsed.command);
440
440
  parsed.command = escape.command(parsed.command);
441
441
  parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
442
442
  const shellCommand = [parsed.command].concat(parsed.args).join(" ");
@@ -592,8 +592,8 @@ var require_windows2 = __commonJS({
592
592
  "use strict";
593
593
  module.exports = isexe;
594
594
  isexe.sync = sync;
595
- var fs = __require("fs");
596
- function checkPathExt(path5, options) {
595
+ var fs2 = __require("fs");
596
+ function checkPathExt(path6, options) {
597
597
  var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT;
598
598
  if (!pathext) {
599
599
  return true;
@@ -604,25 +604,25 @@ var require_windows2 = __commonJS({
604
604
  }
605
605
  for (var i = 0; i < pathext.length; i++) {
606
606
  var p = pathext[i].toLowerCase();
607
- if (p && path5.substr(-p.length).toLowerCase() === p) {
607
+ if (p && path6.substr(-p.length).toLowerCase() === p) {
608
608
  return true;
609
609
  }
610
610
  }
611
611
  return false;
612
612
  }
613
- function checkStat(stat, path5, options) {
613
+ function checkStat(stat, path6, options) {
614
614
  if (!stat.isSymbolicLink() && !stat.isFile()) {
615
615
  return false;
616
616
  }
617
- return checkPathExt(path5, options);
617
+ return checkPathExt(path6, options);
618
618
  }
619
- function isexe(path5, options, cb) {
620
- fs.stat(path5, function(er, stat) {
621
- cb(er, er ? false : checkStat(stat, path5, options));
619
+ function isexe(path6, options, cb) {
620
+ fs2.stat(path6, function(er, stat) {
621
+ cb(er, er ? false : checkStat(stat, path6, options));
622
622
  });
623
623
  }
624
- function sync(path5, options) {
625
- return checkStat(fs.statSync(path5), path5, options);
624
+ function sync(path6, options) {
625
+ return checkStat(fs2.statSync(path6), path6, options);
626
626
  }
627
627
  }
628
628
  });
@@ -633,14 +633,14 @@ var require_mode2 = __commonJS({
633
633
  "use strict";
634
634
  module.exports = isexe;
635
635
  isexe.sync = sync;
636
- var fs = __require("fs");
637
- function isexe(path5, options, cb) {
638
- fs.stat(path5, function(er, stat) {
636
+ var fs2 = __require("fs");
637
+ function isexe(path6, options, cb) {
638
+ fs2.stat(path6, function(er, stat) {
639
639
  cb(er, er ? false : checkStat(stat, options));
640
640
  });
641
641
  }
642
- function sync(path5, options) {
643
- return checkStat(fs.statSync(path5), options);
642
+ function sync(path6, options) {
643
+ return checkStat(fs2.statSync(path6), options);
644
644
  }
645
645
  function checkStat(stat, options) {
646
646
  return stat.isFile() && checkMode(stat, options);
@@ -665,7 +665,7 @@ var require_mode2 = __commonJS({
665
665
  var require_isexe2 = __commonJS({
666
666
  "../langtune/js/node_modules/isexe/index.js"(exports, module) {
667
667
  "use strict";
668
- var fs = __require("fs");
668
+ var fs2 = __require("fs");
669
669
  var core;
670
670
  if (process.platform === "win32" || global.TESTING_WINDOWS) {
671
671
  core = require_windows2();
@@ -674,7 +674,7 @@ var require_isexe2 = __commonJS({
674
674
  }
675
675
  module.exports = isexe;
676
676
  isexe.sync = sync;
677
- function isexe(path5, options, cb) {
677
+ function isexe(path6, options, cb) {
678
678
  if (typeof options === "function") {
679
679
  cb = options;
680
680
  options = {};
@@ -684,7 +684,7 @@ var require_isexe2 = __commonJS({
684
684
  throw new TypeError("callback not provided");
685
685
  }
686
686
  return new Promise(function(resolve, reject) {
687
- isexe(path5, options || {}, function(er, is) {
687
+ isexe(path6, options || {}, function(er, is) {
688
688
  if (er) {
689
689
  reject(er);
690
690
  } else {
@@ -693,7 +693,7 @@ var require_isexe2 = __commonJS({
693
693
  });
694
694
  });
695
695
  }
696
- core(path5, options || {}, function(er, is) {
696
+ core(path6, options || {}, function(er, is) {
697
697
  if (er) {
698
698
  if (er.code === "EACCES" || options && options.ignoreErrors) {
699
699
  er = null;
@@ -703,9 +703,9 @@ var require_isexe2 = __commonJS({
703
703
  cb(er, is);
704
704
  });
705
705
  }
706
- function sync(path5, options) {
706
+ function sync(path6, options) {
707
707
  try {
708
- return core.sync(path5, options || {});
708
+ return core.sync(path6, options || {});
709
709
  } catch (er) {
710
710
  if (options && options.ignoreErrors || er.code === "EACCES") {
711
711
  return false;
@@ -722,7 +722,7 @@ var require_which2 = __commonJS({
722
722
  "../langtune/js/node_modules/which/which.js"(exports, module) {
723
723
  "use strict";
724
724
  var isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
725
- var path5 = __require("path");
725
+ var path6 = __require("path");
726
726
  var COLON = isWindows ? ";" : ":";
727
727
  var isexe = require_isexe2();
728
728
  var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" });
@@ -760,7 +760,7 @@ var require_which2 = __commonJS({
760
760
  return opt.all && found.length ? resolve(found) : reject(getNotFoundError(cmd));
761
761
  const ppRaw = pathEnv[i];
762
762
  const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
763
- const pCmd = path5.join(pathPart, cmd);
763
+ const pCmd = path6.join(pathPart, cmd);
764
764
  const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
765
765
  resolve(subStep(p, i, 0));
766
766
  });
@@ -787,7 +787,7 @@ var require_which2 = __commonJS({
787
787
  for (let i = 0; i < pathEnv.length; i++) {
788
788
  const ppRaw = pathEnv[i];
789
789
  const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
790
- const pCmd = path5.join(pathPart, cmd);
790
+ const pCmd = path6.join(pathPart, cmd);
791
791
  const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
792
792
  for (let j = 0; j < pathExt.length; j++) {
793
793
  const cur = p + pathExt[j];
@@ -835,7 +835,7 @@ var require_path_key2 = __commonJS({
835
835
  var require_resolveCommand2 = __commonJS({
836
836
  "../langtune/js/node_modules/cross-spawn/lib/util/resolveCommand.js"(exports, module) {
837
837
  "use strict";
838
- var path5 = __require("path");
838
+ var path6 = __require("path");
839
839
  var which = require_which2();
840
840
  var getPathKey = require_path_key2();
841
841
  function resolveCommandAttempt(parsed, withoutPathExt) {
@@ -853,7 +853,7 @@ var require_resolveCommand2 = __commonJS({
853
853
  try {
854
854
  resolved = which.sync(parsed.command, {
855
855
  path: env[getPathKey({ env })],
856
- pathExt: withoutPathExt ? path5.delimiter : void 0
856
+ pathExt: withoutPathExt ? path6.delimiter : void 0
857
857
  });
858
858
  } catch (e) {
859
859
  } finally {
@@ -862,7 +862,7 @@ var require_resolveCommand2 = __commonJS({
862
862
  }
863
863
  }
864
864
  if (resolved) {
865
- resolved = path5.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
865
+ resolved = path6.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
866
866
  }
867
867
  return resolved;
868
868
  }
@@ -916,8 +916,8 @@ var require_shebang_command2 = __commonJS({
916
916
  if (!match) {
917
917
  return null;
918
918
  }
919
- const [path5, argument] = match[0].replace(/#! ?/, "").split(" ");
920
- const binary = path5.split("/").pop();
919
+ const [path6, argument] = match[0].replace(/#! ?/, "").split(" ");
920
+ const binary = path6.split("/").pop();
921
921
  if (binary === "env") {
922
922
  return argument;
923
923
  }
@@ -930,16 +930,16 @@ var require_shebang_command2 = __commonJS({
930
930
  var require_readShebang2 = __commonJS({
931
931
  "../langtune/js/node_modules/cross-spawn/lib/util/readShebang.js"(exports, module) {
932
932
  "use strict";
933
- var fs = __require("fs");
933
+ var fs2 = __require("fs");
934
934
  var shebangCommand = require_shebang_command2();
935
935
  function readShebang(command) {
936
936
  const size = 150;
937
937
  const buffer = Buffer.alloc(size);
938
938
  let fd;
939
939
  try {
940
- fd = fs.openSync(command, "r");
941
- fs.readSync(fd, buffer, 0, size, 0);
942
- fs.closeSync(fd);
940
+ fd = fs2.openSync(command, "r");
941
+ fs2.readSync(fd, buffer, 0, size, 0);
942
+ fs2.closeSync(fd);
943
943
  } catch (e) {
944
944
  }
945
945
  return shebangCommand(buffer.toString());
@@ -952,7 +952,7 @@ var require_readShebang2 = __commonJS({
952
952
  var require_parse2 = __commonJS({
953
953
  "../langtune/js/node_modules/cross-spawn/lib/parse.js"(exports, module) {
954
954
  "use strict";
955
- var path5 = __require("path");
955
+ var path6 = __require("path");
956
956
  var resolveCommand = require_resolveCommand2();
957
957
  var escape = require_escape2();
958
958
  var readShebang = require_readShebang2();
@@ -977,7 +977,7 @@ var require_parse2 = __commonJS({
977
977
  const needsShell = !isExecutableRegExp.test(commandFile);
978
978
  if (parsed.options.forceShell || needsShell) {
979
979
  const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
980
- parsed.command = path5.normalize(parsed.command);
980
+ parsed.command = path6.normalize(parsed.command);
981
981
  parsed.command = escape.command(parsed.command);
982
982
  parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
983
983
  const shellCommand = [parsed.command].concat(parsed.args).join(" ");
@@ -1128,8 +1128,8 @@ var require_merge_stream2 = __commonJS({
1128
1128
  });
1129
1129
 
1130
1130
  // src/cli.ts
1131
- import { intro, outro, select, text, spinner, isCancel, cancel } from "@clack/prompts";
1132
- import { bgCyan, black, red, green } from "kleur/colors";
1131
+ import { intro, outro, select, text, spinner, isCancel, cancel, password } from "@clack/prompts";
1132
+ import { bgCyan, black, red, green, yellow, gray } from "kleur/colors";
1133
1133
  import { Command } from "commander";
1134
1134
 
1135
1135
  // ../langvision/js/node_modules/execa/index.js
@@ -3208,8 +3208,8 @@ function getErrorMap() {
3208
3208
 
3209
3209
  // ../langvision/js/node_modules/zod/v3/helpers/parseUtil.js
3210
3210
  var makeIssue = (params) => {
3211
- const { data, path: path5, errorMaps, issueData } = params;
3212
- const fullPath = [...path5, ...issueData.path || []];
3211
+ const { data, path: path6, errorMaps, issueData } = params;
3212
+ const fullPath = [...path6, ...issueData.path || []];
3213
3213
  const fullIssue = {
3214
3214
  ...issueData,
3215
3215
  path: fullPath
@@ -3325,11 +3325,11 @@ var errorUtil;
3325
3325
 
3326
3326
  // ../langvision/js/node_modules/zod/v3/types.js
3327
3327
  var ParseInputLazyPath = class {
3328
- constructor(parent, value, path5, key) {
3328
+ constructor(parent, value, path6, key) {
3329
3329
  this._cachedPath = [];
3330
3330
  this.parent = parent;
3331
3331
  this.data = value;
3332
- this._path = path5;
3332
+ this._path = path6;
3333
3333
  this._key = key;
3334
3334
  }
3335
3335
  get path() {
@@ -6784,6 +6784,13 @@ var FinetuneConfigSchema = external_exports.object({
6784
6784
  var Langvision = class {
6785
6785
  constructor(options = {}) {
6786
6786
  this.cliPath = options.cliPath || "langvision";
6787
+ this.apiKey = options.apiKey;
6788
+ }
6789
+ getEnv() {
6790
+ return {
6791
+ ...process.env,
6792
+ LANGVISION_API_KEY: this.apiKey || process.env.LANGVISION_API_KEY
6793
+ };
6787
6794
  }
6788
6795
  /**
6789
6796
  * Run a fine-tuning job using the local CLI
@@ -6808,7 +6815,10 @@ var Langvision = class {
6808
6815
  validated.outputDir
6809
6816
  ];
6810
6817
  try {
6811
- await execa(this.cliPath, args, { stdio: "inherit" });
6818
+ await execa(this.cliPath, args, {
6819
+ stdio: "inherit",
6820
+ env: this.getEnv()
6821
+ });
6812
6822
  } catch (error) {
6813
6823
  throw new Error(`Langvision fine-tuning failed: ${error}`);
6814
6824
  }
@@ -6831,7 +6841,9 @@ var Langvision = class {
6831
6841
  args.push("--temperature", options.temperature.toString());
6832
6842
  }
6833
6843
  try {
6834
- const { stdout } = await execa(this.cliPath, args);
6844
+ const { stdout } = await execa(this.cliPath, args, {
6845
+ env: this.getEnv()
6846
+ });
6835
6847
  return stdout;
6836
6848
  } catch (error) {
6837
6849
  throw new Error(`Langvision generation failed: ${error}`);
@@ -8915,8 +8927,8 @@ function getErrorMap2() {
8915
8927
 
8916
8928
  // ../langtune/js/node_modules/zod/v3/helpers/parseUtil.js
8917
8929
  var makeIssue2 = (params) => {
8918
- const { data, path: path5, errorMaps, issueData } = params;
8919
- const fullPath = [...path5, ...issueData.path || []];
8930
+ const { data, path: path6, errorMaps, issueData } = params;
8931
+ const fullPath = [...path6, ...issueData.path || []];
8920
8932
  const fullIssue = {
8921
8933
  ...issueData,
8922
8934
  path: fullPath
@@ -9032,11 +9044,11 @@ var errorUtil2;
9032
9044
 
9033
9045
  // ../langtune/js/node_modules/zod/v3/types.js
9034
9046
  var ParseInputLazyPath2 = class {
9035
- constructor(parent, value, path5, key) {
9047
+ constructor(parent, value, path6, key) {
9036
9048
  this._cachedPath = [];
9037
9049
  this.parent = parent;
9038
9050
  this.data = value;
9039
- this._path = path5;
9051
+ this._path = path6;
9040
9052
  this._key = key;
9041
9053
  }
9042
9054
  get path() {
@@ -12494,6 +12506,13 @@ var FinetuneConfigSchema2 = external_exports2.object({
12494
12506
  var Langtune = class {
12495
12507
  constructor(options = {}) {
12496
12508
  this.cliPath = options.cliPath || "langtune";
12509
+ this.apiKey = options.apiKey;
12510
+ }
12511
+ getEnv() {
12512
+ return {
12513
+ ...process.env,
12514
+ LANGTUNE_API_KEY: this.apiKey || process.env.LANGTUNE_API_KEY
12515
+ };
12497
12516
  }
12498
12517
  /**
12499
12518
  * Run a fine-tuning job using the local CLI
@@ -12526,7 +12545,10 @@ var Langtune = class {
12526
12545
  args.push("--use-lisa");
12527
12546
  }
12528
12547
  try {
12529
- await execa2(this.cliPath, args, { stdio: "inherit" });
12548
+ await execa2(this.cliPath, args, {
12549
+ stdio: "inherit",
12550
+ env: this.getEnv()
12551
+ });
12530
12552
  } catch (error) {
12531
12553
  throw new Error(`Langtune fine-tuning failed: ${error}`);
12532
12554
  }
@@ -12549,7 +12571,9 @@ var Langtune = class {
12549
12571
  args.push("--temperature", options.temperature.toString());
12550
12572
  }
12551
12573
  try {
12552
- const { stdout } = await execa2(this.cliPath, args);
12574
+ const { stdout } = await execa2(this.cliPath, args, {
12575
+ env: this.getEnv()
12576
+ });
12553
12577
  return stdout;
12554
12578
  } catch (error) {
12555
12579
  throw new Error(`Langtune generation failed: ${error}`);
@@ -12557,48 +12581,194 @@ var Langtune = class {
12557
12581
  }
12558
12582
  };
12559
12583
 
12584
+ // src/agent.ts
12585
+ import axios from "axios";
12586
+ var AgentClient = class {
12587
+ constructor(config) {
12588
+ this.config = config;
12589
+ this.client = axios.create({
12590
+ baseURL: config.baseUrl || "https://api.langtrain.ai/api/v1",
12591
+ headers: {
12592
+ "X-API-Key": config.apiKey,
12593
+ "Content-Type": "application/json"
12594
+ }
12595
+ });
12596
+ }
12597
+ async list(workspaceId) {
12598
+ const params = {};
12599
+ if (workspaceId) params.workspace_id = workspaceId;
12600
+ const response = await this.client.get("/agents", { params });
12601
+ return response.data.agents;
12602
+ }
12603
+ async execute(agentId, input, messages = [], conversationId) {
12604
+ const response = await this.client.post(`/agents/${agentId}/execute`, {
12605
+ input,
12606
+ messages,
12607
+ conversation_id: conversationId
12608
+ });
12609
+ return response.data;
12610
+ }
12611
+ };
12612
+
12560
12613
  // src/cli.ts
12561
- var vision = new Langvision();
12562
- var tune = new Langtune();
12614
+ import fs from "fs";
12615
+ import path5 from "path";
12616
+ import os3 from "os";
12617
+ import gradient from "gradient-string";
12618
+ var CONFIG_DIR = path5.join(os3.homedir(), ".langtrain");
12619
+ var CONFIG_FILE = path5.join(CONFIG_DIR, "config.json");
12620
+ function getConfig() {
12621
+ if (!fs.existsSync(CONFIG_FILE)) return {};
12622
+ try {
12623
+ return JSON.parse(fs.readFileSync(CONFIG_FILE, "utf-8"));
12624
+ } catch {
12625
+ return {};
12626
+ }
12627
+ }
12628
+ function saveConfig(config) {
12629
+ if (!fs.existsSync(CONFIG_DIR)) {
12630
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
12631
+ }
12632
+ fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
12633
+ }
12563
12634
  async function main() {
12564
12635
  const program = new Command();
12565
- program.name("langtrain").description("Langtrain CLI for AI Model Fine-tuning and Generation").version("0.1.5");
12636
+ program.name("langtrain").description("Langtrain CLI for AI Model Fine-tuning and Generation").version("0.1.9");
12566
12637
  program.action(async () => {
12567
12638
  console.clear();
12568
- intro(`${bgCyan(black(" langtrain "))}`);
12569
- const operation = await select({
12570
- message: "Select an operation:",
12571
- options: [
12572
- { value: "tune-finetune", label: "\u{1F9E0} Fine-tune Text Model (Langtune)" },
12573
- { value: "tune-generate", label: "\u{1F4DD} Generate Text (Langtune)" },
12574
- { value: "vision-finetune", label: "\u{1F441}\uFE0F Fine-tune Vision Model (Langvision)" },
12575
- { value: "vision-generate", label: "\u{1F5BC}\uFE0F Generate Vision Response (Langvision)" },
12576
- { value: "exit", label: "\u{1F6AA} Exit" }
12577
- ]
12578
- });
12579
- if (isCancel(operation) || operation === "exit") {
12580
- outro("Goodbye!");
12581
- process.exit(0);
12582
- }
12583
- try {
12584
- if (operation === "tune-finetune") {
12585
- await handleTuneFinetune();
12586
- } else if (operation === "tune-generate") {
12587
- await handleTuneGenerate();
12588
- } else if (operation === "vision-finetune") {
12589
- await handleVisionFinetune();
12590
- } else if (operation === "vision-generate") {
12591
- await handleVisionGenerate();
12639
+ const banner = `
12640
+ \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2557
12641
+ \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551
12642
+ \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551
12643
+ \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551
12644
+ \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551
12645
+ \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D
12646
+ `;
12647
+ console.log(gradient(["#00DC82", "#36E4DA", "#0047E1"])(banner));
12648
+ intro(`${bgCyan(black(" Langtrain SDK v0.1.9 "))}`);
12649
+ const config = getConfig();
12650
+ if (!config.apiKey) {
12651
+ intro(yellow("Authentication required"));
12652
+ const apiKey = await password({
12653
+ message: "Enter your Langtrain API Key:",
12654
+ validate(value) {
12655
+ if (!value || value.length === 0) return "API Key is required";
12656
+ }
12657
+ });
12658
+ if (isCancel(apiKey)) {
12659
+ cancel("Operation cancelled");
12660
+ process.exit(0);
12661
+ }
12662
+ saveConfig({ ...config, apiKey });
12663
+ intro(green("Successfully logged in!"));
12664
+ }
12665
+ while (true) {
12666
+ const operation = await select({
12667
+ message: "Select an operation:",
12668
+ options: [
12669
+ { value: "group-agents", label: "\u{1F916} Agents (Server)", hint: "Chat with custom agents" },
12670
+ { value: "agent-list", label: " \u21B3 List & Run Agents" },
12671
+ { value: "group-tune", label: "\u{1F9E0} Langtune (LLM)", hint: "Fine-tuning & Text Generation" },
12672
+ { value: "tune-finetune", label: " \u21B3 Fine-tune Text Model" },
12673
+ { value: "tune-generate", label: " \u21B3 Generate Text" },
12674
+ { value: "group-vision", label: "\u{1F441}\uFE0F Langvision (Vision)", hint: "Vision Analysis & Tuning" },
12675
+ { value: "vision-finetune", label: " \u21B3 Fine-tune Vision Model" },
12676
+ { value: "vision-generate", label: " \u21B3 Generate Vision Response" },
12677
+ { value: "group-settings", label: "\u2699\uFE0F Settings" },
12678
+ { value: "login", label: " \u21B3 Update API Key" },
12679
+ { value: "exit", label: " \u21B3 Exit" }
12680
+ ]
12681
+ });
12682
+ if (isCancel(operation) || operation === "exit") {
12683
+ outro("Goodbye!");
12684
+ process.exit(0);
12685
+ }
12686
+ if (typeof operation === "string" && operation.startsWith("group-")) {
12687
+ continue;
12688
+ }
12689
+ try {
12690
+ const currentConfig = getConfig();
12691
+ const currentVision = new Langvision({ apiKey: currentConfig.apiKey });
12692
+ const currentTune = new Langtune({ apiKey: currentConfig.apiKey });
12693
+ const currentAgent = new AgentClient({ apiKey: currentConfig.apiKey, baseUrl: currentConfig.baseUrl });
12694
+ if (operation === "login") {
12695
+ await handleLogin();
12696
+ } else if (operation === "tune-finetune") {
12697
+ await handleTuneFinetune(currentTune);
12698
+ } else if (operation === "tune-generate") {
12699
+ await handleTuneGenerate(currentTune);
12700
+ } else if (operation === "vision-finetune") {
12701
+ await handleVisionFinetune(currentVision);
12702
+ } else if (operation === "vision-generate") {
12703
+ await handleVisionGenerate(currentVision);
12704
+ } else if (operation === "agent-list") {
12705
+ await handleAgentList(currentAgent);
12706
+ }
12707
+ } catch (error) {
12708
+ outro(red(`Error: ${error.message}`));
12592
12709
  }
12593
- } catch (error) {
12594
- outro(red(`Error: ${error.message}`));
12595
- process.exit(1);
12596
12710
  }
12597
- outro(green("Operation completed successfully!"));
12598
12711
  });
12599
12712
  program.parse(process.argv);
12600
12713
  }
12601
- async function handleTuneFinetune() {
12714
+ async function handleLogin() {
12715
+ const apiKey = await password({
12716
+ message: "Enter your new Langtrain API Key:",
12717
+ validate(value) {
12718
+ if (!value || value.length === 0) return "API Key is required";
12719
+ }
12720
+ });
12721
+ if (isCancel(apiKey)) cancel("Operation cancelled");
12722
+ const config = getConfig();
12723
+ saveConfig({ ...config, apiKey });
12724
+ intro(green("API Key updated successfully!"));
12725
+ }
12726
+ async function handleAgentList(client) {
12727
+ const s = spinner();
12728
+ s.start("Fetching agents...");
12729
+ const agents = await client.list();
12730
+ s.stop(`Found ${agents.length} agents`);
12731
+ if (agents.length === 0) {
12732
+ intro(yellow("No agents found in your workspace."));
12733
+ return;
12734
+ }
12735
+ const agentId = await select({
12736
+ message: "Select an agent to run:",
12737
+ options: agents.map((a) => ({ value: a.id, label: a.name, hint: a.description || "No description" }))
12738
+ });
12739
+ if (isCancel(agentId)) return;
12740
+ await handleAgentRun(client, agentId, agents.find((a) => a.id === agentId)?.name || "Agent");
12741
+ }
12742
+ async function handleAgentRun(client, agentId, agentName) {
12743
+ intro(bgCyan(black(` Chatting with ${agentName} `)));
12744
+ console.log(gray('Type "exit" to quit conversation.'));
12745
+ let conversationId = void 0;
12746
+ while (true) {
12747
+ const input = await text({
12748
+ message: "You:",
12749
+ placeholder: "Type a message..."
12750
+ });
12751
+ if (isCancel(input) || input === "exit") {
12752
+ break;
12753
+ }
12754
+ const s = spinner();
12755
+ s.start("Agent is thinking...");
12756
+ try {
12757
+ const result = await client.execute(agentId, { prompt: input }, [], conversationId);
12758
+ s.stop();
12759
+ if (result.output && result.output.response) {
12760
+ console.log(gradient.pastel(`Agent: ${result.output.response}`));
12761
+ } else {
12762
+ console.log(gradient.pastel(`Agent: ${JSON.stringify(result.output)}`));
12763
+ }
12764
+ conversationId = result.conversation_id;
12765
+ } catch (e) {
12766
+ s.stop(red("Error running agent."));
12767
+ console.error(e);
12768
+ }
12769
+ }
12770
+ }
12771
+ async function handleTuneFinetune(tune) {
12602
12772
  const model = await text({
12603
12773
  message: "Enter base model (e.g., gpt-3.5-turbo):",
12604
12774
  placeholder: "gpt-3.5-turbo",
@@ -12622,7 +12792,9 @@ async function handleTuneFinetune() {
12622
12792
  });
12623
12793
  if (isCancel(epochs)) cancel("Operation cancelled.");
12624
12794
  const s = spinner();
12625
- s.start("Starting fine-tuning job...");
12795
+ s.start("Connecting to Langtrain Cloud...");
12796
+ await new Promise((r) => setTimeout(r, 800));
12797
+ s.message("Starting fine-tuning job...");
12626
12798
  try {
12627
12799
  const config = {
12628
12800
  model,
@@ -12636,13 +12808,13 @@ async function handleTuneFinetune() {
12636
12808
  outputDir: "./output"
12637
12809
  };
12638
12810
  await tune.finetune(config);
12639
- s.stop(green("Fine-tuning job started!"));
12811
+ s.stop(green("Fine-tuning job started successfully! \u{1F680}"));
12640
12812
  } catch (e) {
12641
12813
  s.stop(red("Failed to start job."));
12642
12814
  throw e;
12643
12815
  }
12644
12816
  }
12645
- async function handleTuneGenerate() {
12817
+ async function handleTuneGenerate(tune) {
12646
12818
  const model = await text({
12647
12819
  message: "Enter model path:",
12648
12820
  placeholder: "./output/model",
@@ -12655,18 +12827,18 @@ async function handleTuneGenerate() {
12655
12827
  });
12656
12828
  if (isCancel(prompt)) cancel("Operation cancelled");
12657
12829
  const s = spinner();
12658
- s.start("Generating response...");
12830
+ s.start("Connecting to Langtrain Inference API...");
12659
12831
  try {
12660
12832
  const response = await tune.generate(model, { prompt });
12661
12833
  s.stop("Generation complete");
12662
12834
  intro("Response:");
12663
- console.log(response);
12835
+ console.log(gradient.pastel(response));
12664
12836
  } catch (e) {
12665
12837
  s.stop(red("Generation failed."));
12666
12838
  throw e;
12667
12839
  }
12668
12840
  }
12669
- async function handleVisionFinetune() {
12841
+ async function handleVisionFinetune(vision) {
12670
12842
  const model = await text({
12671
12843
  message: "Enter base vision model:",
12672
12844
  placeholder: "llava-v1.5-7b",
@@ -12684,7 +12856,9 @@ async function handleVisionFinetune() {
12684
12856
  initialValue: "3"
12685
12857
  });
12686
12858
  const s = spinner();
12687
- s.start("Starting vision fine-tuning...");
12859
+ s.start("Analyzing dataset structure...");
12860
+ await new Promise((r) => setTimeout(r, 800));
12861
+ s.message("Starting vision fine-tuning on Langtrain Cloud...");
12688
12862
  try {
12689
12863
  const config = {
12690
12864
  model,
@@ -12696,13 +12870,13 @@ async function handleVisionFinetune() {
12696
12870
  outputDir: "./vision-output"
12697
12871
  };
12698
12872
  await vision.finetune(config);
12699
- s.stop(green("Vision fine-tuning started!"));
12873
+ s.stop(green("Vision fine-tuning started successfully! \u{1F441}\uFE0F"));
12700
12874
  } catch (e) {
12701
12875
  s.stop(red("Failed to start vision job."));
12702
12876
  throw e;
12703
12877
  }
12704
12878
  }
12705
- async function handleVisionGenerate() {
12879
+ async function handleVisionGenerate(vision) {
12706
12880
  const model = await text({
12707
12881
  message: "Enter model path:",
12708
12882
  placeholder: "./vision-output/model",
@@ -12716,12 +12890,14 @@ async function handleVisionGenerate() {
12716
12890
  });
12717
12891
  if (isCancel(prompt)) cancel("Operation cancelled");
12718
12892
  const s = spinner();
12719
- s.start("Generating vision response...");
12893
+ s.start("Uploading image and context...");
12894
+ await new Promise((r) => setTimeout(r, 600));
12895
+ s.message("Generating vision response...");
12720
12896
  try {
12721
12897
  const response = await vision.generate(model, { prompt });
12722
12898
  s.stop("Generation complete");
12723
12899
  intro("Response:");
12724
- console.log(response);
12900
+ console.log(gradient.pastel(response));
12725
12901
  } catch (e) {
12726
12902
  s.stop(red("Generation failed."));
12727
12903
  throw e;