chatgpt-api/examples/search-and-crawl.ts

39 wiersze
912 B
TypeScript
Czysty Zwykły widok Historia

2023-06-16 22:50:38 +00:00
import 'dotenv/config'
import { OpenAIClient } from 'openai-fetch'
2023-06-16 22:50:38 +00:00
import { z } from 'zod'
2023-06-25 20:18:06 +00:00
import { Agentic, SearchAndCrawlTool } from '@/index'
2023-06-16 22:50:38 +00:00
async function main() {
const openai = new OpenAIClient({ apiKey: process.env.OPENAI_API_KEY! })
const agentic = new Agentic({ openai })
2023-06-17 00:09:24 +00:00
const topic = process.argv[2] || 'OpenAI'
2023-06-16 22:50:38 +00:00
const res = await agentic
2023-06-17 00:09:24 +00:00
.gpt4({
messages: [
{
role: 'system',
2023-06-25 20:18:06 +00:00
content: `You are a McKinsey analyst who is an expert at writing executive summaries. Always cite your sources and respond using Markdown.`
2023-06-17 00:09:24 +00:00
},
{
role: 'user',
content: `Summarize the latest news on: {{topic}}`
}
],
2023-06-16 23:09:33 +00:00
model: 'gpt-4-32k'
})
2023-06-25 20:18:06 +00:00
.tools([new SearchAndCrawlTool()])
2023-06-16 22:50:38 +00:00
.input(
z.object({
topic: z.string()
})
)
2023-06-20 00:29:40 +00:00
.call({ topic })
2023-06-16 22:50:38 +00:00
console.log(`\n\n\n${res}\n\n\n`)
2023-06-16 22:50:38 +00:00
}
main()