llama-cloud 0.1.8__py3-none-any.whl → 0.1.9__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.

Potentially problematic release.


This version of llama-cloud might be problematic. Click here for more details.

Files changed (27) hide show
  1. llama_cloud/__init__.py +4 -16
  2. llama_cloud/client.py +0 -3
  3. llama_cloud/resources/__init__.py +0 -5
  4. llama_cloud/resources/files/client.py +34 -6
  5. llama_cloud/resources/llama_extract/client.py +126 -424
  6. llama_cloud/resources/parsing/client.py +82 -18
  7. llama_cloud/types/__init__.py +4 -10
  8. llama_cloud/types/extract_job.py +3 -1
  9. llama_cloud/types/extract_resultset.py +2 -6
  10. llama_cloud/types/extract_run.py +5 -0
  11. llama_cloud/types/extract_run_data_value.py +5 -0
  12. llama_cloud/types/{extraction_schema_data_schema_value.py → extract_run_extraction_metadata_value.py} +1 -1
  13. llama_cloud/types/extract_state.py +4 -4
  14. llama_cloud/types/llama_parse_parameters.py +3 -0
  15. {llama_cloud-0.1.8.dist-info → llama_cloud-0.1.9.dist-info}/METADATA +2 -1
  16. {llama_cloud-0.1.8.dist-info → llama_cloud-0.1.9.dist-info}/RECORD +18 -26
  17. {llama_cloud-0.1.8.dist-info → llama_cloud-0.1.9.dist-info}/WHEEL +1 -1
  18. llama_cloud/resources/extraction/__init__.py +0 -5
  19. llama_cloud/resources/extraction/client.py +0 -756
  20. llama_cloud/resources/extraction/types/__init__.py +0 -6
  21. llama_cloud/resources/extraction/types/extraction_schema_create_data_schema_value.py +0 -7
  22. llama_cloud/resources/extraction/types/extraction_schema_update_data_schema_value.py +0 -7
  23. llama_cloud/types/extraction_job.py +0 -35
  24. llama_cloud/types/extraction_result.py +0 -44
  25. llama_cloud/types/extraction_result_data_value.py +0 -5
  26. llama_cloud/types/extraction_schema.py +0 -41
  27. {llama_cloud-0.1.8.dist-info → llama_cloud-0.1.9.dist-info}/LICENSE +0 -0
@@ -1,756 +0,0 @@
1
- # This file was auto-generated by Fern from our API Definition.
2
-
3
- import typing
4
- import urllib.parse
5
- from json.decoder import JSONDecodeError
6
-
7
- from ...core.api_error import ApiError
8
- from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
9
- from ...core.jsonable_encoder import jsonable_encoder
10
- from ...core.remove_none_from_dict import remove_none_from_dict
11
- from ...errors.unprocessable_entity_error import UnprocessableEntityError
12
- from ...types.extraction_job import ExtractionJob
13
- from ...types.extraction_result import ExtractionResult
14
- from ...types.extraction_schema import ExtractionSchema
15
- from ...types.http_validation_error import HttpValidationError
16
- from .types.extraction_schema_create_data_schema_value import ExtractionSchemaCreateDataSchemaValue
17
- from .types.extraction_schema_update_data_schema_value import ExtractionSchemaUpdateDataSchemaValue
18
-
19
- try:
20
- import pydantic
21
- if pydantic.__version__.startswith("1."):
22
- raise ImportError
23
- import pydantic.v1 as pydantic # type: ignore
24
- except ImportError:
25
- import pydantic # type: ignore
26
-
27
- # this is used as the default value for optional parameters
28
- OMIT = typing.cast(typing.Any, ...)
29
-
30
-
31
- class ExtractionClient:
32
- def __init__(self, *, client_wrapper: SyncClientWrapper):
33
- self._client_wrapper = client_wrapper
34
-
35
- def list_schemas(self, *, project_id: typing.Optional[str] = None) -> typing.List[ExtractionSchema]:
36
- """
37
- Parameters:
38
- - project_id: typing.Optional[str].
39
- ---
40
- from llama_cloud.client import LlamaCloud
41
-
42
- client = LlamaCloud(
43
- token="YOUR_TOKEN",
44
- )
45
- client.extraction.list_schemas()
46
- """
47
- _response = self._client_wrapper.httpx_client.request(
48
- "GET",
49
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "api/v1/extraction/schemas"),
50
- params=remove_none_from_dict({"project_id": project_id}),
51
- headers=self._client_wrapper.get_headers(),
52
- timeout=60,
53
- )
54
- if 200 <= _response.status_code < 300:
55
- return pydantic.parse_obj_as(typing.List[ExtractionSchema], _response.json()) # type: ignore
56
- if _response.status_code == 422:
57
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
58
- try:
59
- _response_json = _response.json()
60
- except JSONDecodeError:
61
- raise ApiError(status_code=_response.status_code, body=_response.text)
62
- raise ApiError(status_code=_response.status_code, body=_response_json)
63
-
64
- def create_schema(
65
- self,
66
- *,
67
- name: str,
68
- project_id: typing.Optional[str] = OMIT,
69
- data_schema: typing.Dict[str, typing.Optional[ExtractionSchemaCreateDataSchemaValue]],
70
- ) -> ExtractionSchema:
71
- """
72
- Parameters:
73
- - name: str. The name of the extraction schema
74
-
75
- - project_id: typing.Optional[str].
76
-
77
- - data_schema: typing.Dict[str, typing.Optional[ExtractionSchemaCreateDataSchemaValue]]. The schema of the data
78
- ---
79
- from llama_cloud.client import LlamaCloud
80
-
81
- client = LlamaCloud(
82
- token="YOUR_TOKEN",
83
- )
84
- client.extraction.create_schema(
85
- name="string",
86
- data_schema={},
87
- )
88
- """
89
- _request: typing.Dict[str, typing.Any] = {"name": name, "data_schema": data_schema}
90
- if project_id is not OMIT:
91
- _request["project_id"] = project_id
92
- _response = self._client_wrapper.httpx_client.request(
93
- "POST",
94
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "api/v1/extraction/schemas"),
95
- json=jsonable_encoder(_request),
96
- headers=self._client_wrapper.get_headers(),
97
- timeout=60,
98
- )
99
- if 200 <= _response.status_code < 300:
100
- return pydantic.parse_obj_as(ExtractionSchema, _response.json()) # type: ignore
101
- if _response.status_code == 422:
102
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
103
- try:
104
- _response_json = _response.json()
105
- except JSONDecodeError:
106
- raise ApiError(status_code=_response.status_code, body=_response.text)
107
- raise ApiError(status_code=_response.status_code, body=_response_json)
108
-
109
- def infer_schema(
110
- self,
111
- *,
112
- schema_id: typing.Optional[str] = OMIT,
113
- name: str,
114
- project_id: typing.Optional[str] = OMIT,
115
- file_ids: typing.List[str],
116
- stream: typing.Optional[bool] = OMIT,
117
- ) -> ExtractionSchema:
118
- """
119
- Parameters:
120
- - schema_id: typing.Optional[str].
121
-
122
- - name: str. The name of the extraction schema
123
-
124
- - project_id: typing.Optional[str].
125
-
126
- - file_ids: typing.List[str]. The IDs of the files that the extraction schema contains
127
-
128
- - stream: typing.Optional[bool]. Whether to stream the results of the extraction schema
129
- ---
130
- from llama_cloud.client import LlamaCloud
131
-
132
- client = LlamaCloud(
133
- token="YOUR_TOKEN",
134
- )
135
- client.extraction.infer_schema(
136
- name="string",
137
- file_ids=[],
138
- )
139
- """
140
- _request: typing.Dict[str, typing.Any] = {"name": name, "file_ids": file_ids}
141
- if schema_id is not OMIT:
142
- _request["schema_id"] = schema_id
143
- if project_id is not OMIT:
144
- _request["project_id"] = project_id
145
- if stream is not OMIT:
146
- _request["stream"] = stream
147
- _response = self._client_wrapper.httpx_client.request(
148
- "POST",
149
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "api/v1/extraction/schemas/infer"),
150
- json=jsonable_encoder(_request),
151
- headers=self._client_wrapper.get_headers(),
152
- timeout=60,
153
- )
154
- if 200 <= _response.status_code < 300:
155
- return pydantic.parse_obj_as(ExtractionSchema, _response.json()) # type: ignore
156
- if _response.status_code == 422:
157
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
158
- try:
159
- _response_json = _response.json()
160
- except JSONDecodeError:
161
- raise ApiError(status_code=_response.status_code, body=_response.text)
162
- raise ApiError(status_code=_response.status_code, body=_response_json)
163
-
164
- def get_schema(self, schema_id: str) -> ExtractionSchema:
165
- """
166
- Parameters:
167
- - schema_id: str.
168
- ---
169
- from llama_cloud.client import LlamaCloud
170
-
171
- client = LlamaCloud(
172
- token="YOUR_TOKEN",
173
- )
174
- client.extraction.get_schema(
175
- schema_id="string",
176
- )
177
- """
178
- _response = self._client_wrapper.httpx_client.request(
179
- "GET",
180
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"api/v1/extraction/schemas/{schema_id}"),
181
- headers=self._client_wrapper.get_headers(),
182
- timeout=60,
183
- )
184
- if 200 <= _response.status_code < 300:
185
- return pydantic.parse_obj_as(ExtractionSchema, _response.json()) # type: ignore
186
- if _response.status_code == 422:
187
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
188
- try:
189
- _response_json = _response.json()
190
- except JSONDecodeError:
191
- raise ApiError(status_code=_response.status_code, body=_response.text)
192
- raise ApiError(status_code=_response.status_code, body=_response_json)
193
-
194
- def update_schema(
195
- self,
196
- schema_id: str,
197
- *,
198
- data_schema: typing.Optional[typing.Dict[str, typing.Optional[ExtractionSchemaUpdateDataSchemaValue]]] = OMIT,
199
- ) -> ExtractionSchema:
200
- """
201
- Parameters:
202
- - schema_id: str.
203
-
204
- - data_schema: typing.Optional[typing.Dict[str, typing.Optional[ExtractionSchemaUpdateDataSchemaValue]]].
205
- ---
206
- from llama_cloud.client import LlamaCloud
207
-
208
- client = LlamaCloud(
209
- token="YOUR_TOKEN",
210
- )
211
- client.extraction.update_schema(
212
- schema_id="string",
213
- )
214
- """
215
- _request: typing.Dict[str, typing.Any] = {}
216
- if data_schema is not OMIT:
217
- _request["data_schema"] = data_schema
218
- _response = self._client_wrapper.httpx_client.request(
219
- "PUT",
220
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"api/v1/extraction/schemas/{schema_id}"),
221
- json=jsonable_encoder(_request),
222
- headers=self._client_wrapper.get_headers(),
223
- timeout=60,
224
- )
225
- if 200 <= _response.status_code < 300:
226
- return pydantic.parse_obj_as(ExtractionSchema, _response.json()) # type: ignore
227
- if _response.status_code == 422:
228
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
229
- try:
230
- _response_json = _response.json()
231
- except JSONDecodeError:
232
- raise ApiError(status_code=_response.status_code, body=_response.text)
233
- raise ApiError(status_code=_response.status_code, body=_response_json)
234
-
235
- def list_jobs(self, *, schema_id: str) -> typing.List[ExtractionJob]:
236
- """
237
- Parameters:
238
- - schema_id: str.
239
- ---
240
- from llama_cloud.client import LlamaCloud
241
-
242
- client = LlamaCloud(
243
- token="YOUR_TOKEN",
244
- )
245
- client.extraction.list_jobs(
246
- schema_id="string",
247
- )
248
- """
249
- _response = self._client_wrapper.httpx_client.request(
250
- "GET",
251
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "api/v1/extraction/jobs"),
252
- params=remove_none_from_dict({"schema_id": schema_id}),
253
- headers=self._client_wrapper.get_headers(),
254
- timeout=60,
255
- )
256
- if 200 <= _response.status_code < 300:
257
- return pydantic.parse_obj_as(typing.List[ExtractionJob], _response.json()) # type: ignore
258
- if _response.status_code == 422:
259
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
260
- try:
261
- _response_json = _response.json()
262
- except JSONDecodeError:
263
- raise ApiError(status_code=_response.status_code, body=_response.text)
264
- raise ApiError(status_code=_response.status_code, body=_response_json)
265
-
266
- def run_job(self, *, schema_id: str, file_id: str) -> ExtractionJob:
267
- """
268
- Parameters:
269
- - schema_id: str. The id of the schema
270
-
271
- - file_id: str. The id of the file
272
- ---
273
- from llama_cloud.client import LlamaCloud
274
-
275
- client = LlamaCloud(
276
- token="YOUR_TOKEN",
277
- )
278
- client.extraction.run_job(
279
- schema_id="string",
280
- file_id="string",
281
- )
282
- """
283
- _response = self._client_wrapper.httpx_client.request(
284
- "POST",
285
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "api/v1/extraction/jobs"),
286
- json=jsonable_encoder({"schema_id": schema_id, "file_id": file_id}),
287
- headers=self._client_wrapper.get_headers(),
288
- timeout=60,
289
- )
290
- if 200 <= _response.status_code < 300:
291
- return pydantic.parse_obj_as(ExtractionJob, _response.json()) # type: ignore
292
- if _response.status_code == 422:
293
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
294
- try:
295
- _response_json = _response.json()
296
- except JSONDecodeError:
297
- raise ApiError(status_code=_response.status_code, body=_response.text)
298
- raise ApiError(status_code=_response.status_code, body=_response_json)
299
-
300
- def get_job(self, job_id: str) -> ExtractionJob:
301
- """
302
- Parameters:
303
- - job_id: str.
304
- ---
305
- from llama_cloud.client import LlamaCloud
306
-
307
- client = LlamaCloud(
308
- token="YOUR_TOKEN",
309
- )
310
- client.extraction.get_job(
311
- job_id="string",
312
- )
313
- """
314
- _response = self._client_wrapper.httpx_client.request(
315
- "GET",
316
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"api/v1/extraction/jobs/{job_id}"),
317
- headers=self._client_wrapper.get_headers(),
318
- timeout=60,
319
- )
320
- if 200 <= _response.status_code < 300:
321
- return pydantic.parse_obj_as(ExtractionJob, _response.json()) # type: ignore
322
- if _response.status_code == 422:
323
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
324
- try:
325
- _response_json = _response.json()
326
- except JSONDecodeError:
327
- raise ApiError(status_code=_response.status_code, body=_response.text)
328
- raise ApiError(status_code=_response.status_code, body=_response_json)
329
-
330
- def run_jobs_in_batch(self, *, schema_id: str, file_ids: typing.List[str]) -> typing.List[ExtractionJob]:
331
- """
332
- Parameters:
333
- - schema_id: str. The id of the schema
334
-
335
- - file_ids: typing.List[str]. The ids of the files
336
- ---
337
- from llama_cloud.client import LlamaCloud
338
-
339
- client = LlamaCloud(
340
- token="YOUR_TOKEN",
341
- )
342
- client.extraction.run_jobs_in_batch(
343
- schema_id="string",
344
- file_ids=[],
345
- )
346
- """
347
- _response = self._client_wrapper.httpx_client.request(
348
- "POST",
349
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "api/v1/extraction/jobs/batch"),
350
- json=jsonable_encoder({"schema_id": schema_id, "file_ids": file_ids}),
351
- headers=self._client_wrapper.get_headers(),
352
- timeout=60,
353
- )
354
- if 200 <= _response.status_code < 300:
355
- return pydantic.parse_obj_as(typing.List[ExtractionJob], _response.json()) # type: ignore
356
- if _response.status_code == 422:
357
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
358
- try:
359
- _response_json = _response.json()
360
- except JSONDecodeError:
361
- raise ApiError(status_code=_response.status_code, body=_response.text)
362
- raise ApiError(status_code=_response.status_code, body=_response_json)
363
-
364
- def get_job_result(self, job_id: str) -> ExtractionResult:
365
- """
366
- Parameters:
367
- - job_id: str.
368
- ---
369
- from llama_cloud.client import LlamaCloud
370
-
371
- client = LlamaCloud(
372
- token="YOUR_TOKEN",
373
- )
374
- client.extraction.get_job_result(
375
- job_id="string",
376
- )
377
- """
378
- _response = self._client_wrapper.httpx_client.request(
379
- "GET",
380
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"api/v1/extraction/jobs/{job_id}/result"),
381
- headers=self._client_wrapper.get_headers(),
382
- timeout=60,
383
- )
384
- if 200 <= _response.status_code < 300:
385
- return pydantic.parse_obj_as(ExtractionResult, _response.json()) # type: ignore
386
- if _response.status_code == 422:
387
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
388
- try:
389
- _response_json = _response.json()
390
- except JSONDecodeError:
391
- raise ApiError(status_code=_response.status_code, body=_response.text)
392
- raise ApiError(status_code=_response.status_code, body=_response_json)
393
-
394
-
395
- class AsyncExtractionClient:
396
- def __init__(self, *, client_wrapper: AsyncClientWrapper):
397
- self._client_wrapper = client_wrapper
398
-
399
- async def list_schemas(self, *, project_id: typing.Optional[str] = None) -> typing.List[ExtractionSchema]:
400
- """
401
- Parameters:
402
- - project_id: typing.Optional[str].
403
- ---
404
- from llama_cloud.client import AsyncLlamaCloud
405
-
406
- client = AsyncLlamaCloud(
407
- token="YOUR_TOKEN",
408
- )
409
- await client.extraction.list_schemas()
410
- """
411
- _response = await self._client_wrapper.httpx_client.request(
412
- "GET",
413
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "api/v1/extraction/schemas"),
414
- params=remove_none_from_dict({"project_id": project_id}),
415
- headers=self._client_wrapper.get_headers(),
416
- timeout=60,
417
- )
418
- if 200 <= _response.status_code < 300:
419
- return pydantic.parse_obj_as(typing.List[ExtractionSchema], _response.json()) # type: ignore
420
- if _response.status_code == 422:
421
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
422
- try:
423
- _response_json = _response.json()
424
- except JSONDecodeError:
425
- raise ApiError(status_code=_response.status_code, body=_response.text)
426
- raise ApiError(status_code=_response.status_code, body=_response_json)
427
-
428
- async def create_schema(
429
- self,
430
- *,
431
- name: str,
432
- project_id: typing.Optional[str] = OMIT,
433
- data_schema: typing.Dict[str, typing.Optional[ExtractionSchemaCreateDataSchemaValue]],
434
- ) -> ExtractionSchema:
435
- """
436
- Parameters:
437
- - name: str. The name of the extraction schema
438
-
439
- - project_id: typing.Optional[str].
440
-
441
- - data_schema: typing.Dict[str, typing.Optional[ExtractionSchemaCreateDataSchemaValue]]. The schema of the data
442
- ---
443
- from llama_cloud.client import AsyncLlamaCloud
444
-
445
- client = AsyncLlamaCloud(
446
- token="YOUR_TOKEN",
447
- )
448
- await client.extraction.create_schema(
449
- name="string",
450
- data_schema={},
451
- )
452
- """
453
- _request: typing.Dict[str, typing.Any] = {"name": name, "data_schema": data_schema}
454
- if project_id is not OMIT:
455
- _request["project_id"] = project_id
456
- _response = await self._client_wrapper.httpx_client.request(
457
- "POST",
458
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "api/v1/extraction/schemas"),
459
- json=jsonable_encoder(_request),
460
- headers=self._client_wrapper.get_headers(),
461
- timeout=60,
462
- )
463
- if 200 <= _response.status_code < 300:
464
- return pydantic.parse_obj_as(ExtractionSchema, _response.json()) # type: ignore
465
- if _response.status_code == 422:
466
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
467
- try:
468
- _response_json = _response.json()
469
- except JSONDecodeError:
470
- raise ApiError(status_code=_response.status_code, body=_response.text)
471
- raise ApiError(status_code=_response.status_code, body=_response_json)
472
-
473
- async def infer_schema(
474
- self,
475
- *,
476
- schema_id: typing.Optional[str] = OMIT,
477
- name: str,
478
- project_id: typing.Optional[str] = OMIT,
479
- file_ids: typing.List[str],
480
- stream: typing.Optional[bool] = OMIT,
481
- ) -> ExtractionSchema:
482
- """
483
- Parameters:
484
- - schema_id: typing.Optional[str].
485
-
486
- - name: str. The name of the extraction schema
487
-
488
- - project_id: typing.Optional[str].
489
-
490
- - file_ids: typing.List[str]. The IDs of the files that the extraction schema contains
491
-
492
- - stream: typing.Optional[bool]. Whether to stream the results of the extraction schema
493
- ---
494
- from llama_cloud.client import AsyncLlamaCloud
495
-
496
- client = AsyncLlamaCloud(
497
- token="YOUR_TOKEN",
498
- )
499
- await client.extraction.infer_schema(
500
- name="string",
501
- file_ids=[],
502
- )
503
- """
504
- _request: typing.Dict[str, typing.Any] = {"name": name, "file_ids": file_ids}
505
- if schema_id is not OMIT:
506
- _request["schema_id"] = schema_id
507
- if project_id is not OMIT:
508
- _request["project_id"] = project_id
509
- if stream is not OMIT:
510
- _request["stream"] = stream
511
- _response = await self._client_wrapper.httpx_client.request(
512
- "POST",
513
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "api/v1/extraction/schemas/infer"),
514
- json=jsonable_encoder(_request),
515
- headers=self._client_wrapper.get_headers(),
516
- timeout=60,
517
- )
518
- if 200 <= _response.status_code < 300:
519
- return pydantic.parse_obj_as(ExtractionSchema, _response.json()) # type: ignore
520
- if _response.status_code == 422:
521
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
522
- try:
523
- _response_json = _response.json()
524
- except JSONDecodeError:
525
- raise ApiError(status_code=_response.status_code, body=_response.text)
526
- raise ApiError(status_code=_response.status_code, body=_response_json)
527
-
528
- async def get_schema(self, schema_id: str) -> ExtractionSchema:
529
- """
530
- Parameters:
531
- - schema_id: str.
532
- ---
533
- from llama_cloud.client import AsyncLlamaCloud
534
-
535
- client = AsyncLlamaCloud(
536
- token="YOUR_TOKEN",
537
- )
538
- await client.extraction.get_schema(
539
- schema_id="string",
540
- )
541
- """
542
- _response = await self._client_wrapper.httpx_client.request(
543
- "GET",
544
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"api/v1/extraction/schemas/{schema_id}"),
545
- headers=self._client_wrapper.get_headers(),
546
- timeout=60,
547
- )
548
- if 200 <= _response.status_code < 300:
549
- return pydantic.parse_obj_as(ExtractionSchema, _response.json()) # type: ignore
550
- if _response.status_code == 422:
551
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
552
- try:
553
- _response_json = _response.json()
554
- except JSONDecodeError:
555
- raise ApiError(status_code=_response.status_code, body=_response.text)
556
- raise ApiError(status_code=_response.status_code, body=_response_json)
557
-
558
- async def update_schema(
559
- self,
560
- schema_id: str,
561
- *,
562
- data_schema: typing.Optional[typing.Dict[str, typing.Optional[ExtractionSchemaUpdateDataSchemaValue]]] = OMIT,
563
- ) -> ExtractionSchema:
564
- """
565
- Parameters:
566
- - schema_id: str.
567
-
568
- - data_schema: typing.Optional[typing.Dict[str, typing.Optional[ExtractionSchemaUpdateDataSchemaValue]]].
569
- ---
570
- from llama_cloud.client import AsyncLlamaCloud
571
-
572
- client = AsyncLlamaCloud(
573
- token="YOUR_TOKEN",
574
- )
575
- await client.extraction.update_schema(
576
- schema_id="string",
577
- )
578
- """
579
- _request: typing.Dict[str, typing.Any] = {}
580
- if data_schema is not OMIT:
581
- _request["data_schema"] = data_schema
582
- _response = await self._client_wrapper.httpx_client.request(
583
- "PUT",
584
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"api/v1/extraction/schemas/{schema_id}"),
585
- json=jsonable_encoder(_request),
586
- headers=self._client_wrapper.get_headers(),
587
- timeout=60,
588
- )
589
- if 200 <= _response.status_code < 300:
590
- return pydantic.parse_obj_as(ExtractionSchema, _response.json()) # type: ignore
591
- if _response.status_code == 422:
592
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
593
- try:
594
- _response_json = _response.json()
595
- except JSONDecodeError:
596
- raise ApiError(status_code=_response.status_code, body=_response.text)
597
- raise ApiError(status_code=_response.status_code, body=_response_json)
598
-
599
- async def list_jobs(self, *, schema_id: str) -> typing.List[ExtractionJob]:
600
- """
601
- Parameters:
602
- - schema_id: str.
603
- ---
604
- from llama_cloud.client import AsyncLlamaCloud
605
-
606
- client = AsyncLlamaCloud(
607
- token="YOUR_TOKEN",
608
- )
609
- await client.extraction.list_jobs(
610
- schema_id="string",
611
- )
612
- """
613
- _response = await self._client_wrapper.httpx_client.request(
614
- "GET",
615
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "api/v1/extraction/jobs"),
616
- params=remove_none_from_dict({"schema_id": schema_id}),
617
- headers=self._client_wrapper.get_headers(),
618
- timeout=60,
619
- )
620
- if 200 <= _response.status_code < 300:
621
- return pydantic.parse_obj_as(typing.List[ExtractionJob], _response.json()) # type: ignore
622
- if _response.status_code == 422:
623
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
624
- try:
625
- _response_json = _response.json()
626
- except JSONDecodeError:
627
- raise ApiError(status_code=_response.status_code, body=_response.text)
628
- raise ApiError(status_code=_response.status_code, body=_response_json)
629
-
630
- async def run_job(self, *, schema_id: str, file_id: str) -> ExtractionJob:
631
- """
632
- Parameters:
633
- - schema_id: str. The id of the schema
634
-
635
- - file_id: str. The id of the file
636
- ---
637
- from llama_cloud.client import AsyncLlamaCloud
638
-
639
- client = AsyncLlamaCloud(
640
- token="YOUR_TOKEN",
641
- )
642
- await client.extraction.run_job(
643
- schema_id="string",
644
- file_id="string",
645
- )
646
- """
647
- _response = await self._client_wrapper.httpx_client.request(
648
- "POST",
649
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "api/v1/extraction/jobs"),
650
- json=jsonable_encoder({"schema_id": schema_id, "file_id": file_id}),
651
- headers=self._client_wrapper.get_headers(),
652
- timeout=60,
653
- )
654
- if 200 <= _response.status_code < 300:
655
- return pydantic.parse_obj_as(ExtractionJob, _response.json()) # type: ignore
656
- if _response.status_code == 422:
657
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
658
- try:
659
- _response_json = _response.json()
660
- except JSONDecodeError:
661
- raise ApiError(status_code=_response.status_code, body=_response.text)
662
- raise ApiError(status_code=_response.status_code, body=_response_json)
663
-
664
- async def get_job(self, job_id: str) -> ExtractionJob:
665
- """
666
- Parameters:
667
- - job_id: str.
668
- ---
669
- from llama_cloud.client import AsyncLlamaCloud
670
-
671
- client = AsyncLlamaCloud(
672
- token="YOUR_TOKEN",
673
- )
674
- await client.extraction.get_job(
675
- job_id="string",
676
- )
677
- """
678
- _response = await self._client_wrapper.httpx_client.request(
679
- "GET",
680
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"api/v1/extraction/jobs/{job_id}"),
681
- headers=self._client_wrapper.get_headers(),
682
- timeout=60,
683
- )
684
- if 200 <= _response.status_code < 300:
685
- return pydantic.parse_obj_as(ExtractionJob, _response.json()) # type: ignore
686
- if _response.status_code == 422:
687
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
688
- try:
689
- _response_json = _response.json()
690
- except JSONDecodeError:
691
- raise ApiError(status_code=_response.status_code, body=_response.text)
692
- raise ApiError(status_code=_response.status_code, body=_response_json)
693
-
694
- async def run_jobs_in_batch(self, *, schema_id: str, file_ids: typing.List[str]) -> typing.List[ExtractionJob]:
695
- """
696
- Parameters:
697
- - schema_id: str. The id of the schema
698
-
699
- - file_ids: typing.List[str]. The ids of the files
700
- ---
701
- from llama_cloud.client import AsyncLlamaCloud
702
-
703
- client = AsyncLlamaCloud(
704
- token="YOUR_TOKEN",
705
- )
706
- await client.extraction.run_jobs_in_batch(
707
- schema_id="string",
708
- file_ids=[],
709
- )
710
- """
711
- _response = await self._client_wrapper.httpx_client.request(
712
- "POST",
713
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "api/v1/extraction/jobs/batch"),
714
- json=jsonable_encoder({"schema_id": schema_id, "file_ids": file_ids}),
715
- headers=self._client_wrapper.get_headers(),
716
- timeout=60,
717
- )
718
- if 200 <= _response.status_code < 300:
719
- return pydantic.parse_obj_as(typing.List[ExtractionJob], _response.json()) # type: ignore
720
- if _response.status_code == 422:
721
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
722
- try:
723
- _response_json = _response.json()
724
- except JSONDecodeError:
725
- raise ApiError(status_code=_response.status_code, body=_response.text)
726
- raise ApiError(status_code=_response.status_code, body=_response_json)
727
-
728
- async def get_job_result(self, job_id: str) -> ExtractionResult:
729
- """
730
- Parameters:
731
- - job_id: str.
732
- ---
733
- from llama_cloud.client import AsyncLlamaCloud
734
-
735
- client = AsyncLlamaCloud(
736
- token="YOUR_TOKEN",
737
- )
738
- await client.extraction.get_job_result(
739
- job_id="string",
740
- )
741
- """
742
- _response = await self._client_wrapper.httpx_client.request(
743
- "GET",
744
- urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"api/v1/extraction/jobs/{job_id}/result"),
745
- headers=self._client_wrapper.get_headers(),
746
- timeout=60,
747
- )
748
- if 200 <= _response.status_code < 300:
749
- return pydantic.parse_obj_as(ExtractionResult, _response.json()) # type: ignore
750
- if _response.status_code == 422:
751
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
752
- try:
753
- _response_json = _response.json()
754
- except JSONDecodeError:
755
- raise ApiError(status_code=_response.status_code, body=_response.text)
756
- raise ApiError(status_code=_response.status_code, body=_response_json)