@ragpipe/plugin-cloudflare 0.1.0-alpha.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # @ragpipe/plugin-cloudflare
2
+
3
+ Cloudflare Workers AI embedding and generation plugin for [ragpipe](https://github.com/yungblud/ragpipe).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add ragpipe @ragpipe/plugin-cloudflare
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { defineConfig } from "ragpipe";
15
+ import { cloudflareEmbedding, cloudflareGeneration } from "@ragpipe/plugin-cloudflare";
16
+
17
+ export default defineConfig({
18
+ embedding: cloudflareEmbedding({
19
+ accountId: process.env.CLOUDFLARE_ACCOUNT_ID!,
20
+ apiToken: process.env.CLOUDFLARE_API_TOKEN!,
21
+ model: "@cf/qwen/qwen3-embedding-0.6b",
22
+ }),
23
+ generation: cloudflareGeneration({
24
+ accountId: process.env.CLOUDFLARE_ACCOUNT_ID!,
25
+ apiToken: process.env.CLOUDFLARE_API_TOKEN!,
26
+ model: "@cf/openai/gpt-oss-20b",
27
+ systemPrompt: "Answer based on the provided context.",
28
+ }),
29
+ // ... vectorStore
30
+ });
31
+ ```
32
+
33
+ ## API
34
+
35
+ ### `cloudflareEmbedding(options)`
36
+
37
+ Returns an `EmbeddingPlugin` that calls the Cloudflare Workers AI Embedding API.
38
+
39
+ | Option | Type | Default | Description |
40
+ |---|---|---|---|
41
+ | `accountId` | `string` | — | Cloudflare account ID (required) |
42
+ | `apiToken` | `string` | — | Cloudflare API token (required) |
43
+ | `model` | `string` | — | Embedding model name (required) |
44
+
45
+ - **Batch support**: `embedMany()` sends an array of texts in a single API call
46
+
47
+ ### `cloudflareGeneration(options)`
48
+
49
+ Returns a `GenerationPlugin` that calls the Cloudflare Workers AI Generation API.
50
+
51
+ | Option | Type | Default | Description |
52
+ |---|---|---|---|
53
+ | `accountId` | `string` | — | Cloudflare account ID (required) |
54
+ | `apiToken` | `string` | — | Cloudflare API token (required) |
55
+ | `model` | `string` | — | Generation model name (required) |
56
+ | `systemPrompt` | `string` | `"Answer based on the provided context."` | Default system instruction |
57
+
58
+ - **Streaming**: `generateStream()` returns an `AsyncIterable<string>` via SSE
59
+ - **History**: Pass `{ history }` to include conversation context
60
+ - **Per-call override**: Pass `{ systemPrompt }` at call time to override the default
61
+
62
+ ## Get an API Token
63
+
64
+ 1. Go to [Cloudflare Dashboard](https://dash.cloudflare.com/profile/api-tokens)
65
+ 2. Create a token with **Workers AI** read permission
66
+ 3. Set `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` in your environment
67
+
68
+ ## License
69
+
70
+ MIT
package/dist/index.cjs CHANGED
@@ -51,7 +51,8 @@ function cloudflareEmbedding(options) {
51
51
  }
52
52
  return {
53
53
  name: "cloudflare",
54
- dimensions: 768,
54
+ dimensions: options.dimensions ?? 768,
55
+ model,
55
56
  async embed(text) {
56
57
  const vectors = await callApi([text]);
57
58
  return vectors[0];
@@ -63,9 +64,8 @@ function cloudflareEmbedding(options) {
63
64
  }
64
65
 
65
66
  // src/generation.ts
66
- var DEFAULT_MODEL = "@cf/meta/llama-3.1-8b-instruct";
67
67
  function cloudflareGeneration(options) {
68
- const model = options.model ?? DEFAULT_MODEL;
68
+ const { model } = options;
69
69
  const baseUrl = `https://api.cloudflare.com/client/v4/accounts/${options.accountId}/ai/run/${model}`;
70
70
  function buildMessages(question, context, opts) {
71
71
  const systemPrompt = opts?.systemPrompt ?? options.systemPrompt ?? "Answer based on the provided context.";
@@ -86,6 +86,7 @@ ${userPrompt}`;
86
86
  }
87
87
  return {
88
88
  name: "cloudflare",
89
+ model,
89
90
  async generate(question, context, opts) {
90
91
  const messages = buildMessages(question, context, opts);
91
92
  const res = await fetch(baseUrl, {
package/dist/index.d.cts CHANGED
@@ -4,13 +4,14 @@ interface CloudflareEmbeddingOptions {
4
4
  accountId: string;
5
5
  apiToken: string;
6
6
  model: string;
7
+ dimensions?: number;
7
8
  }
8
9
  declare function cloudflareEmbedding(options: CloudflareEmbeddingOptions): EmbeddingPlugin;
9
10
 
10
11
  interface CloudflareGenerationOptions {
11
12
  accountId: string;
12
13
  apiToken: string;
13
- model?: string;
14
+ model: string;
14
15
  systemPrompt?: string;
15
16
  }
16
17
  declare function cloudflareGeneration(options: CloudflareGenerationOptions): GenerationPlugin;
package/dist/index.d.ts CHANGED
@@ -4,13 +4,14 @@ interface CloudflareEmbeddingOptions {
4
4
  accountId: string;
5
5
  apiToken: string;
6
6
  model: string;
7
+ dimensions?: number;
7
8
  }
8
9
  declare function cloudflareEmbedding(options: CloudflareEmbeddingOptions): EmbeddingPlugin;
9
10
 
10
11
  interface CloudflareGenerationOptions {
11
12
  accountId: string;
12
13
  apiToken: string;
13
- model?: string;
14
+ model: string;
14
15
  systemPrompt?: string;
15
16
  }
16
17
  declare function cloudflareGeneration(options: CloudflareGenerationOptions): GenerationPlugin;
package/dist/index.js CHANGED
@@ -24,7 +24,8 @@ function cloudflareEmbedding(options) {
24
24
  }
25
25
  return {
26
26
  name: "cloudflare",
27
- dimensions: 768,
27
+ dimensions: options.dimensions ?? 768,
28
+ model,
28
29
  async embed(text) {
29
30
  const vectors = await callApi([text]);
30
31
  return vectors[0];
@@ -36,9 +37,8 @@ function cloudflareEmbedding(options) {
36
37
  }
37
38
 
38
39
  // src/generation.ts
39
- var DEFAULT_MODEL = "@cf/meta/llama-3.1-8b-instruct";
40
40
  function cloudflareGeneration(options) {
41
- const model = options.model ?? DEFAULT_MODEL;
41
+ const { model } = options;
42
42
  const baseUrl = `https://api.cloudflare.com/client/v4/accounts/${options.accountId}/ai/run/${model}`;
43
43
  function buildMessages(question, context, opts) {
44
44
  const systemPrompt = opts?.systemPrompt ?? options.systemPrompt ?? "Answer based on the provided context.";
@@ -59,6 +59,7 @@ ${userPrompt}`;
59
59
  }
60
60
  return {
61
61
  name: "cloudflare",
62
+ model,
62
63
  async generate(question, context, opts) {
63
64
  const messages = buildMessages(question, context, opts);
64
65
  const res = await fetch(baseUrl, {
package/package.json CHANGED
@@ -1,61 +1,64 @@
1
1
  {
2
- "name": "@ragpipe/plugin-cloudflare",
3
- "version": "0.1.0-alpha.1",
4
- "description": "Cloudflare Workers AI embedding and generation plugin for ragpipe",
5
- "type": "module",
6
- "license": "MIT",
7
- "author": {
8
- "name": "yungblud",
9
- "url": "https://github.com/yungblud"
10
- },
11
- "repository": {
12
- "type": "git",
13
- "url": "https://github.com/yungblud/ragpipe",
14
- "directory": "packages/plugin-cloudflare"
15
- },
16
- "bugs": {
17
- "url": "https://github.com/yungblud/ragpipe/issues"
18
- },
19
- "homepage": "https://github.com/yungblud/ragpipe#readme",
20
- "publishConfig": {
21
- "registry": "https://registry.npmjs.org/",
22
- "access": "public"
23
- },
24
- "exports": {
25
- ".": {
26
- "types": "./dist/index.d.ts",
27
- "import": "./dist/index.js",
28
- "require": "./dist/index.cjs"
29
- }
30
- },
31
- "main": "./dist/index.cjs",
32
- "module": "./dist/index.js",
33
- "types": "./dist/index.d.ts",
34
- "files": ["dist", "README.md"],
35
- "scripts": {
36
- "build": "tsup",
37
- "dev": "tsup --watch",
38
- "typecheck": "tsc --noEmit",
39
- "test": "vitest run",
40
- "test:watch": "vitest",
41
- "test:coverage": "vitest run --coverage"
42
- },
43
- "keywords": [
44
- "ragpipe",
45
- "rag",
46
- "cloudflare",
47
- "workers-ai",
48
- "embedding",
49
- "generation",
50
- "plugin"
51
- ],
52
- "peerDependencies": {
53
- "ragpipe": ">=0.1.0"
54
- },
55
- "devDependencies": {
56
- "ragpipe": "workspace:*",
57
- "tsup": "^8.4.0",
58
- "typescript": "^5.8.3",
59
- "vitest": "^3.1.1"
60
- }
61
- }
2
+ "name": "@ragpipe/plugin-cloudflare",
3
+ "version": "0.1.0",
4
+ "description": "Cloudflare Workers AI embedding and generation plugin for ragpipe",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": {
8
+ "name": "yungblud",
9
+ "url": "https://github.com/yungblud"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/yungblud/ragpipe",
14
+ "directory": "packages/plugin-cloudflare"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/yungblud/ragpipe/issues"
18
+ },
19
+ "homepage": "https://github.com/yungblud/ragpipe#readme",
20
+ "publishConfig": {
21
+ "registry": "https://registry.npmjs.org/",
22
+ "access": "public"
23
+ },
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js",
28
+ "require": "./dist/index.cjs"
29
+ }
30
+ },
31
+ "main": "./dist/index.cjs",
32
+ "module": "./dist/index.js",
33
+ "types": "./dist/index.d.ts",
34
+ "files": [
35
+ "dist",
36
+ "README.md"
37
+ ],
38
+ "keywords": [
39
+ "ragpipe",
40
+ "rag",
41
+ "cloudflare",
42
+ "workers-ai",
43
+ "embedding",
44
+ "generation",
45
+ "plugin"
46
+ ],
47
+ "peerDependencies": {
48
+ "ragpipe": ">=0.2.0"
49
+ },
50
+ "devDependencies": {
51
+ "tsup": "^8.4.0",
52
+ "typescript": "^5.8.3",
53
+ "vitest": "^3.1.1",
54
+ "ragpipe": "0.2.0"
55
+ },
56
+ "scripts": {
57
+ "build": "tsup",
58
+ "dev": "tsup --watch",
59
+ "typecheck": "tsc --noEmit",
60
+ "test": "vitest run",
61
+ "test:watch": "vitest",
62
+ "test:coverage": "vitest run --coverage"
63
+ }
64
+ }