Spaces:
Sleeping
Sleeping
Commit ·
e68c044
1
Parent(s): c7f28a0
fix: switch to chat_completion API for Mistral-7B
Browse files
app.py
CHANGED
|
@@ -110,17 +110,17 @@ def translate(req: TranslationRequest):
|
|
| 110 |
if len(req.arabic_text) > 3000:
|
| 111 |
raise HTTPException(status_code=400, detail="arabic_text too long (max 3000 chars)")
|
| 112 |
|
| 113 |
-
prompt = f"<s>[INST] {SYSTEM_PROMPT}\n\nTranslate this Arabic dua into {req.target_language} and provide its transliteration.\n\nArabic text: {req.arabic_text.strip()}\n\nRespond ONLY with JSON: {{\"translation\": \"...\", \"transliteration\": \"...\"}} [/INST]"
|
| 114 |
-
|
| 115 |
try:
|
| 116 |
-
response = client.
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
| 119 |
temperature=0.2,
|
| 120 |
-
repetition_penalty=1.1,
|
| 121 |
-
do_sample=True,
|
| 122 |
)
|
| 123 |
-
|
|
|
|
| 124 |
return TranslationResponse(
|
| 125 |
translation=result.get("translation", ""),
|
| 126 |
transliteration=result.get("transliteration", ""),
|
|
|
|
| 110 |
if len(req.arabic_text) > 3000:
|
| 111 |
raise HTTPException(status_code=400, detail="arabic_text too long (max 3000 chars)")
|
| 112 |
|
|
|
|
|
|
|
| 113 |
try:
|
| 114 |
+
response = client.chat_completion(
|
| 115 |
+
messages=[
|
| 116 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
| 117 |
+
{"role": "user", "content": f"Translate this Arabic dua into {req.target_language} and provide its transliteration.\n\nArabic text: {req.arabic_text.strip()}\n\nRespond ONLY with JSON: {{\"translation\": \"...\", \"transliteration\": \"...\"}}"},
|
| 118 |
+
],
|
| 119 |
+
max_tokens=600,
|
| 120 |
temperature=0.2,
|
|
|
|
|
|
|
| 121 |
)
|
| 122 |
+
raw = response.choices[0].message.content
|
| 123 |
+
result = extract_json(raw)
|
| 124 |
return TranslationResponse(
|
| 125 |
translation=result.get("translation", ""),
|
| 126 |
transliteration=result.get("transliteration", ""),
|