From 0084f5552476e15a1e165da392e7b775b45614e3 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Wed, 14 Jun 2023 15:59:12 -0400 Subject: [PATCH] docs: add feedback examples for Slack and Twilio --- .../scratch/examples/human-feedback-slack.ts | 39 +++++++++++++++++++ .../scratch/examples/human-feedback-twilio.ts | 39 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 legacy/scratch/examples/human-feedback-slack.ts create mode 100644 legacy/scratch/examples/human-feedback-twilio.ts diff --git a/legacy/scratch/examples/human-feedback-slack.ts b/legacy/scratch/examples/human-feedback-slack.ts new file mode 100644 index 00000000..c1b21e69 --- /dev/null +++ b/legacy/scratch/examples/human-feedback-slack.ts @@ -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() diff --git a/legacy/scratch/examples/human-feedback-twilio.ts b/legacy/scratch/examples/human-feedback-twilio.ts new file mode 100644 index 00000000..e94807b8 --- /dev/null +++ b/legacy/scratch/examples/human-feedback-twilio.ts @@ -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()