@ragpipe/plugin-cloudflare
Advanced tools
+70
| # @ragpipe/plugin-cloudflare | ||
| Cloudflare Workers AI embedding and generation plugin for [ragpipe](https://github.com/yungblud/ragpipe). | ||
| ## Install | ||
| ```bash | ||
| pnpm add ragpipe @ragpipe/plugin-cloudflare | ||
| ``` | ||
| ## Usage | ||
| ```ts | ||
| import { defineConfig } from "ragpipe"; | ||
| import { cloudflareEmbedding, cloudflareGeneration } from "@ragpipe/plugin-cloudflare"; | ||
| export default defineConfig({ | ||
| embedding: cloudflareEmbedding({ | ||
| accountId: process.env.CLOUDFLARE_ACCOUNT_ID!, | ||
| apiToken: process.env.CLOUDFLARE_API_TOKEN!, | ||
| model: "@cf/qwen/qwen3-embedding-0.6b", | ||
| }), | ||
| generation: cloudflareGeneration({ | ||
| accountId: process.env.CLOUDFLARE_ACCOUNT_ID!, | ||
| apiToken: process.env.CLOUDFLARE_API_TOKEN!, | ||
| model: "@cf/openai/gpt-oss-20b", | ||
| systemPrompt: "Answer based on the provided context.", | ||
| }), | ||
| // ... vectorStore | ||
| }); | ||
| ``` | ||
| ## API | ||
| ### `cloudflareEmbedding(options)` | ||
| Returns an `EmbeddingPlugin` that calls the Cloudflare Workers AI Embedding API. | ||
| | Option | Type | Default | Description | | ||
| |---|---|---|---| | ||
| | `accountId` | `string` | — | Cloudflare account ID (required) | | ||
| | `apiToken` | `string` | — | Cloudflare API token (required) | | ||
| | `model` | `string` | — | Embedding model name (required) | | ||
| - **Batch support**: `embedMany()` sends an array of texts in a single API call | ||
| ### `cloudflareGeneration(options)` | ||
| Returns a `GenerationPlugin` that calls the Cloudflare Workers AI Generation API. | ||
| | Option | Type | Default | Description | | ||
| |---|---|---|---| | ||
| | `accountId` | `string` | — | Cloudflare account ID (required) | | ||
| | `apiToken` | `string` | — | Cloudflare API token (required) | | ||
| | `model` | `string` | — | Generation model name (required) | | ||
| | `systemPrompt` | `string` | `"Answer based on the provided context."` | Default system instruction | | ||
| - **Streaming**: `generateStream()` returns an `AsyncIterable<string>` via SSE | ||
| - **History**: Pass `{ history }` to include conversation context | ||
| - **Per-call override**: Pass `{ systemPrompt }` at call time to override the default | ||
| ## Get an API Token | ||
| 1. Go to [Cloudflare Dashboard](https://dash.cloudflare.com/profile/api-tokens) | ||
| 2. Create a token with **Workers AI** read permission | ||
| 3. Set `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` in your environment | ||
| ## License | ||
| MIT |
+4
-3
@@ -54,3 +54,4 @@ "use strict"; | ||
| name: "cloudflare", | ||
| dimensions: 768, | ||
| dimensions: options.dimensions ?? 768, | ||
| model, | ||
| async embed(text) { | ||
@@ -67,5 +68,4 @@ const vectors = await callApi([text]); | ||
| // src/generation.ts | ||
| var DEFAULT_MODEL = "@cf/meta/llama-3.1-8b-instruct"; | ||
| function cloudflareGeneration(options) { | ||
| const model = options.model ?? DEFAULT_MODEL; | ||
| const { model } = options; | ||
| const baseUrl = `https://api.cloudflare.com/client/v4/accounts/${options.accountId}/ai/run/${model}`; | ||
@@ -91,2 +91,3 @@ function buildMessages(question, context, opts) { | ||
| name: "cloudflare", | ||
| model, | ||
| async generate(question, context, opts) { | ||
@@ -93,0 +94,0 @@ const messages = buildMessages(question, context, opts); |
+2
-1
@@ -7,2 +7,3 @@ import { EmbeddingPlugin, GenerationPlugin } from 'ragpipe'; | ||
| model: string; | ||
| dimensions?: number; | ||
| } | ||
@@ -14,3 +15,3 @@ declare function cloudflareEmbedding(options: CloudflareEmbeddingOptions): EmbeddingPlugin; | ||
| apiToken: string; | ||
| model?: string; | ||
| model: string; | ||
| systemPrompt?: string; | ||
@@ -17,0 +18,0 @@ } |
+2
-1
@@ -7,2 +7,3 @@ import { EmbeddingPlugin, GenerationPlugin } from 'ragpipe'; | ||
| model: string; | ||
| dimensions?: number; | ||
| } | ||
@@ -14,3 +15,3 @@ declare function cloudflareEmbedding(options: CloudflareEmbeddingOptions): EmbeddingPlugin; | ||
| apiToken: string; | ||
| model?: string; | ||
| model: string; | ||
| systemPrompt?: string; | ||
@@ -17,0 +18,0 @@ } |
+4
-3
@@ -27,3 +27,4 @@ // src/embedding.ts | ||
| name: "cloudflare", | ||
| dimensions: 768, | ||
| dimensions: options.dimensions ?? 768, | ||
| model, | ||
| async embed(text) { | ||
@@ -40,5 +41,4 @@ const vectors = await callApi([text]); | ||
| // src/generation.ts | ||
| var DEFAULT_MODEL = "@cf/meta/llama-3.1-8b-instruct"; | ||
| function cloudflareGeneration(options) { | ||
| const model = options.model ?? DEFAULT_MODEL; | ||
| const { model } = options; | ||
| const baseUrl = `https://api.cloudflare.com/client/v4/accounts/${options.accountId}/ai/run/${model}`; | ||
@@ -64,2 +64,3 @@ function buildMessages(question, context, opts) { | ||
| name: "cloudflare", | ||
| model, | ||
| async generate(question, context, opts) { | ||
@@ -66,0 +67,0 @@ const messages = buildMessages(question, context, opts); |
+63
-60
| { | ||
| "name": "@ragpipe/plugin-cloudflare", | ||
| "version": "0.1.0-alpha.1", | ||
| "description": "Cloudflare Workers AI embedding and generation plugin for ragpipe", | ||
| "type": "module", | ||
| "license": "MIT", | ||
| "author": { | ||
| "name": "yungblud", | ||
| "url": "https://github.com/yungblud" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/yungblud/ragpipe", | ||
| "directory": "packages/plugin-cloudflare" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/yungblud/ragpipe/issues" | ||
| }, | ||
| "homepage": "https://github.com/yungblud/ragpipe#readme", | ||
| "publishConfig": { | ||
| "registry": "https://registry.npmjs.org/", | ||
| "access": "public" | ||
| }, | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/index.js", | ||
| "require": "./dist/index.cjs" | ||
| } | ||
| }, | ||
| "main": "./dist/index.cjs", | ||
| "module": "./dist/index.js", | ||
| "types": "./dist/index.d.ts", | ||
| "files": ["dist", "README.md"], | ||
| "scripts": { | ||
| "build": "tsup", | ||
| "dev": "tsup --watch", | ||
| "typecheck": "tsc --noEmit", | ||
| "test": "vitest run", | ||
| "test:watch": "vitest", | ||
| "test:coverage": "vitest run --coverage" | ||
| }, | ||
| "keywords": [ | ||
| "ragpipe", | ||
| "rag", | ||
| "cloudflare", | ||
| "workers-ai", | ||
| "embedding", | ||
| "generation", | ||
| "plugin" | ||
| ], | ||
| "peerDependencies": { | ||
| "ragpipe": ">=0.1.0" | ||
| }, | ||
| "devDependencies": { | ||
| "ragpipe": "workspace:*", | ||
| "tsup": "^8.4.0", | ||
| "typescript": "^5.8.3", | ||
| "vitest": "^3.1.1" | ||
| } | ||
| } | ||
| "name": "@ragpipe/plugin-cloudflare", | ||
| "version": "0.1.0", | ||
| "description": "Cloudflare Workers AI embedding and generation plugin for ragpipe", | ||
| "type": "module", | ||
| "license": "MIT", | ||
| "author": { | ||
| "name": "yungblud", | ||
| "url": "https://github.com/yungblud" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/yungblud/ragpipe", | ||
| "directory": "packages/plugin-cloudflare" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/yungblud/ragpipe/issues" | ||
| }, | ||
| "homepage": "https://github.com/yungblud/ragpipe#readme", | ||
| "publishConfig": { | ||
| "registry": "https://registry.npmjs.org/", | ||
| "access": "public" | ||
| }, | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/index.js", | ||
| "require": "./dist/index.cjs" | ||
| } | ||
| }, | ||
| "main": "./dist/index.cjs", | ||
| "module": "./dist/index.js", | ||
| "types": "./dist/index.d.ts", | ||
| "files": [ | ||
| "dist", | ||
| "README.md" | ||
| ], | ||
| "keywords": [ | ||
| "ragpipe", | ||
| "rag", | ||
| "cloudflare", | ||
| "workers-ai", | ||
| "embedding", | ||
| "generation", | ||
| "plugin" | ||
| ], | ||
| "peerDependencies": { | ||
| "ragpipe": ">=0.2.0" | ||
| }, | ||
| "devDependencies": { | ||
| "tsup": "^8.4.0", | ||
| "typescript": "^5.8.3", | ||
| "vitest": "^3.1.1", | ||
| "ragpipe": "0.2.0" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsup", | ||
| "dev": "tsup --watch", | ||
| "typecheck": "tsc --noEmit", | ||
| "test": "vitest run", | ||
| "test:watch": "vitest", | ||
| "test:coverage": "vitest run --coverage" | ||
| } | ||
| } |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
13845
20.38%6
20%300
1.01%0
-100%71
Infinity%