chatgpt-api/examples/dexter/extract-user.ts

35 wiersze
780 B
TypeScript
Czysty Zwykły widok Historia

2024-07-26 21:40:34 +00:00
#!/usr/bin/env node
import 'dotenv/config'
2024-07-27 01:34:44 +00:00
import { extractObject, Msg } from '@agentic/stdlib'
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-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()
})
})
console.log(result)
}
await main()