docs: add feedback examples for Slack and Twilio

old-agentic-v1^2
Philipp Burckhardt 2023-06-14 15:59:12 -04:00 zatwierdzone przez Travis Fischer
rodzic 4ff22618a2
commit 8ba59411e7
2 zmienionych plików z 78 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,39 @@
import 'dotenv/config'
import { OpenAIClient } from 'openai-fetch'
import { z } from 'zod'
import { HumanFeedbackMechanismSlack } 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 })
const topicJokes = ai
.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 })
const topicJokesFeedback = withHumanFeedback(topicJokes, {
type: 'selectN',
annotations: false,
bail: false,
editing: true,
mechanism: HumanFeedbackMechanismSlack
})
const out = await topicJokesFeedback.callWithMetadata({
topic: 'politicians',
num: 5
})
const feedback = out.metadata.feedback
console.log(JSON.stringify(feedback, null, 2))
}
main()

Wyświetl plik

@ -0,0 +1,39 @@
import 'dotenv/config'
import { OpenAIClient } from 'openai-fetch'
import { z } from 'zod'
import { HumanFeedbackMechanismTwilio } 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 })
const topicJokes = ai
.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 })
const topicJokesFeedback = withHumanFeedback(topicJokes, {
type: 'selectN',
annotations: false,
bail: false,
editing: true,
mechanism: HumanFeedbackMechanismTwilio
})
const out = await topicJokesFeedback.callWithMetadata({
topic: 'politicians',
num: 5
})
const feedback = out.metadata.feedback
console.log(JSON.stringify(feedback, null, 2))
}
main()