@expandai/ai
v0.1.1
Published
Vercel AI SDK integration for expand.ai - fetch and extract content from any URL
Readme
@expandai/ai
Vercel AI SDK integration for Expand - fetch and extract content from any URL with AI.
Installation
npm install @expandai/ai ai zod
# or
pnpm add @expandai/ai ai zod
# or
yarn add @expandai/ai ai zodPrerequisites
You need an Expand API key. Get one at expand.ai.
Set your API key as an environment variable:
export EXPAND_API_KEY=your_api_key_hereUsage
Basic Example
import { expandFetchTool } from '@expandai/ai'
import { generateText } from 'ai'
import { openai } from '@ai-sdk/openai'
const result = await generateText({
model: openai('gpt-4'),
tools: {
expandFetch: expandFetchTool,
},
prompt: 'What is on the Expand homepage at https://expand.ai?',
})
console.log(result.text)Custom Configuration
import { createExpandFetchTool } from '@expandai/ai'
const customTool = createExpandFetchTool({
apiKey: 'your_custom_api_key',
description: 'Custom tool description for your specific use case',
})
const result = await generateText({
model: openai('gpt-4'),
tools: {
fetch: customTool,
},
prompt: 'Summarize the content at https://example.com',
})With Multiple Tools
import { expandFetchTool } from '@expandai/ai'
import { generateText } from 'ai'
import { openai } from '@ai-sdk/openai'
import { weatherTool } from './other-tools'
const result = await generateText({
model: openai('gpt-4'),
tools: {
expandFetch: expandFetchTool,
weather: weatherTool,
},
prompt: 'Check the weather forecast on https://weather.com and plan my weekend',
})API
expandFetchTool
The default tool instance that uses the EXPAND_API_KEY environment variable.
import { expandFetchTool } from '@expandai/ai'createExpandFetchTool(options?)
Create a custom Expand fetch tool with specific configuration.
Parameters:
options.apiKey(optional): Expand API key. Defaults toprocess.env.EXPAND_API_KEYoptions.description(optional): Custom tool description for the AI model
Returns: A Vercel AI SDK tool
import { createExpandFetchTool } from '@expandai/ai'
const tool = createExpandFetchTool({
apiKey: 'your_api_key',
description: 'Fetch web content for analysis',
})Tool Output
The tool returns an object with:
url: The fetched URLmarkdown: The extracted content in Markdown formatmeta: Metadata object containing:title: Page titledescription: Page description- And other metadata fields
Examples
Research Assistant
import { expandFetchTool } from '@expandai/ai'
import { generateText } from 'ai'
import { anthropic } from '@ai-sdk/anthropic'
const result = await generateText({
model: anthropic('claude-3-5-sonnet-20241022'),
tools: {
expandFetch: expandFetchTool,
},
prompt: `
Research the latest developments in AI from these sources:
- https://openai.com/blog
- https://www.anthropic.com/news
Provide a summary of the most important updates.
`,
})Content Comparison
import { expandFetchTool } from '@expandai/ai'
import { streamText } from 'ai'
import { openai } from '@ai-sdk/openai'
const result = await streamText({
model: openai('gpt-4-turbo'),
tools: {
expandFetch: expandFetchTool,
},
prompt: `
Compare the pricing pages of:
- https://vercel.com/pricing
- https://netlify.com/pricing
Which one offers better value for small teams?
`,
})
for await (const chunk of result.textStream) {
process.stdout.write(chunk)
}Error Handling
import { createExpandFetchTool } from '@expandai/ai'
import { generateText } from 'ai'
import { openai } from '@ai-sdk/openai'
try {
const tool = createExpandFetchTool({ apiKey: process.env.EXPAND_API_KEY })
const result = await generateText({
model: openai('gpt-4'),
tools: { expandFetch: tool },
prompt: 'Fetch https://example.com',
})
} catch (error) {
console.error('Failed to fetch content:', error)
}Requirements
- Node.js 18 or higher
ai>= 3.0.0zod>= 3.0.0
License
Apache-2.0
Links
Support
For issues and questions:
- GitHub Issues: expandai/expandai-ai-sdk
- Email: [email protected]
- Discord: Join our community
