chatgpt-api/legacy/examples/basic.ts

38 wiersze
947 B
TypeScript
Czysty Zwykły widok Historia

2023-05-26 03:30:36 +00:00
import dotenv from 'dotenv-safe'
import { OpenAIClient } from 'openai-fetch'
import { z } from 'zod'
import { Agentic } from '../src'
dotenv.config()
async function main() {
const openai = new OpenAIClient({ apiKey: process.env.OPENAI_API_KEY! })
const $ = new Agentic({ openai })
// const ex0 = await $.gpt4(`give me a single boolean value`)
// .output(z.boolean())
// // .retry({ attempts: 3 })
// .call()
// console.log(ex0)
2023-05-27 00:03:25 +00:00
const ex1 = await $.gpt4(`generate fake data`)
2023-05-26 19:06:39 +00:00
.output(z.object({ foo: z.string(), bar: z.number() }))
// .output(z.string())
// .retry({ attempts: 3 })
.call()
console.log(ex1)
// const getBoolean = $.gpt4(`are you {{mood}}?`)
// .input(z.object({ mood: z.string() }))
// .output(z.boolean())
2023-05-26 03:30:36 +00:00
2023-05-26 19:06:39 +00:00
// const results = await Promise.all([
// getBoolean.call({ mood: 'happy' }),
// getBoolean.call({ mood: 'sad' })
// ])
// console.log(results)
2023-05-26 03:30:36 +00:00
}
main()