Invocation

Direct Invocation

Once you create your pipeline you can invoke it by calling the invoke method. The input is your defined Pipeline input and the output is the defined Pipeline output.

index.ts

_20
export const jokeGptPipeline = aigur.pipeline
_20
.create<{ subject: string}, { joke: string}>({
_20
id: 'jokegpt',
_20
flow: (flow) =>
_20
flow
_20
.node(replaceString, ({ input }) => ({
_20
text: input.subject,
_20
modifier: 'tell me a joke about $(text)$',
_20
}))
_20
.node(gpt3Prediction, ({ prev, input, nodes }) => ({
_20
prompt: prev.text,
_20
}))
_20
.output(({ prev }) => ({
_20
joke: prev.text,
_20
})),
_20
});
_20
_20
const { joke } = await jokeGptPipeline.invoke({
_20
subject: 'cats',
_20
});

Remote Invocation

Since pipelines can run on the server you can easily invoke them from the client using the invokeRemote method. invokeRemote is just a typed wrapper around fetch which accepts the input of the pipeline and returns the output of the pipeline. It receives a url parameter which is the URL of the server endpoint where the pipeline will run.

Here are examples of the server side endpoint that will do the actual invocation:


export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const { input } = req.body;
const output = await pipeline.invoke(input); // <-- import your pipeline
return res.json(output);
}

And here is an example of the client side code that will invoke the pipeline on the server:


const { joke } = await jokePipeline.invokeRemote('/api/jokePipeline',
{
subject: 'cats',
},
);

Invoke Stream

If your pipeline has a stream output you need to use the invokeStream method to invoke it. Read about streaming to learn more about streaming results.

Vercel Edge Functions

If you're using Vercel check out the dedicated page.