|
| 1 | +import { defineCommand, prepareBatch, batchDataNotes, type FlagsDef } from "bailian-cli-core"; |
| 2 | +import { emitBare, emitResult } from "bailian-cli-runtime"; |
| 3 | +import { ENDPOINT_FLAGS, FORCE_FLAGS, DRY_RUN_NOTE } from "./shared.ts"; |
| 4 | +const CONVERT_FLAGS = { |
| 5 | + file: { |
| 6 | + type: "string", |
| 7 | + required: true, |
| 8 | + valueHint: "<csv>", |
| 9 | + description: { "en-US": "UTF-8 CSV with headers", "zh-CN": "带表头的 UTF-8 CSV" }, |
| 10 | + }, |
| 11 | + outputFile: { |
| 12 | + type: "string", |
| 13 | + required: true, |
| 14 | + valueHint: "<jsonl>", |
| 15 | + description: { "en-US": "Local JSONL output path", "zh-CN": "本地 JSONL 输出路径" }, |
| 16 | + }, |
| 17 | + model: { |
| 18 | + type: "string", |
| 19 | + required: true, |
| 20 | + valueHint: "<model>", |
| 21 | + description: { "en-US": "Model for every record", "zh-CN": "全部记录统一使用的模型" }, |
| 22 | + }, |
| 23 | + idColumn: { |
| 24 | + type: "string", |
| 25 | + valueHint: "<name>", |
| 26 | + description: { "en-US": "ID column (default: custom_id)", "zh-CN": "ID 列(默认:custom_id)" }, |
| 27 | + }, |
| 28 | + inputColumn: { |
| 29 | + type: "string", |
| 30 | + valueHint: "<name>", |
| 31 | + description: { "en-US": "Input column (default: content)", "zh-CN": "输入列(默认:content)" }, |
| 32 | + }, |
| 33 | + system: { |
| 34 | + type: "string", |
| 35 | + valueHint: "<text>", |
| 36 | + description: { |
| 37 | + "en-US": "Shared system prompt (Chat only)", |
| 38 | + "zh-CN": "统一系统提示词(仅 Chat)", |
| 39 | + }, |
| 40 | + }, |
| 41 | + bodyFile: { |
| 42 | + type: "string", |
| 43 | + valueHint: "<json>", |
| 44 | + description: { |
| 45 | + "en-US": "Shared body parameters, excluding model/messages/input", |
| 46 | + "zh-CN": "公共 body 参数,不得包含 model/messages/input", |
| 47 | + }, |
| 48 | + }, |
| 49 | + ...ENDPOINT_FLAGS, |
| 50 | + ...FORCE_FLAGS, |
| 51 | +} satisfies FlagsDef; |
| 52 | +export default defineCommand({ |
| 53 | + description: { |
| 54 | + "en-US": "Build Batch JSONL from CSV locally", |
| 55 | + "zh-CN": "在本地从 CSV 构造 Batch JSONL", |
| 56 | + }, |
| 57 | + auth: "none", |
| 58 | + usageArgs: "--file <csv> --model <model> --output-file <jsonl> [flags]", |
| 59 | + flags: CONVERT_FLAGS, |
| 60 | + exampleArgs: [ |
| 61 | + "--file input.csv --model qwen-plus --output-file input.jsonl", |
| 62 | + "--file input.csv --model text-embedding-v4 --endpoint /v1/embeddings --output-file vectors.jsonl", |
| 63 | + "--file input.csv --model qwen-plus --body-file defaults.json --output-file input.jsonl --dry-run", |
| 64 | + ], |
| 65 | + notes: [ |
| 66 | + batchDataNotes("convert"), |
| 67 | + { |
| 68 | + "en-US": |
| 69 | + "Text/embedding mapping only; use native JSONL for multimodal or multi-turn input. IDs remain strings; import CSV IDs as text in spreadsheet software.", |
| 70 | + "zh-CN": |
| 71 | + "仅提供文本/向量映射;多模态、多轮输入使用原生 JSONL。ID 保持字符串,表格软件导入 ID 时请选择文本类型。", |
| 72 | + }, |
| 73 | + DRY_RUN_NOTE, |
| 74 | + ], |
| 75 | + async run(ctx) { |
| 76 | + const report = await prepareBatch({ ...ctx.flags, dryRun: ctx.settings.dryRun }); |
| 77 | + for (const warning of report.warnings) console.error(warning); |
| 78 | + if (ctx.settings.quiet) emitBare(report.output_file); |
| 79 | + else emitResult(report, ctx.settings.output === "text" ? "text" : "json"); |
| 80 | + }, |
| 81 | +}); |
0 commit comments