Public
Script
Forked from substrate/shapeshift
July 18, 2024
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 { ComputeJSON, ComputeText, sb, Substrate } from "npm:substrate";
import { z } from "npm:zod";
import { zodToJsonSchema } from "npm:zod-to-json-schema";
const substrate = new Substrate({ apiKey: Deno.env.get("SUBSTRATE_API_KEY")});
const sourceObj = {
personalInfo: {
name: "John Doe",
age: 30,
},
occupation: "Software Engineer",
fullAddress: "123 Main St, Anytown",
address: {
street: "123 Main St",
city: "Anytown",
},
};
const TargetObjSchema = z.object({
fullName: z.string(),
yearsOld: z.number().int().nonnegative(),
profession: z.string(),
location: z.object({
streetAddress: z.string(),
cityName: z.string(),
}),
});
const json = new ComputeJSON({
prompt: `Translate the following JSON object to the target schema.
${JSON.stringify(sourceObj)}`,
json_schema: zodToJsonSchema(TargetObjSchema),
})
const res = await substrate.run(json);
console.log(JSON.stringify(res.get(json).json_object, null, 2));
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
July 18, 2024