chatgpt-api/examples/llm-with-search.ts

35 wiersze
716 B
TypeScript
Czysty Zwykły widok Historia

import { OpenAIClient } from '@agentic/openai-fetch'
2023-06-01 01:53:09 +00:00
import 'dotenv/config'
2023-05-27 00:38:55 +00:00
import { z } from 'zod'
2023-06-15 05:11:30 +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-15 05:11:30 +00:00
const res = await agentic
.gpt4(
`Can you summarize the top {{numResults}} results for today's news about {{topic}}?`
)
.tools([new SerpAPITool()])
2023-05-27 00:38:55 +00:00
.input(
z.object({
2023-06-15 05:11:30 +00:00
topic: z.string(),
numResults: z.number().default(3)
2023-05-27 00:38:55 +00:00
})
)
.output(
z.object({
2023-06-15 05:11:30 +00:00
summary: z.string()
2023-05-27 00:38:55 +00:00
})
)
.call({
2023-06-15 05:11:30 +00:00
topic: 'OpenAI'
2023-05-27 00:38:55 +00:00
})
2023-06-15 05:11:30 +00:00
console.log(res)
2023-05-27 00:38:55 +00:00
}
main()