chatgpt-api/examples/summarize-news.ts

29 wiersze
612 B
TypeScript
Czysty Zwykły widok Historia

2023-06-01 01:53:09 +00:00
import 'dotenv/config'
import { OpenAIClient } from 'openai-fetch'
2023-05-27 00:38:55 +00:00
import { z } from 'zod'
2023-06-17 00:42:21 +00:00
import { Agentic, SerpAPITool } from '@/index'
2023-05-27 00:38:55 +00:00
async function main() {
const openai = new OpenAIClient({ apiKey: process.env.OPENAI_API_KEY! })
2023-06-15 05:11:30 +00:00
const agentic = new Agentic({ openai })
2023-05-27 00:38:55 +00:00
2023-06-17 19:02:14 +00:00
const topic = process.argv[2] || 'HF0 accelerator'
2023-06-15 05:11:30 +00:00
const res = await agentic
2023-06-20 00:29:40 +00:00
.gpt3(`Summarize the latest news on {{topic}} using markdown.`)
2023-06-17 00:42:21 +00:00
.tools([new SerpAPITool()])
2023-05-27 00:38:55 +00:00
.input(
z.object({
2023-06-16 22:50:38 +00:00
topic: z.string()
2023-05-27 00:38:55 +00:00
})
)
.call({
2023-06-17 19:02:14 +00:00
topic
2023-05-27 00:38:55 +00:00
})
2023-06-15 05:11:30 +00:00
console.log(`\n\n\n${res}\n\n\n`)
2023-05-27 00:38:55 +00:00
}
main()