chatgpt-api/scratch/examples/human-feedback-cli.ts

40 wiersze
1004 B
TypeScript
Czysty Zwykły widok Historia

2023-06-14 19:55:19 +00:00
import 'dotenv/config'
import { OpenAIClient } from 'openai-fetch'
import { z } from 'zod'
import { HumanFeedbackMechanismCLI } from '@/human-feedback'
import { Agentic, withHumanFeedback } from '@/index'
async function main() {
const openai = new OpenAIClient({ apiKey: process.env.OPENAI_API_KEY! })
const ai = new Agentic({ openai })
2023-06-14 19:57:15 +00:00
const topicJokes = ai
2023-06-14 19:55:19 +00:00
.gpt3(`Tell me {{num}} jokes about {{topic}}`)
.input(
z.object({
topic: z.string(),
num: z.number().int().default(5).optional()
})
)
.output(z.array(z.string()))
.modelParams({ temperature: 0.9 })
2023-06-14 19:57:15 +00:00
const topicJokesFeedback = withHumanFeedback(topicJokes, {
2023-06-14 19:55:19 +00:00
type: 'selectN',
annotations: false,
bail: false,
editing: true,
mechanism: HumanFeedbackMechanismCLI
})
2023-06-14 19:57:15 +00:00
const out = await topicJokesFeedback.callWithMetadata({
2023-06-14 19:55:19 +00:00
topic: 'politicians',
num: 5
})
const feedback = out.metadata.feedback
console.log(JSON.stringify(feedback, null, 2))
}
main()