|
| 1 | +"""``client.ai`` — AI assistant: credits + LLM analysis.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from collections.abc import Sequence |
| 6 | +from typing import TYPE_CHECKING, Any |
| 7 | + |
| 8 | +if TYPE_CHECKING: |
| 9 | + from .._client import CryptohopperClient |
| 10 | + |
| 11 | + |
| 12 | +class AI: |
| 13 | + def __init__(self, client: CryptohopperClient) -> None: |
| 14 | + self._client = client |
| 15 | + |
| 16 | + def list(self, **params: Any) -> Sequence[dict[str, Any]]: |
| 17 | + """List AI assistant items / sessions. Requires ``read``.""" |
| 18 | + return self._client._request("GET", "/ai/list", params=params or None) |
| 19 | + |
| 20 | + def get(self, id: int | str) -> dict[str, Any]: |
| 21 | + """Fetch a single AI item / session. Requires ``read``.""" |
| 22 | + return self._client._request("GET", "/ai/get", params={"id": id}) |
| 23 | + |
| 24 | + def available_models(self) -> Sequence[dict[str, Any]]: |
| 25 | + """Models available to the authenticated user.""" |
| 26 | + return self._client._request("GET", "/ai/availablemodels") |
| 27 | + |
| 28 | + # ─── Credits ───────────────────────────────────────────────────────── |
| 29 | + |
| 30 | + def get_credits(self) -> dict[str, Any]: |
| 31 | + """Remaining AI credit balance. Requires ``read``.""" |
| 32 | + return self._client._request("GET", "/ai/getaicredits") |
| 33 | + |
| 34 | + def credit_invoices(self, **params: Any) -> Sequence[dict[str, Any]]: |
| 35 | + """Past invoices for AI-credit purchases. Requires ``read``.""" |
| 36 | + return self._client._request( |
| 37 | + "GET", "/ai/aicreditinvoices", params=params or None |
| 38 | + ) |
| 39 | + |
| 40 | + def credit_transactions(self, **params: Any) -> Sequence[dict[str, Any]]: |
| 41 | + """Credit spend/top-up transaction history. Requires ``read``.""" |
| 42 | + return self._client._request( |
| 43 | + "GET", "/ai/aicredittransactions", params=params or None |
| 44 | + ) |
| 45 | + |
| 46 | + def buy_credits(self, data: dict[str, Any]) -> dict[str, Any]: |
| 47 | + """Start a purchase of additional credits. Requires ``user``.""" |
| 48 | + return self._client._request("POST", "/ai/buyaicredits", json=data) |
| 49 | + |
| 50 | + # ─── LLM analysis ──────────────────────────────────────────────────── |
| 51 | + |
| 52 | + def llm_analyze_options(self) -> dict[str, Any]: |
| 53 | + """Options/metadata for the LLM analyse endpoint. Requires ``read``.""" |
| 54 | + return self._client._request("GET", "/ai/aillmanalyzeoptions") |
| 55 | + |
| 56 | + def llm_analyze(self, data: dict[str, Any]) -> dict[str, Any]: |
| 57 | + """Run an LLM analysis. Usually async — returns a job id. Requires ``manage``.""" |
| 58 | + return self._client._request("POST", "/ai/doaillmanalyze", json=data) |
| 59 | + |
| 60 | + def llm_analyze_results(self, **params: Any) -> dict[str, Any]: |
| 61 | + """Fetch the result(s) of an LLM analysis. Requires ``read``.""" |
| 62 | + return self._client._request( |
| 63 | + "GET", "/ai/aillmanalyzeresults", params=params or None |
| 64 | + ) |
| 65 | + |
| 66 | + def llm_results(self, **params: Any) -> Sequence[dict[str, Any]]: |
| 67 | + """Historical LLM analysis results. Requires ``read``.""" |
| 68 | + return self._client._request( |
| 69 | + "GET", "/ai/aillmresults", params=params or None |
| 70 | + ) |
0 commit comments