@composio/cloudflare
The Cloudflare AI provider for Composio SDK, providing seamless integration with Cloudflare's AI capabilities and Workers AI.
Features
- Workers AI Integration: Seamless integration with Cloudflare Workers AI
- Streaming Support: First-class support for streaming responses
- Model Support: Support for all Cloudflare AI models (@cf/meta/llama-2-7b-chat-int8, etc.)
- Edge Deployment: Deploy and run AI models at the edge
- Tool Execution: Execute tools with proper parameter handling
- Type Safety: Full TypeScript support with proper type definitions
Installation
npm install @composio/cloudflare
yarn add @composio/cloudflare
pnpm add @composio/cloudflare
Quick Start
import { Composio } from '@composio/core';
import { CloudflareProvider } from '@composio/cloudflare';
const composio = new Composio({
apiKey: 'your-composio-api-key',
provider: new CloudflareProvider({
accountId: 'your-cloudflare-account-id',
apiToken: 'your-cloudflare-api-token',
}),
});
const tools = await composio.tools.get('user123', {
toolkits: ['gmail', 'googlecalendar'],
limit: 10,
});
Usage Examples
Basic Chat Completion with Streaming
import { Composio } from '@composio/core';
import { CloudflareProvider } from '@composio/cloudflare';
import { Ai } from '@cloudflare/ai';
const composio = new Composio({
apiKey: process.env.COMPOSIO_API_KEY,
provider: new CloudflareProvider(),
});
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
const ai = new Ai(env.AI);
const tools = await composio.tools.get('user123', {
toolkits: ['gmail'],
});
const messages = [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What can you do?' },
];
const stream = await ai.run('@cf/meta/llama-2-7b-chat-int8', {
messages,
tools,
stream: true,
});
return new Response(stream, {
headers: {
'content-type': 'text/event-stream',
},
});
},
};
Multi-Modal Example
import { Composio } from '@composio/core';
import { CloudflareProvider } from '@composio/cloudflare';
import { Ai } from '@cloudflare/ai';
const composio = new Composio({
apiKey: process.env.COMPOSIO_API_KEY,
provider: new CloudflareProvider(),
});
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
const ai = new Ai(env.AI);
const tools = await composio.tools.get('user123', {
toolkits: ['gmail'],
});
const imageResponse = await ai.run('@cf/microsoft/resnet-50', {
image: await request.arrayBuffer(),
});
const messages = [
{ role: 'system', content: 'You are a helpful assistant.' },
{
role: 'user',
content: 'What do you see in this image?',
context: { image_analysis: imageResponse },
},
];
const stream = await ai.run('@cf/meta/llama-2-7b-chat-int8', {
messages,
tools,
stream: true,
});
return new Response(stream, {
headers: {
'content-type': 'text/event-stream',
},
});
},
};
API Reference
CloudflareProvider Class
The CloudflareProvider
class extends BaseComposioProvider
and provides Cloudflare-specific functionality.
Methods
executeToolCall(tool: ToolCall): Promise<string>
Executes a tool call and returns the result.
const result = await composio.provider.executeToolCall(toolCall);
Contributing
We welcome contributions! Please see our Contributing Guide for more details.
License
ISC License
Support
For support, please visit our Documentation or join our Discord Community.