-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerate-schema.ts
More file actions
37 lines (33 loc) · 1.12 KB
/
generate-schema.ts
File metadata and controls
37 lines (33 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { defineCommand } from "citty";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";
import * as scrapegraphai from "../lib/scrapegraphai.js";
export default defineCommand({
meta: {
name: "generate-schema",
description: "Generate a JSON schema from a natural language prompt",
},
args: {
prompt: {
type: "positional",
description: "Describe the schema you need",
required: true,
},
"existing-schema": {
type: "string",
description: "Existing schema to modify (as JSON string)",
},
json: { type: "boolean", description: "Output raw JSON (pipeable)" },
},
run: async ({ args }) => {
const out = log.create(!!args.json);
const key = await resolveApiKey(!!args.json);
const params: scrapegraphai.GenerateSchemaParams = { user_prompt: args.prompt };
if (args["existing-schema"]) params.existing_schema = JSON.parse(args["existing-schema"]);
out.start("Generating schema");
const result = await scrapegraphai.generateSchema(key, params, out.poll);
out.stop(result.elapsedMs);
if (result.data) out.result(result.data);
else out.error(result.error);
},
});