langtrain 0.1.9 → 0.1.11

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
@@ -12600,6 +12600,17 @@ var AgentClient = class {
12600
12600
  const response = await this.client.get("/agents", { params });
12601
12601
  return response.data.agents;
12602
12602
  }
12603
+ async get(agentId) {
12604
+ const response = await this.client.get(`/agents/${agentId}`);
12605
+ return response.data;
12606
+ }
12607
+ async create(agent) {
12608
+ const response = await this.client.post("/agents/", agent);
12609
+ return response.data;
12610
+ }
12611
+ async delete(agentId) {
12612
+ await this.client.delete(`/agents/${agentId}`);
12613
+ }
12603
12614
  async execute(agentId, input, messages = [], conversationId) {
12604
12615
  const response = await this.client.post(`/agents/${agentId}/execute`, {
12605
12616
  input,
@@ -12631,9 +12642,11 @@ function saveConfig(config) {
12631
12642
  }
12632
12643
  fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
12633
12644
  }
12645
+ var packageJson = __require(path5.join(__dirname, "../package.json"));
12634
12646
  async function main() {
12635
12647
  const program = new Command();
12636
- program.name("langtrain").description("Langtrain CLI for AI Model Fine-tuning and Generation").version("0.1.9");
12648
+ const version = packageJson.version;
12649
+ program.name("langtrain").description(packageJson.description || "Langtrain CLI for AI Model Fine-tuning and Generation").version(version);
12637
12650
  program.action(async () => {
12638
12651
  console.clear();
12639
12652
  const banner = `
@@ -12645,29 +12658,34 @@ async function main() {
12645
12658
  \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
12659
  `;
12647
12660
  console.log(gradient(["#00DC82", "#36E4DA", "#0047E1"])(banner));
12648
- intro(`${bgCyan(black(" Langtrain SDK v0.1.9 "))}`);
12661
+ intro(`${bgCyan(black(` Langtrain SDK v${version} `))}`);
12649
12662
  const config = getConfig();
12650
12663
  if (!config.apiKey) {
12651
12664
  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");
12665
+ await handleLogin();
12666
+ }
12667
+ const handlers = {
12668
+ "login": handleLogin,
12669
+ "tune-finetune": (c) => handleTuneFinetune(c.tune),
12670
+ "tune-generate": (c) => handleTuneGenerate(c.tune),
12671
+ "vision-finetune": (c) => handleVisionFinetune(c.vision),
12672
+ "vision-generate": (c) => handleVisionGenerate(c.vision),
12673
+ "agent-list": (c) => handleAgentList(c.agent),
12674
+ "agent-create": (c) => handleAgentCreate(c.agent),
12675
+ "agent-delete": (c) => handleAgentDelete(c.agent),
12676
+ "exit": async () => {
12677
+ outro("Goodbye!");
12660
12678
  process.exit(0);
12661
12679
  }
12662
- saveConfig({ ...config, apiKey });
12663
- intro(green("Successfully logged in!"));
12664
- }
12680
+ };
12665
12681
  while (true) {
12666
12682
  const operation = await select({
12667
12683
  message: "Select an operation:",
12668
12684
  options: [
12669
12685
  { value: "group-agents", label: "\u{1F916} Agents (Server)", hint: "Chat with custom agents" },
12670
12686
  { value: "agent-list", label: " \u21B3 List & Run Agents" },
12687
+ { value: "agent-create", label: " \u21B3 Create New Agent" },
12688
+ { value: "agent-delete", label: " \u21B3 Delete Agent" },
12671
12689
  { value: "group-tune", label: "\u{1F9E0} Langtune (LLM)", hint: "Fine-tuning & Text Generation" },
12672
12690
  { value: "tune-finetune", label: " \u21B3 Fine-tune Text Model" },
12673
12691
  { value: "tune-generate", label: " \u21B3 Generate Text" },
@@ -12679,33 +12697,26 @@ async function main() {
12679
12697
  { value: "exit", label: " \u21B3 Exit" }
12680
12698
  ]
12681
12699
  });
12682
- if (isCancel(operation) || operation === "exit") {
12700
+ if (isCancel(operation)) {
12683
12701
  outro("Goodbye!");
12684
12702
  process.exit(0);
12685
12703
  }
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}`));
12704
+ if (typeof operation === "string") {
12705
+ if (operation.startsWith("group-")) continue;
12706
+ const handler = handlers[operation];
12707
+ if (handler) {
12708
+ try {
12709
+ const currentConfig = getConfig();
12710
+ const clients = {
12711
+ vision: new Langvision({ apiKey: currentConfig.apiKey }),
12712
+ tune: new Langtune({ apiKey: currentConfig.apiKey }),
12713
+ agent: new AgentClient({ apiKey: currentConfig.apiKey, baseUrl: currentConfig.baseUrl })
12714
+ };
12715
+ await handler(clients);
12716
+ } catch (error) {
12717
+ outro(red(`Error: ${error.message}`));
12718
+ }
12719
+ }
12709
12720
  }
12710
12721
  }
12711
12722
  });
@@ -12723,6 +12734,96 @@ async function handleLogin() {
12723
12734
  saveConfig({ ...config, apiKey });
12724
12735
  intro(green("API Key updated successfully!"));
12725
12736
  }
12737
+ async function handleAgentCreate(client) {
12738
+ const name = await text({
12739
+ message: "Agent Name:",
12740
+ placeholder: "e.g. Support Bot",
12741
+ validate(value) {
12742
+ if (value.length === 0) return "Name is required!";
12743
+ }
12744
+ });
12745
+ if (isCancel(name)) return;
12746
+ const description = await text({
12747
+ message: "Description:",
12748
+ placeholder: "e.g. A helpful support assistant"
12749
+ });
12750
+ if (isCancel(description)) return;
12751
+ const systemPrompt = await text({
12752
+ message: "System Prompt:",
12753
+ placeholder: "e.g. You are a helpful assistant.",
12754
+ initialValue: "You are a helpful assistant."
12755
+ });
12756
+ if (isCancel(systemPrompt)) return;
12757
+ const s = spinner();
12758
+ s.start("Creating agent...");
12759
+ try {
12760
+ const agents = await client.list();
12761
+ let workspaceId = "";
12762
+ if (agents.length > 0) {
12763
+ workspaceId = agents[0].workspace_id;
12764
+ } else {
12765
+ s.stop(yellow("Workspace ID needed (no existing agents found)."));
12766
+ const wid = await text({
12767
+ message: "Enter Workspace ID (UUID):",
12768
+ validate(value) {
12769
+ if (value.length === 0) return "Required";
12770
+ }
12771
+ });
12772
+ if (isCancel(wid)) return;
12773
+ workspaceId = wid;
12774
+ s.start("Creating agent...");
12775
+ }
12776
+ const agent = await client.create({
12777
+ workspace_id: workspaceId,
12778
+ name,
12779
+ description,
12780
+ config: {
12781
+ system_prompt: systemPrompt,
12782
+ model: "gpt-4o"
12783
+ // Default or prompt? simplified
12784
+ }
12785
+ });
12786
+ s.stop(green(`Agent "${agent.name}" created successfully! ID: ${agent.id}`));
12787
+ } catch (e) {
12788
+ s.stop(red("Failed to create agent."));
12789
+ throw e;
12790
+ }
12791
+ }
12792
+ async function handleAgentDelete(client) {
12793
+ const s = spinner();
12794
+ s.start("Fetching agents...");
12795
+ const agents = await client.list();
12796
+ s.stop(`Found ${agents.length} agents`);
12797
+ if (agents.length === 0) {
12798
+ intro(yellow("No agents to delete."));
12799
+ return;
12800
+ }
12801
+ const agentId = await select({
12802
+ message: "Select an agent to DELETE:",
12803
+ options: agents.map((a) => ({ value: a.id, label: a.name, hint: a.description || "No description" }))
12804
+ });
12805
+ if (isCancel(agentId)) return;
12806
+ const confirm = await select({
12807
+ message: `Are you sure you want to delete this agent?`,
12808
+ options: [
12809
+ { value: "yes", label: "Yes, delete it", hint: "Cannot be undone" },
12810
+ { value: "no", label: "No, keep it" }
12811
+ ]
12812
+ });
12813
+ if (confirm !== "yes") {
12814
+ intro(gray("Deletion cancelled."));
12815
+ return;
12816
+ }
12817
+ const d = spinner();
12818
+ d.start("Deleting agent...");
12819
+ try {
12820
+ await client.delete(agentId);
12821
+ d.stop(green("Agent deleted successfully."));
12822
+ } catch (e) {
12823
+ d.stop(red("Failed to delete agent."));
12824
+ throw e;
12825
+ }
12826
+ }
12726
12827
  async function handleAgentList(client) {
12727
12828
  const s = spinner();
12728
12829
  s.start("Fetching agents...");