2024-07-26 21:40:34 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
import 'dotenv/config'
|
|
|
|
|
2024-08-04 06:32:30 +00:00
|
|
|
import { extractObject, Msg } from '@agentic/core'
|
2024-07-26 21:40:34 +00:00
|
|
|
import { ChatModel } from '@dexaai/dexter'
|
|
|
|
import { z } from 'zod'
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const chatModel = new ChatModel({
|
2024-07-27 01:34:44 +00:00
|
|
|
params: { model: 'gpt-4o-mini', temperature: 0 },
|
2024-07-26 21:40:34 +00:00
|
|
|
debug: true
|
|
|
|
})
|
|
|
|
|
2024-07-27 01:34:44 +00:00
|
|
|
const result = await extractObject({
|
2024-08-07 09:52:49 +00:00
|
|
|
name: 'extract-user',
|
2024-07-26 21:40:34 +00:00
|
|
|
chatFn: chatModel.run.bind(chatModel),
|
|
|
|
params: {
|
2024-07-27 01:34:44 +00:00
|
|
|
messages: [
|
|
|
|
Msg.system('Extract a JSON user object from the given text.'),
|
|
|
|
Msg.user(
|
|
|
|
'Bob Vance is 42 years old and lives in Brooklyn, NY. He is a software engineer.'
|
|
|
|
)
|
|
|
|
]
|
2024-07-26 21:40:34 +00:00
|
|
|
},
|
|
|
|
schema: z.object({
|
|
|
|
name: z.string(),
|
|
|
|
age: z.number(),
|
|
|
|
location: z.string().optional()
|
2024-08-07 09:52:49 +00:00
|
|
|
}),
|
|
|
|
strict: true
|
2024-07-26 21:40:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
console.log(result)
|
|
|
|
}
|
|
|
|
|
|
|
|
await main()
|