diff --git a/src/components/models/code/Bge-Reranker-Base.astro b/src/components/models/code/Bge-Reranker-Base.astro new file mode 100644 index 000000000000000..e0cbb1743fbce4a --- /dev/null +++ b/src/components/models/code/Bge-Reranker-Base.astro @@ -0,0 +1,79 @@ +--- +import { z } from "astro:schema"; +import { Code } from "@astrojs/starlight/components"; +import Details from "~/components/Details.astro"; + +type Props = z.infer; + +const props = z.object({ + name: z.string(), +}); + +const { name } = props.parse(Astro.props); + +const worker = ` +export interface Env { + AI: Ai; +} + +export default { + async fetch(request, env): Promise { + const query = 'Which one is cooler?' + const contexts = [ + { + text: 'a cyberpunk lizzard' + }, + { + text: 'a cyberpunk cat' + } + ]; + + const response = await env.AI.run('${name}', { query, contexts }); + + return Response.json(response); + }, +} satisfies ExportedHandler; + +`; + +const python = ` +import os +import requests + +ACCOUNT_ID = "your-account-id" +AUTH_TOKEN = os.environ.get("CLOUDFLARE_AUTH_TOKEN") + +response = requests.post( + f"https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/run/${name}", + headers={"Authorization": f"Bearer {AUTH_TOKEN}"}, + json={ + "query": "Which one is better?" + "context": [ + {"text": "a cyberpunk lizzard"}, + {"text": "a cyberpunk car"}, + ] + } +) +result = response.json() +print(result) +`; + +const curl = ` +curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run/${name} \\ + -X POST \\ + -H "Authorization: Bearer $CLOUDFLARE_AUTH_TOKEN" \\ + -d '{ "query": "Which one is better?", "contexts": [{ "text": "a cyberpunk lizzard" }, {"text": "a cyberpunk cat"}]}' +`; +--- + +
+ +
+ +
+ +
+ +
+ +
diff --git a/src/pages/workers-ai/models/[name].astro b/src/pages/workers-ai/models/[name].astro index 46d45c8657912a1..bba0efd12a5c6f4 100644 --- a/src/pages/workers-ai/models/[name].astro +++ b/src/pages/workers-ai/models/[name].astro @@ -24,6 +24,7 @@ import StableDiffusionV15InpaintingCode from "~/components/models/code/StableDif import Flux1Schnell from "~/components/models/code/Flux-1-Schnell.astro"; import WhisperBase64Code from "~/components/models/code/WhisperBase64Code.astro"; import LlamaGuard from "~/components/models/code/LlamaGuard.astro"; +import BgeRerankerBase from "~/components/models/code/Bge-Reranker-Base.astro"; import { authorData } from "~/components/models/data"; @@ -98,6 +99,10 @@ if (model.name === "@cf/meta/llama-guard-3-8b") { CodeExamples = LlamaGuard; } +if (model.name === "@cf/baai/bge-reranker-base") { + CodeExamples = BgeRerankerBase; +} + const description = model.description; const isBeta = model.properties.find(