Install
Usage
This example also requires you to install the genkitx-openai package, which adds support for OpenAI to Genkit.
import 'dotenv/config'
import { createGenkitTools } from '@agentic/genkit'
import { WeatherClient } from '@agentic/stdlib'
import { generate } from '@genkit-ai/ai'
import { configureGenkit } from '@genkit-ai/core'
import { gpt4oMini, openAI } from 'genkitx-openai'
async function main() {
const weather = new WeatherClient()
configureGenkit({
plugins: [openAI()]
})
const result = await generate({
model: gpt4oMini,
tools: createGenkitTools(weather),
history: [
{
role: 'system',
content: [
{
text: 'You are a helpful assistant. Be as concise as possible.'
}
]
}
],
prompt: 'What is the weather in San Francisco?'
})
console.log(result)
}
await main()
Running this example
You’ll need a free API key from weatherapi.com
to run this example. Store it in a local .env
file as WEATHER_API_KEY
.
You’ll need an OpenAI API key
to run this example. Store it in a local .env
file as OPENAI_API_KEY
.
git clone git@github.com:transitive-bullshit/agentic.git
cd agentic
pnpm install
echo 'WEATHER_API_KEY=your-key' >> .env
echo 'OPENAI_API_KEY=your-key' >> .env
npx tsx examples/genkit/bin/weather.ts