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

40 wiersze
941 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-17 00:09:24 +00:00
import { Agentic, SearchAndCrawlTool, WeatherTool } 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-17 19:02:14 +00:00
content: `You are a McKinsey analyst who is an expert at writing executive summaries. Always 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-17 00:09:24 +00:00
.tools([new SearchAndCrawlTool(), new WeatherTool()])
2023-06-16 22:50:38 +00:00
.input(
z.object({
topic: z.string()
})
)
.callWithMetadata({ topic })
2023-06-16 22:50:38 +00:00
2023-06-17 00:09:24 +00:00
console.log('\n\n\n')
2023-06-16 22:50:38 +00:00
console.log(res)
}
main()