1. Translate the same text into multiple languages—how can I keep the prompt short?
Çoklu diller için tek satırda dil kodlarını listelerim:
Bu sayede tek bir çağrıda dört çeviri alınır; prompt uzunluğu kısa tutulur.
2. How do I force a consistent output structure for each language?
System mesajı ekleyerek formatı belirlerim:
Bu, genellikle
3. What settings reduce token usage and cost for large texts?
4. Can I cache translations to avoid repeated requests?
Evet, çeviri sonuçlarını bir key‑value veritabanında saklayarak aynı metin için tekrar çağrı yapılmasını engelleyebilirsiniz.
5. What is a quick sanity check before sending a big request?
Bir test isteğiyle tek bir dil için kısa bir metni çevirerek yanıt formatını ve token sayısını kontrol edin.
Bu, beklenmedik yüksek token maliyetlerini önler.
Çoklu diller için tek satırda dil kodlarını listelerim:
Kod:
Translate the following text into Spanish, French, German, and Italian.
Text: {original_text}
2. How do I force a consistent output structure for each language?
System mesajı ekleyerek formatı belirlerim:
Kod:
System: For each language, output the ISO code followed by the translation.
Example: "es: Hola"
Do not add extra text or explanations.
json_format gibi yapılandırılmış çıktı sağlamaya yöneliktir.3. What settings reduce token usage and cost for large texts?
max_tokensparametresiyle maksimum çıktı uzunluğunu sınırlayın.- Çok uzun metinleri bölebilir ve her parçayı ayrı çağrı yaparak toplam token sayısını düşürebilirsiniz.
temperature=0.2gibi düşük bir sıcaklık ile daha kısa yanıtlar alınır.
4. Can I cache translations to avoid repeated requests?
Evet, çeviri sonuçlarını bir key‑value veritabanında saklayarak aynı metin için tekrar çağrı yapılmasını engelleyebilirsiniz.
Python:
cache_key = f"translate:{hash(original_text)}:{','.join(languages)}"
translation = cache.get(cache_key) or openai.ChatCompletion.create(...)
cache.set(cache_key, translation, ttl=86400)
5. What is a quick sanity check before sending a big request?
Bir test isteğiyle tek bir dil için kısa bir metni çevirerek yanıt formatını ve token sayısını kontrol edin.
Python:
response = openai.ChatCompletion.create(
model="gpt-4o-mini",
messages=[{"role":"system","content":"..."},
{"role":"user","content":"Translate 'Hello world' to Spanish."}],
max_tokens=50
)
print(response.choices[0].message.content)