@ragpipe/plugin-cloudflare
Advanced tools
+5
-14
@@ -69,3 +69,3 @@ "use strict"; | ||
| const { model } = options; | ||
| const baseUrl = `https://api.cloudflare.com/client/v4/accounts/${options.accountId}/ai/run/${model}`; | ||
| const baseUrl = `https://api.cloudflare.com/client/v4/accounts/${options.accountId}/ai/v1/chat/completions`; | ||
| function buildMessages(question, context, opts) { | ||
@@ -99,3 +99,3 @@ const systemPrompt = opts?.systemPrompt ?? options.systemPrompt ?? "Answer based on the provided context."; | ||
| }, | ||
| body: JSON.stringify({ messages, stream: false }) | ||
| body: JSON.stringify({ model, messages, stream: false }) | ||
| }); | ||
@@ -108,12 +108,3 @@ if (!res.ok) { | ||
| const data = await res.json(); | ||
| if (!data.success) { | ||
| throw new Error( | ||
| "Cloudflare generation error: API returned success=false" | ||
| ); | ||
| } | ||
| if (data.result.choices?.length) { | ||
| const message = data.result.choices[0].message; | ||
| return message.content ?? message.reasoning_content ?? ""; | ||
| } | ||
| return data.result.response ?? ""; | ||
| return data.choices?.[0]?.message?.content ?? ""; | ||
| }, | ||
@@ -128,3 +119,3 @@ async *generateStream(question, context, opts) { | ||
| }, | ||
| body: JSON.stringify({ messages, stream: true }) | ||
| body: JSON.stringify({ model, messages, stream: true }) | ||
| }); | ||
@@ -153,3 +144,3 @@ if (!res.ok) { | ||
| const data = JSON.parse(payload); | ||
| const chunk = data.choices?.[0]?.delta?.content ?? data.response; | ||
| const chunk = data.choices?.[0]?.delta?.content; | ||
| if (chunk) yield chunk; | ||
@@ -156,0 +147,0 @@ } catch { |
+5
-14
@@ -42,3 +42,3 @@ // src/embedding.ts | ||
| const { model } = options; | ||
| const baseUrl = `https://api.cloudflare.com/client/v4/accounts/${options.accountId}/ai/run/${model}`; | ||
| const baseUrl = `https://api.cloudflare.com/client/v4/accounts/${options.accountId}/ai/v1/chat/completions`; | ||
| function buildMessages(question, context, opts) { | ||
@@ -72,3 +72,3 @@ const systemPrompt = opts?.systemPrompt ?? options.systemPrompt ?? "Answer based on the provided context."; | ||
| }, | ||
| body: JSON.stringify({ messages, stream: false }) | ||
| body: JSON.stringify({ model, messages, stream: false }) | ||
| }); | ||
@@ -81,12 +81,3 @@ if (!res.ok) { | ||
| const data = await res.json(); | ||
| if (!data.success) { | ||
| throw new Error( | ||
| "Cloudflare generation error: API returned success=false" | ||
| ); | ||
| } | ||
| if (data.result.choices?.length) { | ||
| const message = data.result.choices[0].message; | ||
| return message.content ?? message.reasoning_content ?? ""; | ||
| } | ||
| return data.result.response ?? ""; | ||
| return data.choices?.[0]?.message?.content ?? ""; | ||
| }, | ||
@@ -101,3 +92,3 @@ async *generateStream(question, context, opts) { | ||
| }, | ||
| body: JSON.stringify({ messages, stream: true }) | ||
| body: JSON.stringify({ model, messages, stream: true }) | ||
| }); | ||
@@ -126,3 +117,3 @@ if (!res.ok) { | ||
| const data = JSON.parse(payload); | ||
| const chunk = data.choices?.[0]?.delta?.content ?? data.response; | ||
| const chunk = data.choices?.[0]?.delta?.content; | ||
| if (chunk) yield chunk; | ||
@@ -129,0 +120,0 @@ } catch { |
+1
-1
| { | ||
| "name": "@ragpipe/plugin-cloudflare", | ||
| "version": "0.3.0-alpha.1", | ||
| "version": "0.3.0-alpha.2", | ||
| "description": "Cloudflare Workers AI embedding and generation plugin for ragpipe", | ||
@@ -5,0 +5,0 @@ "type": "module", |
13639
-4.11%292
-5.81%