Skip to content

Instantly share code, notes, and snippets.

@up1
Last active November 4, 2024 08:12
Show Gist options
  • Save up1/8b45d0f12eb4bfc188132e4ce6388d01 to your computer and use it in GitHub Desktop.
Save up1/8b45d0f12eb4bfc188132e4ce6388d01 to your computer and use it in GitHub Desktop.
GenAI Script
$npx genaiscript run genaisrc/demo01.genai.mjs
genaiscript: genaisrc/demo01.genai.mjs
trace: /.genaiscript/runs/demo01/2024-11-04T08-11-49-564Z.trace.md
prompting openai:gpt-4o (~543 tokens)
```json schema=CITY_SCHEMA
[
{
"name": "Bangkok",
"population": 10539000,
"url": "https://en.wikipedia.org/wiki/Bangkok"
},
{
"name": "Chiang Mai",
"population": 127240,
"url": "https://en.wikipedia.org/wiki/Chiang_Mai"
},
{
"name": "Phuket",
"population": 416582,
"url": "https://en.wikipedia.org/wiki/Phuket_(city)"
},
{
"name": "Pattaya",
"population": 119530,
"url": "https://en.wikipedia.org/wiki/Pattaya"
},
{
"name": "Hat Yai",
"population": 156802,
"url": "https://en.wikipedia.org/wiki/Hat_Yai"
},
{
"name": "Nakhon Ratchasima",
"population": 174332,
"url": "https://en.wikipedia.org/wiki/Nakhon_Ratchasima"
},
{
"name": "Khon Kaen",
"population": 113754,
"url": "https://en.wikipedia.org/wiki/Khon_Kaen"
},
{
"name": "Udon Thani",
"population": 130531,
"url": "https://en.wikipedia.org/wiki/Udon_Thani"
},
{
"name": "Surat Thani",
"population": 132040,
"url": "https://en.wikipedia.org/wiki/Surat_Thani"
},
{
"name": "Nakhon Si Thammarat",
"population": 105417,
"url": "https://en.wikipedia.org/wiki/Nakhon_Si_Thammarat"
}
]
```
genaiscript: success
> 914 tokens (511 -> 403) 0.531¢
openai:gpt-4o-2024-08-06> 914 tokens (511 -> 403) 0.531¢
script({
model: "openai:gpt-4o",
})
const schema = defSchema("CITY_SCHEMA", {
type: "array",
description: "A list of Thailand's cities with population and elevation information.",
items: {
type: "object",
description: "A city with population and elevation information.",
properties: {
name: { type: "string", description: "The name of the city." },
population: { type: "number", description: "The population of the city." },
url: { type: "string", description: "The URL of the city's Wikipedia page." }
},
required: ["name", "population", "url"]
}
})
$`Generate 10 data items using JSON compliant with ${schema}.`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment