npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@luisfun/cloudflare-ai-plugin

v0.2.4

Published

This plugin enables you to code REST API or AI Gateway in the same way as the binding AI when using Cloudflare's Workers AI

Downloads

30

Readme

Cloudflare AI Plugin npm v Bundle Size

  • REST API or AI Gateway - You can code the same way as the binding AI.
  • MD Translator - You can translate while maintaining the structure of Markdown to some extent.
  • TypeScript - TypeScript support.

Install

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

How to Use

import { Ai } from '@luisfun/cloudflare-ai-plugin'

// const ai = env.AI
// const ai = new Ai(env.AI) // When extending binding AI
const 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

Extension

API Options
Gateway: cf-cache

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

MD Translator
⚠️ AI translation requests will increase.

// const { translated_text } = await ai.run('@cf/meta/m2m100-1.2b', inputs)
const { translated_text } = await ai.mdt('@cf/meta/m2m100-1.2b', inputs)

fetch Response Object

// response is Response Object
// outputs is the same `await ai.run()` outputs
const { response, outputs } = await ai.fetch(model, inputs)

Builder

URL Builder

import { Ai, restUrl, gatewayUrl } from '@luisfun/cloudflare-ai-plugin'

const restAi = new Ai(restUrl(env.ACCOUNT_ID), env.AI_API_TOKEN)
const gatewayAi = new Ai(gatewayUrl(env.ACCOUNT_ID, env.GATEWAY_SLUG), env.AI_API_TOKEN)

Examples

References

The following repositories were referenced in the making of this project: