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/README.md +1 -1
- package/dist/cli.js +138 -37
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +138 -37
- package/dist/cli.mjs.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/agent.ts +30 -0
- package/src/cli.ts +167 -49
- package/src/index.ts +1 -1
- package/dist/cli.d.mts +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/index.d.mts +0 -47
- package/dist/index.d.ts +0 -47
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/langtrain-ai/langtrain-sdk/main/public/langtrain-black.svg">
|
|
5
5
|
<img alt="Langtrain Logo" src="https://raw.githubusercontent.com/langtrain-ai/langtrain-sdk/main/public/langtrain-black.svg" width="250">
|
|
6
6
|
</picture>
|
|
7
|
-
<
|
|
7
|
+
<h3>Langtrain SDK</h3>
|
|
8
8
|
<p>
|
|
9
9
|
The unified intelligence layer for JavaScript applications. <br/>
|
|
10
10
|
Combine computer vision and LLM fine-tuning in a single, high-performance SDK.
|
package/dist/cli.js
CHANGED
|
@@ -12595,6 +12595,17 @@ var AgentClient = class {
|
|
|
12595
12595
|
const response = await this.client.get("/agents", { params });
|
|
12596
12596
|
return response.data.agents;
|
|
12597
12597
|
}
|
|
12598
|
+
async get(agentId) {
|
|
12599
|
+
const response = await this.client.get(`/agents/${agentId}`);
|
|
12600
|
+
return response.data;
|
|
12601
|
+
}
|
|
12602
|
+
async create(agent) {
|
|
12603
|
+
const response = await this.client.post("/agents/", agent);
|
|
12604
|
+
return response.data;
|
|
12605
|
+
}
|
|
12606
|
+
async delete(agentId) {
|
|
12607
|
+
await this.client.delete(`/agents/${agentId}`);
|
|
12608
|
+
}
|
|
12598
12609
|
async execute(agentId, input, messages = [], conversationId) {
|
|
12599
12610
|
const response = await this.client.post(`/agents/${agentId}/execute`, {
|
|
12600
12611
|
input,
|
|
@@ -12626,9 +12637,11 @@ function saveConfig(config) {
|
|
|
12626
12637
|
}
|
|
12627
12638
|
import_fs.default.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
12628
12639
|
}
|
|
12640
|
+
var packageJson = require(import_path.default.join(__dirname, "../package.json"));
|
|
12629
12641
|
async function main() {
|
|
12630
12642
|
const program = new import_commander.Command();
|
|
12631
|
-
|
|
12643
|
+
const version = packageJson.version;
|
|
12644
|
+
program.name("langtrain").description(packageJson.description || "Langtrain CLI for AI Model Fine-tuning and Generation").version(version);
|
|
12632
12645
|
program.action(async () => {
|
|
12633
12646
|
console.clear();
|
|
12634
12647
|
const banner = `
|
|
@@ -12640,29 +12653,34 @@ async function main() {
|
|
|
12640
12653
|
\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
|
|
12641
12654
|
`;
|
|
12642
12655
|
console.log((0, import_gradient_string.default)(["#00DC82", "#36E4DA", "#0047E1"])(banner));
|
|
12643
|
-
(0, import_prompts.intro)(`${(0, import_colors.bgCyan)((0, import_colors.black)(
|
|
12656
|
+
(0, import_prompts.intro)(`${(0, import_colors.bgCyan)((0, import_colors.black)(` Langtrain SDK v${version} `))}`);
|
|
12644
12657
|
const config = getConfig();
|
|
12645
12658
|
if (!config.apiKey) {
|
|
12646
12659
|
(0, import_prompts.intro)((0, import_colors.yellow)("Authentication required"));
|
|
12647
|
-
|
|
12648
|
-
|
|
12649
|
-
|
|
12650
|
-
|
|
12651
|
-
|
|
12652
|
-
|
|
12653
|
-
|
|
12654
|
-
|
|
12660
|
+
await handleLogin();
|
|
12661
|
+
}
|
|
12662
|
+
const handlers = {
|
|
12663
|
+
"login": handleLogin,
|
|
12664
|
+
"tune-finetune": (c) => handleTuneFinetune(c.tune),
|
|
12665
|
+
"tune-generate": (c) => handleTuneGenerate(c.tune),
|
|
12666
|
+
"vision-finetune": (c) => handleVisionFinetune(c.vision),
|
|
12667
|
+
"vision-generate": (c) => handleVisionGenerate(c.vision),
|
|
12668
|
+
"agent-list": (c) => handleAgentList(c.agent),
|
|
12669
|
+
"agent-create": (c) => handleAgentCreate(c.agent),
|
|
12670
|
+
"agent-delete": (c) => handleAgentDelete(c.agent),
|
|
12671
|
+
"exit": async () => {
|
|
12672
|
+
(0, import_prompts.outro)("Goodbye!");
|
|
12655
12673
|
process.exit(0);
|
|
12656
12674
|
}
|
|
12657
|
-
|
|
12658
|
-
(0, import_prompts.intro)((0, import_colors.green)("Successfully logged in!"));
|
|
12659
|
-
}
|
|
12675
|
+
};
|
|
12660
12676
|
while (true) {
|
|
12661
12677
|
const operation = await (0, import_prompts.select)({
|
|
12662
12678
|
message: "Select an operation:",
|
|
12663
12679
|
options: [
|
|
12664
12680
|
{ value: "group-agents", label: "\u{1F916} Agents (Server)", hint: "Chat with custom agents" },
|
|
12665
12681
|
{ value: "agent-list", label: " \u21B3 List & Run Agents" },
|
|
12682
|
+
{ value: "agent-create", label: " \u21B3 Create New Agent" },
|
|
12683
|
+
{ value: "agent-delete", label: " \u21B3 Delete Agent" },
|
|
12666
12684
|
{ value: "group-tune", label: "\u{1F9E0} Langtune (LLM)", hint: "Fine-tuning & Text Generation" },
|
|
12667
12685
|
{ value: "tune-finetune", label: " \u21B3 Fine-tune Text Model" },
|
|
12668
12686
|
{ value: "tune-generate", label: " \u21B3 Generate Text" },
|
|
@@ -12674,33 +12692,26 @@ async function main() {
|
|
|
12674
12692
|
{ value: "exit", label: " \u21B3 Exit" }
|
|
12675
12693
|
]
|
|
12676
12694
|
});
|
|
12677
|
-
if ((0, import_prompts.isCancel)(operation)
|
|
12695
|
+
if ((0, import_prompts.isCancel)(operation)) {
|
|
12678
12696
|
(0, import_prompts.outro)("Goodbye!");
|
|
12679
12697
|
process.exit(0);
|
|
12680
12698
|
}
|
|
12681
|
-
if (typeof operation === "string"
|
|
12682
|
-
continue;
|
|
12683
|
-
|
|
12684
|
-
|
|
12685
|
-
|
|
12686
|
-
|
|
12687
|
-
|
|
12688
|
-
|
|
12689
|
-
|
|
12690
|
-
|
|
12691
|
-
|
|
12692
|
-
|
|
12693
|
-
|
|
12694
|
-
|
|
12695
|
-
|
|
12696
|
-
|
|
12697
|
-
} else if (operation === "vision-generate") {
|
|
12698
|
-
await handleVisionGenerate(currentVision);
|
|
12699
|
-
} else if (operation === "agent-list") {
|
|
12700
|
-
await handleAgentList(currentAgent);
|
|
12701
|
-
}
|
|
12702
|
-
} catch (error) {
|
|
12703
|
-
(0, import_prompts.outro)((0, import_colors.red)(`Error: ${error.message}`));
|
|
12699
|
+
if (typeof operation === "string") {
|
|
12700
|
+
if (operation.startsWith("group-")) continue;
|
|
12701
|
+
const handler = handlers[operation];
|
|
12702
|
+
if (handler) {
|
|
12703
|
+
try {
|
|
12704
|
+
const currentConfig = getConfig();
|
|
12705
|
+
const clients = {
|
|
12706
|
+
vision: new Langvision({ apiKey: currentConfig.apiKey }),
|
|
12707
|
+
tune: new Langtune({ apiKey: currentConfig.apiKey }),
|
|
12708
|
+
agent: new AgentClient({ apiKey: currentConfig.apiKey, baseUrl: currentConfig.baseUrl })
|
|
12709
|
+
};
|
|
12710
|
+
await handler(clients);
|
|
12711
|
+
} catch (error) {
|
|
12712
|
+
(0, import_prompts.outro)((0, import_colors.red)(`Error: ${error.message}`));
|
|
12713
|
+
}
|
|
12714
|
+
}
|
|
12704
12715
|
}
|
|
12705
12716
|
}
|
|
12706
12717
|
});
|
|
@@ -12718,6 +12729,96 @@ async function handleLogin() {
|
|
|
12718
12729
|
saveConfig({ ...config, apiKey });
|
|
12719
12730
|
(0, import_prompts.intro)((0, import_colors.green)("API Key updated successfully!"));
|
|
12720
12731
|
}
|
|
12732
|
+
async function handleAgentCreate(client) {
|
|
12733
|
+
const name = await (0, import_prompts.text)({
|
|
12734
|
+
message: "Agent Name:",
|
|
12735
|
+
placeholder: "e.g. Support Bot",
|
|
12736
|
+
validate(value) {
|
|
12737
|
+
if (value.length === 0) return "Name is required!";
|
|
12738
|
+
}
|
|
12739
|
+
});
|
|
12740
|
+
if ((0, import_prompts.isCancel)(name)) return;
|
|
12741
|
+
const description = await (0, import_prompts.text)({
|
|
12742
|
+
message: "Description:",
|
|
12743
|
+
placeholder: "e.g. A helpful support assistant"
|
|
12744
|
+
});
|
|
12745
|
+
if ((0, import_prompts.isCancel)(description)) return;
|
|
12746
|
+
const systemPrompt = await (0, import_prompts.text)({
|
|
12747
|
+
message: "System Prompt:",
|
|
12748
|
+
placeholder: "e.g. You are a helpful assistant.",
|
|
12749
|
+
initialValue: "You are a helpful assistant."
|
|
12750
|
+
});
|
|
12751
|
+
if ((0, import_prompts.isCancel)(systemPrompt)) return;
|
|
12752
|
+
const s = (0, import_prompts.spinner)();
|
|
12753
|
+
s.start("Creating agent...");
|
|
12754
|
+
try {
|
|
12755
|
+
const agents = await client.list();
|
|
12756
|
+
let workspaceId = "";
|
|
12757
|
+
if (agents.length > 0) {
|
|
12758
|
+
workspaceId = agents[0].workspace_id;
|
|
12759
|
+
} else {
|
|
12760
|
+
s.stop((0, import_colors.yellow)("Workspace ID needed (no existing agents found)."));
|
|
12761
|
+
const wid = await (0, import_prompts.text)({
|
|
12762
|
+
message: "Enter Workspace ID (UUID):",
|
|
12763
|
+
validate(value) {
|
|
12764
|
+
if (value.length === 0) return "Required";
|
|
12765
|
+
}
|
|
12766
|
+
});
|
|
12767
|
+
if ((0, import_prompts.isCancel)(wid)) return;
|
|
12768
|
+
workspaceId = wid;
|
|
12769
|
+
s.start("Creating agent...");
|
|
12770
|
+
}
|
|
12771
|
+
const agent = await client.create({
|
|
12772
|
+
workspace_id: workspaceId,
|
|
12773
|
+
name,
|
|
12774
|
+
description,
|
|
12775
|
+
config: {
|
|
12776
|
+
system_prompt: systemPrompt,
|
|
12777
|
+
model: "gpt-4o"
|
|
12778
|
+
// Default or prompt? simplified
|
|
12779
|
+
}
|
|
12780
|
+
});
|
|
12781
|
+
s.stop((0, import_colors.green)(`Agent "${agent.name}" created successfully! ID: ${agent.id}`));
|
|
12782
|
+
} catch (e) {
|
|
12783
|
+
s.stop((0, import_colors.red)("Failed to create agent."));
|
|
12784
|
+
throw e;
|
|
12785
|
+
}
|
|
12786
|
+
}
|
|
12787
|
+
async function handleAgentDelete(client) {
|
|
12788
|
+
const s = (0, import_prompts.spinner)();
|
|
12789
|
+
s.start("Fetching agents...");
|
|
12790
|
+
const agents = await client.list();
|
|
12791
|
+
s.stop(`Found ${agents.length} agents`);
|
|
12792
|
+
if (agents.length === 0) {
|
|
12793
|
+
(0, import_prompts.intro)((0, import_colors.yellow)("No agents to delete."));
|
|
12794
|
+
return;
|
|
12795
|
+
}
|
|
12796
|
+
const agentId = await (0, import_prompts.select)({
|
|
12797
|
+
message: "Select an agent to DELETE:",
|
|
12798
|
+
options: agents.map((a) => ({ value: a.id, label: a.name, hint: a.description || "No description" }))
|
|
12799
|
+
});
|
|
12800
|
+
if ((0, import_prompts.isCancel)(agentId)) return;
|
|
12801
|
+
const confirm = await (0, import_prompts.select)({
|
|
12802
|
+
message: `Are you sure you want to delete this agent?`,
|
|
12803
|
+
options: [
|
|
12804
|
+
{ value: "yes", label: "Yes, delete it", hint: "Cannot be undone" },
|
|
12805
|
+
{ value: "no", label: "No, keep it" }
|
|
12806
|
+
]
|
|
12807
|
+
});
|
|
12808
|
+
if (confirm !== "yes") {
|
|
12809
|
+
(0, import_prompts.intro)((0, import_colors.gray)("Deletion cancelled."));
|
|
12810
|
+
return;
|
|
12811
|
+
}
|
|
12812
|
+
const d = (0, import_prompts.spinner)();
|
|
12813
|
+
d.start("Deleting agent...");
|
|
12814
|
+
try {
|
|
12815
|
+
await client.delete(agentId);
|
|
12816
|
+
d.stop((0, import_colors.green)("Agent deleted successfully."));
|
|
12817
|
+
} catch (e) {
|
|
12818
|
+
d.stop((0, import_colors.red)("Failed to delete agent."));
|
|
12819
|
+
throw e;
|
|
12820
|
+
}
|
|
12821
|
+
}
|
|
12721
12822
|
async function handleAgentList(client) {
|
|
12722
12823
|
const s = (0, import_prompts.spinner)();
|
|
12723
12824
|
s.start("Fetching agents...");
|