added RAG, Multiuser, TG bot
This commit is contained in:
@@ -141,3 +141,24 @@ class HaClient:
|
||||
return int(session["id"])
|
||||
created = await self.create_session("Telegram")
|
||||
return int(created["id"])
|
||||
|
||||
async def download_media(self, path_or_url: str, *, ha_api_base: str | None = None) -> bytes:
|
||||
base = ha_api_base or self.base_url
|
||||
url = resolve_media_url(base, path_or_url)
|
||||
async with httpx.AsyncClient(timeout=60.0) as client:
|
||||
response = await client.get(url, headers=self._headers())
|
||||
if response.status_code >= 400:
|
||||
raise HaApiError(response.text.strip() or f"HTTP {response.status_code}", response.status_code)
|
||||
return response.content
|
||||
|
||||
|
||||
def resolve_media_url(ha_api_base: str, path_or_url: str) -> str:
|
||||
raw = (path_or_url or "").strip()
|
||||
if raw.startswith("http://") or raw.startswith("https://"):
|
||||
return raw
|
||||
origin = ha_api_base.rstrip("/")
|
||||
if origin.endswith("/api/v1"):
|
||||
origin = origin[: -len("/api/v1")]
|
||||
if not raw.startswith("/"):
|
||||
raw = f"/{raw}"
|
||||
return f"{origin}{raw}"
|
||||
|
||||
Reference in New Issue
Block a user