Last active
December 8, 2023 20:42
-
-
Save jonasfroeller/c51f4c4af569fb59ed78361819603595 to your computer and use it in GitHub Desktop.
cloudflare i18n worker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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