Tổng Quan
Sử dụng /v1/translations cho dịch văn bản sang văn bản.
Endpoint này khác với Dịch Âm Thanh, endpoint này nhận một tệp âm thanh và luôn xuất ra văn bản tiếng Anh.
Với các luồng agent, trước tiên hãy khám phá các model dịch được khuyến nghị hiện tại:
curl "https://api.tokenlab.sh/v1/models?recommended_for=translation" \
-H "Authorization: Bearer sk-your-api-key"
Sau đó gửi rõ model đã chọn đến /v1/translations.
recommended_for=translation chỉ áp dụng cho dịch văn bản (POST /v1/translations). Nó không áp dụng cho dịch âm thanh.
Thân Yêu Cầu
ID model dịch được trả về từ /v1/models?recommended_for=translation.
Mã ngôn ngữ đích hoặc tên ngôn ngữ, tùy theo hỗ trợ của model.
Gợi ý ngôn ngữ nguồn tùy chọn.
mime_type
string
mặc định:"text/plain"
Định dạng văn bản nguồn. Giá trị hỗ trợ: text/plain, text/html.
Định danh người dùng cuối tùy chọn để giám sát lạm dụng và theo dõi request.
Phản Hồi
Ngôn ngữ nguồn được model phát hiện hoặc chấp nhận.
Ngôn ngữ đích được dùng cho request.
curl -X POST "https://api.tokenlab.sh/v1/translations" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "doubao-seed-translation",
"text": "你好,欢迎使用 TokenLab。",
"target_language": "en"
}'
from openai import OpenAI
import requests
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://api.tokenlab.sh/v1"
)
response = requests.post(
"https://api.tokenlab.sh/v1/translations",
headers={
"Authorization": "Bearer sk-your-api-key",
"Content-Type": "application/json",
},
json={
"model": "doubao-seed-translation",
"text": "你好,欢迎使用 TokenLab。",
"target_language": "en",
},
timeout=30,
)
print(response.json()["text"])
{
"text": "Hello, welcome to TokenLab.",
"model": "doubao-seed-translation",
"source_language": "zh",
"target_language": "en"
}