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.
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.