chatgpt-api/examples/ai-sdk/bin/weather.ts

25 wiersze
667 B
TypeScript
Czysty Zwykły widok Historia

2024-06-02 02:04:13 +00:00
import 'dotenv/config'
import { createAISDKTools } from '@agentic/ai-sdk'
import { WeatherClient } from '@agentic/weather'
import { createOpenAI } from '@ai-sdk/openai'
2024-06-02 02:04:13 +00:00
import { generateText } from 'ai'
async function main() {
const weather = new WeatherClient()
const openai = createOpenAI({ compatibility: 'strict' })
2024-06-02 02:04:13 +00:00
const result = await generateText({
2024-08-04 10:55:47 +00:00
model: openai('gpt-4o-mini'),
2024-06-02 08:06:45 +00:00
tools: createAISDKTools(weather),
2024-06-02 02:04:13 +00:00
toolChoice: 'required',
2024-06-02 08:16:23 +00:00
temperature: 0,
2024-06-02 22:30:39 +00:00
system: 'You are a helpful assistant. Be as concise as possible.',
2024-06-02 08:16:23 +00:00
prompt: 'What is the weather in San Francisco?'
2024-06-02 02:04:13 +00:00
})
console.log(result.toolResults[0])
}
await main()