trovegen 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- trovegen/__init__.py +41 -0
- trovegen/_async.py +357 -0
- trovegen/_client.py +446 -0
- trovegen/_core.py +193 -0
- trovegen/py.typed +0 -0
- trovegen-0.3.0.dist-info/METADATA +187 -0
- trovegen-0.3.0.dist-info/RECORD +9 -0
- trovegen-0.3.0.dist-info/WHEEL +4 -0
- trovegen-0.3.0.dist-info/licenses/LICENSE +202 -0
trovegen/__init__.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""troveGEN Python SDK: ingestion, hybrid search and grounded, cited answers.
|
|
2
|
+
|
|
3
|
+
from trovegen import TroveGen
|
|
4
|
+
tg = TroveGen(api_key="trv_...", base_url="https://trovegen.com")
|
|
5
|
+
tg.documents.ingest_text(project_id, "...", title="Refunds", external_id="kb/refunds", metadata={"topics": ["billing"]})
|
|
6
|
+
hits = tg.search(project_id, "refund window", filter={"topics": "billing"}, timeout=2.0)
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import base64
|
|
12
|
+
import hashlib
|
|
13
|
+
import hmac
|
|
14
|
+
import json
|
|
15
|
+
import time
|
|
16
|
+
from typing import Sequence
|
|
17
|
+
|
|
18
|
+
from ._async import AsyncTroveGen
|
|
19
|
+
from ._client import TroveGen
|
|
20
|
+
from ._core import ResponseInfo, TroveGenError, parse_server_timing
|
|
21
|
+
|
|
22
|
+
__all__ = ["TroveGen", "AsyncTroveGen", "TroveGenError", "ResponseInfo", "mint_end_user_token", "parse_server_timing"]
|
|
23
|
+
__version__ = "0.3.0"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _b64url(data: bytes) -> str:
|
|
27
|
+
return base64.urlsafe_b64encode(data).rstrip(b"=").decode("ascii")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def mint_end_user_token(secret: str, sub: str, principals: Sequence[str], ttl_seconds: int = 300) -> str:
|
|
31
|
+
"""Sign a short-lived end-user assertion (HS256) with the project's ACL secret; send it as ``end_user_token``.
|
|
32
|
+
|
|
33
|
+
Do this on your server only: the secret must never reach a browser. The server accepts at most 15 minutes.
|
|
34
|
+
"""
|
|
35
|
+
if ttl_seconds < 1 or ttl_seconds > 900:
|
|
36
|
+
raise ValueError("ttl_seconds must be between 1 and 900")
|
|
37
|
+
now = int(time.time())
|
|
38
|
+
header = _b64url(json.dumps({"alg": "HS256", "typ": "JWT"}, separators=(",", ":")).encode())
|
|
39
|
+
payload = _b64url(json.dumps({"sub": sub, "principals": list(principals), "iat": now, "exp": now + ttl_seconds}, separators=(",", ":")).encode())
|
|
40
|
+
signature = hmac.new(secret.encode(), f"{header}.{payload}".encode(), hashlib.sha256).digest()
|
|
41
|
+
return f"{header}.{payload}.{_b64url(signature)}"
|
trovegen/_async.py
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
"""The asyncio troveGEN client: the same surface as ``TroveGen``, with ``await``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import time
|
|
7
|
+
from typing import Any, AsyncIterator, Dict, List, Mapping, Optional, Sequence
|
|
8
|
+
|
|
9
|
+
import httpx
|
|
10
|
+
|
|
11
|
+
from ._client import FileData
|
|
12
|
+
from ._core import (
|
|
13
|
+
DEFAULT_BASE_URL,
|
|
14
|
+
DEFAULT_MAX_RETRIES,
|
|
15
|
+
DEFAULT_TIMEOUT,
|
|
16
|
+
OnResponse,
|
|
17
|
+
ResponseInfo,
|
|
18
|
+
TroveGenError,
|
|
19
|
+
backoff,
|
|
20
|
+
body_from,
|
|
21
|
+
file_fields,
|
|
22
|
+
parse_server_timing,
|
|
23
|
+
parse_sse_block,
|
|
24
|
+
query_string,
|
|
25
|
+
retry_after,
|
|
26
|
+
seg,
|
|
27
|
+
unwrap,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class _AsyncTransport:
|
|
32
|
+
def __init__(
|
|
33
|
+
self,
|
|
34
|
+
api_key: str,
|
|
35
|
+
base_url: str,
|
|
36
|
+
timeout: float,
|
|
37
|
+
max_retries: int,
|
|
38
|
+
on_response: Optional[OnResponse],
|
|
39
|
+
http_client: Optional[httpx.AsyncClient],
|
|
40
|
+
):
|
|
41
|
+
if not api_key:
|
|
42
|
+
raise ValueError("AsyncTroveGen: api_key is required")
|
|
43
|
+
self.base = base_url.rstrip("/") + "/api/v1"
|
|
44
|
+
self.headers = {"Authorization": f"Bearer {api_key}", "User-Agent": "trovegen-python/0.3.0"}
|
|
45
|
+
self.timeout = timeout
|
|
46
|
+
self.max_retries = max_retries
|
|
47
|
+
self.on_response = on_response
|
|
48
|
+
self.http = http_client or httpx.AsyncClient()
|
|
49
|
+
self._own_client = http_client is None
|
|
50
|
+
|
|
51
|
+
async def close(self) -> None:
|
|
52
|
+
if self._own_client:
|
|
53
|
+
await self.http.aclose()
|
|
54
|
+
|
|
55
|
+
def _report(self, method: str, path: str, res: httpx.Response, ms: float, attempt: int) -> None:
|
|
56
|
+
if not self.on_response:
|
|
57
|
+
return
|
|
58
|
+
try:
|
|
59
|
+
total, stages = parse_server_timing(res.headers.get("server-timing"))
|
|
60
|
+
self.on_response(ResponseInfo(method, path, res.status_code, ms, attempt, res.headers.get("x-request-id"), total, stages))
|
|
61
|
+
except Exception:
|
|
62
|
+
pass
|
|
63
|
+
|
|
64
|
+
async def send(
|
|
65
|
+
self,
|
|
66
|
+
method: str,
|
|
67
|
+
path: str,
|
|
68
|
+
*,
|
|
69
|
+
json: Any = None,
|
|
70
|
+
files: Any = None,
|
|
71
|
+
data: Optional[Mapping[str, str]] = None,
|
|
72
|
+
end_user_token: Optional[str] = None,
|
|
73
|
+
timeout: Optional[float] = None,
|
|
74
|
+
max_retries: Optional[int] = None,
|
|
75
|
+
stream: bool = False,
|
|
76
|
+
) -> httpx.Response:
|
|
77
|
+
retries = self.max_retries if max_retries is None else max_retries
|
|
78
|
+
deadline = time.monotonic() + timeout if timeout is not None else None
|
|
79
|
+
headers = dict(self.headers)
|
|
80
|
+
if end_user_token:
|
|
81
|
+
headers["x-trovegen-end-user"] = end_user_token
|
|
82
|
+
if stream:
|
|
83
|
+
headers["Accept"] = "text/event-stream"
|
|
84
|
+
last: Optional[TroveGenError] = None
|
|
85
|
+
for attempt in range(retries + 1):
|
|
86
|
+
remaining = self.timeout if deadline is None else deadline - time.monotonic()
|
|
87
|
+
if remaining <= 0:
|
|
88
|
+
raise TroveGenError("TIMEOUT", f"troveGEN did not answer within {timeout} s", 0, details={"attempts": attempt})
|
|
89
|
+
started = time.monotonic()
|
|
90
|
+
try:
|
|
91
|
+
req = self.http.build_request(method, self.base + path, headers=headers, json=json, files=files, data=data, timeout=remaining)
|
|
92
|
+
# asyncio.wait_for as well: httpx timeouts are per phase, a slow trickle could otherwise outlive the budget.
|
|
93
|
+
res = await asyncio.wait_for(self.http.send(req, stream=stream), timeout=remaining)
|
|
94
|
+
except (httpx.TimeoutException, asyncio.TimeoutError):
|
|
95
|
+
last = TroveGenError("TIMEOUT", f"troveGEN did not answer within {timeout if timeout is not None else self.timeout} s", 0)
|
|
96
|
+
except httpx.TransportError as exc:
|
|
97
|
+
last = TroveGenError("NETWORK_ERROR", f"Could not reach troveGEN: {exc}", 0, details={"cause": str(exc)})
|
|
98
|
+
else:
|
|
99
|
+
self._report(method, path, res, (time.monotonic() - started) * 1000, attempt)
|
|
100
|
+
if (res.status_code == 429 or res.status_code >= 500) and attempt < retries:
|
|
101
|
+
wait = retry_after(res.headers) or backoff(attempt)
|
|
102
|
+
if deadline is None or time.monotonic() + wait < deadline:
|
|
103
|
+
await res.aclose()
|
|
104
|
+
await asyncio.sleep(wait)
|
|
105
|
+
continue
|
|
106
|
+
return res
|
|
107
|
+
wait = backoff(attempt)
|
|
108
|
+
if attempt < retries and (deadline is None or time.monotonic() + wait < deadline):
|
|
109
|
+
await asyncio.sleep(wait)
|
|
110
|
+
continue
|
|
111
|
+
raise last
|
|
112
|
+
raise last or TroveGenError("NETWORK_ERROR", "request failed", 0)
|
|
113
|
+
|
|
114
|
+
async def json(self, method: str, path: str, **kw: Any) -> Any:
|
|
115
|
+
res = await self.send(method, path, **kw)
|
|
116
|
+
return unwrap(res.status_code, res.text, res.headers.get("x-request-id"))
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class _AsyncProjects:
|
|
120
|
+
def __init__(self, t: _AsyncTransport):
|
|
121
|
+
self._t = t
|
|
122
|
+
|
|
123
|
+
async def create(self, name: str, **settings: Any) -> Dict[str, Any]:
|
|
124
|
+
return await self._t.json("POST", "/projects", json={"name": name, **body_from(settings)})
|
|
125
|
+
|
|
126
|
+
async def list(self) -> List[Dict[str, Any]]:
|
|
127
|
+
return await self._t.json("GET", "/projects")
|
|
128
|
+
|
|
129
|
+
async def get(self, project_id: str) -> Dict[str, Any]:
|
|
130
|
+
return await self._t.json("GET", f"/projects/{seg(project_id)}")
|
|
131
|
+
|
|
132
|
+
async def update(self, project_id: str, **patch: Any) -> Dict[str, Any]:
|
|
133
|
+
return await self._t.json("PATCH", f"/projects/{seg(project_id)}", json=body_from(patch))
|
|
134
|
+
|
|
135
|
+
async def delete(self, project_id: str) -> Dict[str, Any]:
|
|
136
|
+
return await self._t.json("DELETE", f"/projects/{seg(project_id)}")
|
|
137
|
+
|
|
138
|
+
async def metadata_keys(self, project_id: str) -> List[Dict[str, Any]]:
|
|
139
|
+
return await self._t.json("GET", f"/projects/{seg(project_id)}/metadata-keys")
|
|
140
|
+
|
|
141
|
+
async def rotate_acl_secret(self, project_id: str) -> Dict[str, Any]:
|
|
142
|
+
return await self._t.json("POST", f"/projects/{seg(project_id)}/acl-secret")
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
class _AsyncDocuments:
|
|
146
|
+
def __init__(self, t: _AsyncTransport):
|
|
147
|
+
self._t = t
|
|
148
|
+
|
|
149
|
+
async def ingest_text(
|
|
150
|
+
self,
|
|
151
|
+
project_id: str,
|
|
152
|
+
text: Optional[str] = None,
|
|
153
|
+
*,
|
|
154
|
+
segments: Optional[Sequence[Mapping[str, Any]]] = None,
|
|
155
|
+
title: Optional[str] = None,
|
|
156
|
+
external_id: Optional[str] = None,
|
|
157
|
+
metadata: Optional[Mapping[str, Any]] = None,
|
|
158
|
+
acl: Optional[Mapping[str, Any]] = None,
|
|
159
|
+
document_type: Optional[str] = None,
|
|
160
|
+
domain: Optional[str] = None,
|
|
161
|
+
layout: Optional[str] = None,
|
|
162
|
+
book_title: Optional[str] = None,
|
|
163
|
+
force: Optional[bool] = None,
|
|
164
|
+
timeout: Optional[float] = None,
|
|
165
|
+
) -> Dict[str, Any]:
|
|
166
|
+
body = body_from(
|
|
167
|
+
dict(
|
|
168
|
+
text=text,
|
|
169
|
+
segments=list(segments) if segments is not None else None,
|
|
170
|
+
title=title,
|
|
171
|
+
external_id=external_id,
|
|
172
|
+
metadata=dict(metadata) if metadata is not None else None,
|
|
173
|
+
acl=dict(acl) if acl is not None else None,
|
|
174
|
+
document_type=document_type,
|
|
175
|
+
domain=domain,
|
|
176
|
+
layout=layout,
|
|
177
|
+
book_title=book_title,
|
|
178
|
+
force=force,
|
|
179
|
+
)
|
|
180
|
+
)
|
|
181
|
+
return await self._t.json("POST", f"/projects/{seg(project_id)}/documents/text", json=body, timeout=timeout)
|
|
182
|
+
|
|
183
|
+
async def ingest_url(self, project_id: str, url: str, **options: Any) -> Dict[str, Any]:
|
|
184
|
+
return await self._t.json("POST", f"/projects/{seg(project_id)}/documents/url", json={"url": url, **body_from(options)})
|
|
185
|
+
|
|
186
|
+
async def ingest_file(
|
|
187
|
+
self, project_id: str, data: FileData, filename: str, *, content_type: str = "application/octet-stream", wait: bool = True, **options: Any
|
|
188
|
+
) -> Dict[str, Any]:
|
|
189
|
+
fields = file_fields(**options)
|
|
190
|
+
path = f"/projects/{seg(project_id)}/documents/file" + ("" if wait else "?async=1")
|
|
191
|
+
out = await self._t.json("POST", path, files={"file": (filename, data, content_type)}, data=fields)
|
|
192
|
+
return out if wait else out.get("job", out)
|
|
193
|
+
|
|
194
|
+
async def job(self, project_id: str, job_id: str) -> Dict[str, Any]:
|
|
195
|
+
return await self._t.json("GET", f"/projects/{seg(project_id)}/ingest-jobs/{seg(job_id)}")
|
|
196
|
+
|
|
197
|
+
async def wait_for_job(self, project_id: str, job_id: str, *, timeout: float = 900.0, poll: float = 1.0) -> Dict[str, Any]:
|
|
198
|
+
deadline = time.monotonic() + timeout
|
|
199
|
+
while True:
|
|
200
|
+
job = await self.job(project_id, job_id)
|
|
201
|
+
if job.get("state") == "completed":
|
|
202
|
+
return job
|
|
203
|
+
if job.get("state") == "failed":
|
|
204
|
+
err = job.get("error") or {}
|
|
205
|
+
raise TroveGenError(err.get("code", "INGEST_FAILED"), err.get("message", "The upload failed"), 422)
|
|
206
|
+
if time.monotonic() > deadline:
|
|
207
|
+
raise TroveGenError("INGEST_WAIT_TIMEOUT", "The upload did not finish in time", 408)
|
|
208
|
+
await asyncio.sleep(poll)
|
|
209
|
+
|
|
210
|
+
async def list(
|
|
211
|
+
self,
|
|
212
|
+
project_id: str,
|
|
213
|
+
*,
|
|
214
|
+
external_id: Optional[str] = None,
|
|
215
|
+
folder: Optional[str] = None,
|
|
216
|
+
status: Optional[str] = None,
|
|
217
|
+
limit: Optional[int] = None,
|
|
218
|
+
offset: Optional[int] = None,
|
|
219
|
+
) -> List[Dict[str, Any]]:
|
|
220
|
+
q = query_string(dict(external_id=external_id, folder=folder, status=status, limit=limit, offset=offset))
|
|
221
|
+
return await self._t.json("GET", f"/projects/{seg(project_id)}/documents{q}")
|
|
222
|
+
|
|
223
|
+
async def get(self, project_id: str, document_id: str) -> Dict[str, Any]:
|
|
224
|
+
return await self._t.json("GET", f"/projects/{seg(project_id)}/documents/{seg(document_id)}")
|
|
225
|
+
|
|
226
|
+
async def find_by_external_id(self, project_id: str, external_id: str) -> Optional[Dict[str, Any]]:
|
|
227
|
+
rows = await self.list(project_id, external_id=external_id, status="completed", limit=1)
|
|
228
|
+
return rows[0] if rows else None
|
|
229
|
+
|
|
230
|
+
async def update_metadata(
|
|
231
|
+
self,
|
|
232
|
+
project_id: str,
|
|
233
|
+
document_id: str,
|
|
234
|
+
metadata: Optional[Mapping[str, Any]] = None,
|
|
235
|
+
*,
|
|
236
|
+
mode: str = "merge",
|
|
237
|
+
segments: Optional[Sequence[Mapping[str, Any]]] = None,
|
|
238
|
+
title: Optional[str] = None,
|
|
239
|
+
external_id: Any = ...,
|
|
240
|
+
) -> Dict[str, Any]:
|
|
241
|
+
body: Dict[str, Any] = {"mode": mode}
|
|
242
|
+
if metadata is not None:
|
|
243
|
+
body["metadata"] = dict(metadata)
|
|
244
|
+
if segments is not None:
|
|
245
|
+
body["segments"] = list(segments)
|
|
246
|
+
if title is not None:
|
|
247
|
+
body["title"] = title
|
|
248
|
+
if external_id is not ...:
|
|
249
|
+
body["externalId"] = external_id
|
|
250
|
+
return await self._t.json("PATCH", f"/projects/{seg(project_id)}/documents/{seg(document_id)}/metadata", json=body)
|
|
251
|
+
|
|
252
|
+
async def set_acl(self, project_id: str, document_id: str, public: bool, principals: Optional[Sequence[str]] = None) -> Dict[str, Any]:
|
|
253
|
+
acl: Dict[str, Any] = {"public": public}
|
|
254
|
+
if principals is not None:
|
|
255
|
+
acl["principals"] = list(principals)
|
|
256
|
+
return await self._t.json("PATCH", f"/projects/{seg(project_id)}/documents/{seg(document_id)}/acl", json={"acl": acl})
|
|
257
|
+
|
|
258
|
+
async def content(self, project_id: str, document_id: str) -> Dict[str, Any]:
|
|
259
|
+
return await self._t.json("GET", f"/projects/{seg(project_id)}/documents/{seg(document_id)}/content")
|
|
260
|
+
|
|
261
|
+
async def deletion_impact(self, project_id: str, document_id: str) -> Dict[str, Any]:
|
|
262
|
+
return await self._t.json("GET", f"/projects/{seg(project_id)}/documents/{seg(document_id)}/deletion-impact")
|
|
263
|
+
|
|
264
|
+
async def delete(self, project_id: str, document_id: str) -> Dict[str, Any]:
|
|
265
|
+
return await self._t.json("DELETE", f"/projects/{seg(project_id)}/documents/{seg(document_id)}")
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
class AsyncTroveGen:
|
|
269
|
+
"""asyncio client. ``async with AsyncTroveGen(api_key=...) as tg: await tg.search(...)``."""
|
|
270
|
+
|
|
271
|
+
def __init__(
|
|
272
|
+
self,
|
|
273
|
+
api_key: str,
|
|
274
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
275
|
+
*,
|
|
276
|
+
timeout: float = DEFAULT_TIMEOUT,
|
|
277
|
+
max_retries: int = DEFAULT_MAX_RETRIES,
|
|
278
|
+
on_response: Optional[OnResponse] = None,
|
|
279
|
+
http_client: Optional[httpx.AsyncClient] = None,
|
|
280
|
+
):
|
|
281
|
+
self._t = _AsyncTransport(api_key, base_url, timeout, max_retries, on_response, http_client)
|
|
282
|
+
self.projects = _AsyncProjects(self._t)
|
|
283
|
+
self.documents = _AsyncDocuments(self._t)
|
|
284
|
+
|
|
285
|
+
async def __aenter__(self) -> "AsyncTroveGen":
|
|
286
|
+
return self
|
|
287
|
+
|
|
288
|
+
async def __aexit__(self, *exc: Any) -> None:
|
|
289
|
+
await self.close()
|
|
290
|
+
|
|
291
|
+
async def close(self) -> None:
|
|
292
|
+
await self._t.close()
|
|
293
|
+
|
|
294
|
+
async def search(
|
|
295
|
+
self, project_id: str, query: str, *, end_user_token: Optional[str] = None, timeout: Optional[float] = None, max_retries: Optional[int] = None, **params: Any
|
|
296
|
+
) -> Dict[str, Any]:
|
|
297
|
+
return await self._t.json(
|
|
298
|
+
"POST",
|
|
299
|
+
f"/projects/{seg(project_id)}/search",
|
|
300
|
+
json={"query": query, **body_from(params)},
|
|
301
|
+
end_user_token=end_user_token,
|
|
302
|
+
timeout=timeout,
|
|
303
|
+
max_retries=max_retries,
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
async def search_projects(self, query: str, *, project_ids: Optional[Sequence[str]] = None, timeout: Optional[float] = None, **params: Any) -> Dict[str, Any]:
|
|
307
|
+
if project_ids is not None and len(project_ids) == 0:
|
|
308
|
+
raise TroveGenError("INVALID_INPUT", "project_ids must name at least one project; leave it out to search every project", 400)
|
|
309
|
+
body = {"query": query, **body_from(params), **({"projectIds": list(project_ids)} if project_ids else {})}
|
|
310
|
+
return await self._t.json("POST", "/search", json=body, timeout=timeout)
|
|
311
|
+
|
|
312
|
+
async def ask(
|
|
313
|
+
self, project_id: str, query: str, *, end_user_token: Optional[str] = None, timeout: Optional[float] = None, max_retries: Optional[int] = None, **params: Any
|
|
314
|
+
) -> Dict[str, Any]:
|
|
315
|
+
return await self._t.json(
|
|
316
|
+
"POST",
|
|
317
|
+
f"/projects/{seg(project_id)}/ask",
|
|
318
|
+
json={"query": query, **body_from(params)},
|
|
319
|
+
end_user_token=end_user_token,
|
|
320
|
+
timeout=timeout,
|
|
321
|
+
max_retries=max_retries,
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
async def ask_stream(
|
|
325
|
+
self, project_id: str, query: str, *, end_user_token: Optional[str] = None, timeout: Optional[float] = None, **params: Any
|
|
326
|
+
) -> AsyncIterator[Dict[str, Any]]:
|
|
327
|
+
res = await self._t.send(
|
|
328
|
+
"POST",
|
|
329
|
+
f"/projects/{seg(project_id)}/ask",
|
|
330
|
+
json={"query": query, "stream": True, **body_from(params)},
|
|
331
|
+
end_user_token=end_user_token,
|
|
332
|
+
timeout=timeout,
|
|
333
|
+
stream=True,
|
|
334
|
+
)
|
|
335
|
+
try:
|
|
336
|
+
if res.status_code >= 400:
|
|
337
|
+
await res.aread()
|
|
338
|
+
unwrap(res.status_code, res.text, res.headers.get("x-request-id"))
|
|
339
|
+
buffer = ""
|
|
340
|
+
async for chunk in res.aiter_text():
|
|
341
|
+
buffer += chunk
|
|
342
|
+
while "\n\n" in buffer:
|
|
343
|
+
block, buffer = buffer.split("\n\n", 1)
|
|
344
|
+
event = parse_sse_block(block)
|
|
345
|
+
if event is not None:
|
|
346
|
+
yield event
|
|
347
|
+
finally:
|
|
348
|
+
await res.aclose()
|
|
349
|
+
|
|
350
|
+
async def asset(self, project_id: str, asset_id: str, *, end_user_token: Optional[str] = None) -> tuple[bytes, str]:
|
|
351
|
+
res = await self._t.send("GET", f"/projects/{seg(project_id)}/assets/{seg(asset_id)}", end_user_token=end_user_token)
|
|
352
|
+
if res.status_code >= 400:
|
|
353
|
+
unwrap(res.status_code, res.text, res.headers.get("x-request-id"))
|
|
354
|
+
return res.content, res.headers.get("content-type", "application/octet-stream")
|
|
355
|
+
|
|
356
|
+
async def usage(self) -> Dict[str, Any]:
|
|
357
|
+
return await self._t.json("GET", "/usage")
|