kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
docs: add and update examples
rodzic
11b303c738
commit
06c4d93f9c
|
@ -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()
|
|
@ -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()
|
|
@ -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()
|
||||
|
|
|
@ -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' }
|
||||
|
|
|
@ -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()
|
Ładowanie…
Reference in New Issue