Frameworks
Vercel Edge Functions

All Pipeline Nodes support Vercel Edge Functions out of the box 🎉

You can define them manually and invoke them as usual or use the built-in helpers.

Aigur Vercel Helpers

Aigur Client has built-in helpers for invoking Pipeline on Vercel Edge Functions.

Define Your Pipeline Repository

Create an object that holds references to your Pipelines where the key is their id.

jokegpt.ts

_10
export const jokeGptPipeline = aigur.pipeline.create<..., ...>({
_10
id: 'jokegpt',
_10
...

pipelines/pipelines.ts

_10
import { jokeGptPipeline } from './jokegpt';
_10
_10
export const pipelines = {
_10
jokegpt: jokeGptPipeline,
_10
} as const;

Generic Vercel Edge Function

Next, create a generic Vercel Edge Function that will invoke the Pipeline based on the request path. You can now invoke any Pipeline and it will automatically run on Vercel Edge Functions (see below how).

💡

The Generic Edge Function must be defined at /api/pipelines/[id].ts

/api/pipelines/[...id].ts

_10
import { pipelines } from '#/pipelines/pipelines'; // import your pipeline repository
_10
import { vercelEdgeFunction } from '@aigur/client'; // import the helper
_10
_10
// export default the helper with your pipeline repository
_10
export default vercelEdgeFunction(pipelines);
_10
export const config = { // export the config
_10
runtime: 'edge',
_10
};

Invoke the Pipeline

We use the vercel.invoke helper function to invoke the Pipeline. Behind the scenes it will access our generic Edge Function, invoke the Pipeline and return the result.

index.ts

jokeGptPipeline.vercel.invoke({ subject }).then(({text}) => {});

For streaming using the vercel.invokeStream helper function:

index.ts

let text = '';
jokeGptStreamPipeline.vercel.invokeStream({ subject }, (res) => {
text += res;
});

Define Your Edge Function Manually

If you don't want to use the helper function, you can define your Pipeline Edge Functions manually:

/api/joke.ts

import { NextRequest, NextResponse } from 'next/server';
import { jokeGptPipeline } from '#/pipelines/jokegpt'; // <-- import your pipeline
export default async function handler(req: NextRequest) {
const { input } = input = await req.json(); // <-- receive the input
const output = await jokeGptPipeline.invoke(input); // <-- invoke the pipeline
return NextResponse.json(output); // <-- return the output
}
export const config = {
runtime: 'edge', // <-- define the runtime as edge
};

client.ts

import { jokeGptPipeline } from '#/pipelines/jokegpt'; // <-- import same pipeline
jokeGptPipeline.invokeRemote('/api/joke', { subject }) // <-- invoke the pipeline
.then(({ joke }) => {});