chatgpt-api/examples/facts.ts

27 wiersze
630 B
TypeScript
Czysty Zwykły widok Historia

import { OpenAIClient } from '@agentic/openai-fetch'
2023-06-01 01:53:09 +00:00
import 'dotenv/config'
import { z } from 'zod'
2023-06-07 19:13:01 +00:00
import { Agentic } from '@/agentic'
async function main() {
const openai = new OpenAIClient({ apiKey: process.env.OPENAI_API_KEY! })
const ai = new Agentic({ openai })
const out = await ai
2023-05-27 01:18:15 +00:00
.gpt3(`Give me {{numFacts}} random facts about {{topic}}`)
.input(
2023-06-01 01:56:21 +00:00
z.object({
topic: z.string(),
numFacts: z.number().int().default(5)
2023-06-01 01:56:21 +00:00
})
2023-05-27 01:18:15 +00:00
)
.output(z.object({ facts: z.array(z.string()) }))
.modelParams({ temperature: 0.9 })
.call({ topic: 'cats' })
2023-05-26 03:30:36 +00:00
console.log(out)
}
main()