Cloudflare Docs
Workers AI
Edit this page on GitHub
Set theme to dark (⇧+D)

m2m100-1.2b

Model ID: @cf/meta/m2m100-1.2b

Multilingual encoder-decoder (seq-to-seq) model trained for Many-to-Many multilingual translation

More Information   Terms & License  

​​ Properties

Task Type: Translation

​​ Code Examples

Worker - TypeScript
import { Ai } from "@cloudflare/ai";
export interface Env {
AI: Ai;
}
export default {
async fetch(request: Request, env: Env) {
const ai = new Ai(env.AI);
const response = await ai.run(
"@cf/meta/m2m100-1.2b",
{
text: "I'll have an order of the moule frites",
source_lang: "english", // defaults to english
target_lang: "french",
}
);
return new Response(JSON.stringify(response));
},
};
Python
import requests
API_BASE_URL = "https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/run/"
headers = {"Authorization": "Bearer {API_TOKEN}"}
def run(model, input):
response = requests.post(f"{API_BASE_URL}{model}", headers=headers, json=input)
return response.json()
output = run('@cf/meta/m2m100-1.2b', {
"text": "I'll have an order of the moule frites",
"source_lang": "english",
"target_lang": "french"
})
print(output)
curl
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run/@cf/meta/m2m100-1.2b \
-X POST \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-d '{ "text": "Ill have an order of the moule frites", "source_lang": "english", "target_lang": "french" }'

​​ Response

{
"translated_text": "Je vais commander des moules frites"
}

​​ API Schema

The following schema is based on JSON Schema

Input JSON Schema
{
"type": "object",
"properties": {
"text": {
"type": "string"
},
"source_lang": {
"type": "string",
"default": "en"
},
"target_lang": {
"type": "string"
}
},
"required": [
"text",
"target_lang"
]
}
Output JSON Schema
{
"type": "object",
"contentType": "application/json",
"properties": {
"translated_text": {
"type": "string"
}
}
}