chatgpt-api/legacy/examples/ai-sdk/bin/tavily.ts

28 wiersze
813 B
TypeScript
Czysty Zwykły widok Historia

2025-03-31 05:45:51 +00:00
import 'dotenv/config'
import { createAISDKTools } from '@agentic/ai-sdk'
import { TavilyClient } from '@agentic/stdlib'
import { createOpenAI } from '@ai-sdk/openai'
import { generateText } from 'ai'
async function main() {
const tavily = new TavilyClient()
2025-04-01 14:10:31 +00:00
const openai = createOpenAI({ compatibility: 'compatible' })
2025-03-31 05:45:51 +00:00
const result = await generateText({
2025-04-01 14:10:31 +00:00
model: openai('gpt-4o-mini', {
// TODO: https://github.com/transitive-bullshit/agentic/issues/702
// structuredOutputs: true
}),
2025-03-31 05:45:51 +00:00
tools: createAISDKTools(tavily),
toolChoice: 'required',
temperature: 0,
system: 'You are a helpful assistant. Be as concise as possible.',
prompt: 'What is the latest news in the US right now?'
})
console.log(JSON.stringify(result.toolResults[0], null, 2))
}
await main()