Skip to content

Instantly share code, notes, and snippets.

@jonasfroeller
Last active December 8, 2023 20:42
Show Gist options
  • Save jonasfroeller/c51f4c4af569fb59ed78361819603595 to your computer and use it in GitHub Desktop.
Save jonasfroeller/c51f4c4af569fb59ed78361819603595 to your computer and use it in GitHub Desktop.
cloudflare i18n worker
import { Ai } from './vendor/@cloudflare/ai.js';
export default {
async fetch(request, env) {
const ai = new Ai(env.AI);
const url = new URL(request.url);
const textParam = url.searchParams.get('text');
const inputs = {
text: textParam || "Standardtext, falls kein Textparameter übergeben wurde",
source_lang: 'de',
target_lang: 'en'
};
const response = await ai.run('@cf/meta/m2m100-1.2b', inputs);
return new Response(JSON.stringify({ inputs, response }), {
headers: { 'Content-Type': 'application/json' }
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment