Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 16, 2024 08:18 pm GMT

Plugin for Cloudflare AI API

I created a module for @luisfun/cloudflare-ai-plugin, and this is its introduction.

What I Built

This is a plugin that allows you to write REST API and AI Gateway in the same way as binding AI (env.AI.run) when using Cloudflare's Workers AI.
Also, it supports Typescript.

How to Use

Install

npm i @luisfun/cloudflare-ai-pluginnpm i -D @cloudflare/ai # When using TypeScript

Coding

import { Ai } from '@luisfun/cloudflare-ai-plugin'// const ai = env.AIconst ai = new Ai(env.AI_API_URL, env.AI_API_TOKEN)const response = await ai.run(model, inputs)

How to get API URL and TOKEN

There are also some extensions available.
Here, I will include the cache control of the Gateway.
If you are interested in other extensions, please check the repository.

const options = {  'cf-skip-cache': true,  'cf-cache-ttl': 60,}const response = await ai.run(model, inputs, options)

Repository

https://github.com/LuisFun/cloudflare-ai-plugin


Original Link: https://dev.to/luisfun/plugin-for-cloudflare-ai-api-4e5f

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To