chatgpt-api/scratch/examples/json-summary.ts

36 wiersze
896 B
TypeScript
Czysty Zwykły widok Historia

2023-06-01 01:53:09 +00:00
import 'dotenv/config'
2023-05-27 00:38:55 +00:00
import { OpenAIClient } from 'openai-fetch'
import { z } from 'zod'
import { Agentic } from '../src'
2023-05-27 00:58:46 +00:00
export async function main() {
2023-05-27 00:38:55 +00:00
const openai = new OpenAIClient({ apiKey: process.env.OPENAI_API_KEY! })
const $ = new Agentic({ openai })
2023-05-27 00:58:46 +00:00
const article = await $.gpt3(
'Generate a fake, short Wikipedia article.'
2023-05-27 00:38:55 +00:00
).call()
2023-05-27 00:58:46 +00:00
const example = await $.gpt3(
2023-05-27 00:38:55 +00:00
`You are a wikipedia article summarizer. However,
you return a bunch of important information about the article in JSON format.
You're really good at coming up with semantic labels for the information you find.
Article: {{article}}`
)
.input(z.object({ article: z.string() }))
.output(
z.object({
title: z.string(),
2023-05-27 00:58:46 +00:00
summary: z.string()
2023-05-27 00:38:55 +00:00
})
)
2023-05-27 00:58:46 +00:00
// .assert((output) => JSON.parse(output.summary))
2023-05-27 00:38:55 +00:00
.call({
article
})
}
2023-05-27 00:58:46 +00:00
main()