import os
import httpx
from dotenv import load_dotenv

load_dotenv()

LIBRETRANSLATE_URL = os.getenv("LIBRETRANSLATE_URL", "http://192.168.1.109:5100")


async def translate_to_russian(text: str) -> str:
    async with httpx.AsyncClient(timeout=30) as client:
        r = await client.post(
            f"{LIBRETRANSLATE_URL}/translate",
            json={"q": text, "source": "auto", "target": "ru", "format": "text"},
        )
        r.raise_for_status()
        return r.json()["translatedText"]
