From 06c4d93f9c2c895193094e56d544756ecc4a9315 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sun, 25 Jun 2023 16:18:06 -0400 Subject: [PATCH] docs: add and update examples --- examples/article-highlights.ts | 46 ++++++++++++++++++++++++++++ examples/people.ts | 50 +++++++++++++++++++++++++++++++ examples/search-and-crawl.ts | 6 ++-- examples/sentiment.ts | 2 +- examples/transcript-highlights.ts | 48 +++++++++++++++++++++++++++++ 5 files changed, 148 insertions(+), 4 deletions(-) create mode 100644 examples/article-highlights.ts create mode 100644 examples/people.ts create mode 100644 examples/transcript-highlights.ts diff --git a/examples/article-highlights.ts b/examples/article-highlights.ts new file mode 100644 index 0000000..56b4226 --- /dev/null +++ b/examples/article-highlights.ts @@ -0,0 +1,46 @@ +import 'dotenv/config' +import { readFileSync } from 'fs' +import { OpenAIClient } from 'openai-fetch' +import { z } from 'zod' + +import { Agentic } from '@/index' + +async function main() { + const openai = new OpenAIClient({ apiKey: process.env.OPENAI_API_KEY! }) + const agentic = new Agentic({ openai }) + + const fileName = process.argv[2] + const article = readFileSync(fileName, 'utf-8') + + const res = await agentic + .gpt4({ + messages: [ + { + role: 'system', + content: `You are a social media manager who is an expert at writing social media posts. You are generating draft posts advertising an article. Return a list of the best quotes from the article as they relate to its topic. Return not more than three sentences per quote.` + }, + { + role: 'user', + content: `Process the following article: {{article}}.` + } + ], + model: 'gpt-4-32k' + }) + .input( + z.object({ + article: z.string() + }) + ) + .output( + z.array( + z.object({ + quote: z.string() + }) + ) + ) + .call({ article }) + + console.log(`\n\n\n${JSON.stringify(res, null, 2)}\n\n\n`) +} + +main() diff --git a/examples/people.ts b/examples/people.ts new file mode 100644 index 0000000..7f455a7 --- /dev/null +++ b/examples/people.ts @@ -0,0 +1,50 @@ +import 'dotenv/config' +import { OpenAIClient } from 'openai-fetch' +import { z } from 'zod' + +import { Agentic, SearchAndCrawlTool } from '@/index' + +async function main() { + const openai = new OpenAIClient({ apiKey: process.env.OPENAI_API_KEY! }) + const agentic = new Agentic({ openai }) + + const person = process.argv[2] + if (!person) { + console.log('Please provide a person') + return + } + + const res = await agentic + .gpt4({ + messages: [ + { + role: 'system', + content: `You are research assistant who is an expert at doing background research on people. Specifically, you will find people who have written about or worked with {{person}}. Besides their name, generate a short explanation of their relationship.` + }, + { + role: 'user', + content: `Find people who have written about or worked with {{person}}.` + } + ], + model: 'gpt-4-32k' + }) + .tools([new SearchAndCrawlTool()]) + .input( + z.object({ + person: z.string() + }) + ) + .output( + z.array( + z.object({ + name: z.string(), + relationship: z.string() + }) + ) + ) + .call({ person }) + + console.log(`\n\n\n${JSON.stringify(res, null, 2)}\n\n\n`) +} + +main() diff --git a/examples/search-and-crawl.ts b/examples/search-and-crawl.ts index 23d805f..20bdef9 100644 --- a/examples/search-and-crawl.ts +++ b/examples/search-and-crawl.ts @@ -2,7 +2,7 @@ import 'dotenv/config' import { OpenAIClient } from 'openai-fetch' import { z } from 'zod' -import { Agentic, SearchAndCrawlTool, WeatherTool } from '@/index' +import { Agentic, SearchAndCrawlTool } from '@/index' async function main() { const openai = new OpenAIClient({ apiKey: process.env.OPENAI_API_KEY! }) @@ -15,7 +15,7 @@ async function main() { messages: [ { role: 'system', - content: `You are a McKinsey analyst who is an expert at writing executive summaries. Always cite your sources and respond using markdown.` + content: `You are a McKinsey analyst who is an expert at writing executive summaries. Always cite your sources and respond using Markdown.` }, { role: 'user', @@ -24,7 +24,7 @@ async function main() { ], model: 'gpt-4-32k' }) - .tools([new SearchAndCrawlTool(), new WeatherTool()]) + .tools([new SearchAndCrawlTool()]) .input( z.object({ topic: z.string() diff --git a/examples/sentiment.ts b/examples/sentiment.ts index de49ddb..9a04491 100644 --- a/examples/sentiment.ts +++ b/examples/sentiment.ts @@ -14,7 +14,7 @@ export async function main() { .input(z.object({ texts: z.string().array() })) .output(z.array(z.object({ text: z.string(), label: z.string() }))) .examples([ - { input: 'The food was digusting', output: 'negative' }, + { input: 'The food was disgusting', output: 'negative' }, { input: 'We had a fantastic night', output: 'positive' }, { input: 'Recommended', output: 'positive' }, { input: 'The waiter was rude', output: 'negative' } diff --git a/examples/transcript-highlights.ts b/examples/transcript-highlights.ts new file mode 100644 index 0000000..8182f72 --- /dev/null +++ b/examples/transcript-highlights.ts @@ -0,0 +1,48 @@ +import 'dotenv/config' +import { readFileSync } from 'fs' +import { OpenAIClient } from 'openai-fetch' +import { z } from 'zod' + +import { Agentic } from '@/index' + +async function main() { + const openai = new OpenAIClient({ apiKey: process.env.OPENAI_API_KEY! }) + const agentic = new Agentic({ openai }) + + const fileName = process.argv[2] + const transcript = readFileSync(fileName, 'utf-8') + + const res = await agentic + .gpt4({ + messages: [ + { + role: 'system', + content: `You are a social media manager who is an expert at writing social media posts. You are generating draft posts advertising for a new podcast episode. Return a list of the best quotes by the interviewee from the transcript as they relate to the topic of the podcast. A quote can span multiple paragraphs.` + }, + { + role: 'user', + content: `Process the following transcript: {{transcript}}.` + } + ], + model: 'gpt-4-32k' + }) + .input( + z.object({ + transcript: z.string() + }) + ) + .output( + z.array( + z.object({ + quote: z.string(), + timestampStart: z.string(), + timestampEnd: z.string() + }) + ) + ) + .call({ transcript }) + + console.log(`\n\n\n${JSON.stringify(res, null, 2)}\n\n\n`) +} + +main()