An Interest In:
Web News this Week
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
- April 12, 2024
- April 11, 2024
- April 10, 2024
April 16, 2024 08:18 pm GMT
Original Link: https://dev.to/luisfun/plugin-for-cloudflare-ai-api-4e5f
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)
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
Original Link: https://dev.to/luisfun/plugin-for-cloudflare-ai-api-4e5f
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To