added RAG, Multiuser, TG bot

This commit is contained in:
2026-06-14 06:26:16 +00:00
parent c8a9429bed
commit 0c8ab6018a
24 changed files with 1280 additions and 479 deletions
+21
View File
@@ -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}"