kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
35 wiersze
780 B
JavaScript
35 wiersze
780 B
JavaScript
#!/usr/bin/env node
|
|
import 'dotenv/config'
|
|
|
|
import { extractObject, Msg } from '@agentic/stdlib'
|
|
import { ChatModel } from '@dexaai/dexter'
|
|
import { z } from 'zod'
|
|
|
|
async function main() {
|
|
const chatModel = new ChatModel({
|
|
params: { model: 'gpt-4o-mini', temperature: 0 },
|
|
debug: true
|
|
})
|
|
|
|
const result = await extractObject({
|
|
chatFn: chatModel.run.bind(chatModel),
|
|
params: {
|
|
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.'
|
|
)
|
|
]
|
|
},
|
|
schema: z.object({
|
|
name: z.string(),
|
|
age: z.number(),
|
|
location: z.string().optional()
|
|
})
|
|
})
|
|
|
|
console.log(result)
|
|
}
|
|
|
|
await main()
|