Back to Ai

Flowise

content/providers/03-community-providers/98-flowise.mdx

2.1.102.5 KB
Original Source

Flowise Provider

The Flowise provider allows you to easily integrate Flowise chatflows with your applications using the AI SDK.

Setup

The Flowise provider is available in the @ahmedrowaihi/flowise-vercel-ai-sdk-provider module. You can install it with:

<Tabs items={['pnpm', 'npm', 'yarn']}> <Tab> <Snippet text="pnpm add @ahmedrowaihi/flowise-vercel-ai-sdk-provider" dark /> </Tab> <Tab> <Snippet text="npm install @ahmedrowaihi/flowise-vercel-ai-sdk-provider" dark /> </Tab> <Tab> <Snippet text="yarn add @ahmedrowaihi/flowise-vercel-ai-sdk-provider" dark /> </Tab> </Tabs>

Provider Instance

You can import the provider factory from @ahmedrowaihi/flowise-vercel-ai-sdk-provider:

ts
import { createFlowiseProvider } from '@ahmedrowaihi/flowise-vercel-ai-sdk-provider';

Quick Start

Using a Reusable Provider

Create a file called .env.local and add your Flowise configuration:

text
FLOWISE_BASE_URL=https://your-flowise-instance.com
FLOWISE_API_KEY=your_api_key_optional
ts
import { createFlowiseProvider } from '@ahmedrowaihi/flowise-vercel-ai-sdk-provider';
import { generateText } from 'ai';

const flowise = createFlowiseProvider({
  baseUrl: process.env.FLOWISE_BASE_URL!,
  apiKey: process.env.FLOWISE_API_KEY,
});

const { text } = await generateText({
  model: flowise('your-chatflow-id'),
  prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});

Using a One-shot Model

ts
import { createFlowiseModel } from '@ahmedrowaihi/flowise-vercel-ai-sdk-provider';
import { generateText } from 'ai';

const { text } = await generateText({
  model: createFlowiseModel({
    baseUrl: process.env.FLOWISE_BASE_URL!,
    apiKey: process.env.FLOWISE_API_KEY,
    chatflowId: 'your-chatflow-id',
  }),
  prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});

Streaming Example

ts
import { streamText } from 'ai';
import { createFlowiseProvider } from '@ahmedrowaihi/flowise-vercel-ai-sdk-provider';

const flowise = createFlowiseProvider({
  baseUrl: process.env.FLOWISE_BASE_URL!,
  apiKey: process.env.FLOWISE_API_KEY,
});

const result = streamText({
  model: flowise('your-chatflow-id'),
  prompt: 'Write a story about a robot learning to cook.',
});

return result.toDataStreamResponse();

More Information

For more information and advanced usage, see the Flowise provider documentation.