I created a module for @luisfun/cloudflare-ai-plugin
, and this is its introduction.
What I Built
This plugin enables you to write REST API or 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-plugin
npm i -D @cloudflare/ai # When using TypeScript
Coding
import { Ai } from '@luisfun/cloudflare-ai-plugin'
// const ai = env.AI
const ai = new Ai(env.AI_API_URL, env.AI_API_TOKEN)
const response = await ai.run(model, inputs)
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)
Top comments (0)