athena-intelligence 0.1.124__py3-none-any.whl → 0.1.126__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.
- athena/__init__.py +3 -0
- athena/agents/client.py +88 -36
- athena/agents/drive/client.py +80 -32
- athena/agents/general/client.py +222 -91
- athena/agents/research/client.py +80 -32
- athena/agents/sql/client.py +80 -32
- athena/base_client.py +13 -11
- athena/client.py +191 -80
- athena/core/__init__.py +21 -4
- athena/core/client_wrapper.py +9 -10
- athena/core/file.py +37 -8
- athena/core/http_client.py +97 -41
- athena/core/jsonable_encoder.py +33 -31
- athena/core/pydantic_utilities.py +272 -4
- athena/core/query_encoder.py +38 -13
- athena/core/request_options.py +5 -2
- athena/core/serialization.py +272 -0
- athena/errors/internal_server_error.py +2 -3
- athena/errors/unauthorized_error.py +2 -3
- athena/errors/unprocessable_entity_error.py +2 -3
- athena/query/client.py +208 -58
- athena/tools/calendar/client.py +82 -30
- athena/tools/client.py +576 -184
- athena/tools/email/client.py +117 -43
- athena/tools/structured_data_extractor/client.py +118 -67
- athena/tools/tasks/client.py +41 -17
- athena/types/asset_node.py +14 -24
- athena/types/asset_not_found_error.py +11 -21
- athena/types/chunk.py +11 -21
- athena/types/chunk_content_item.py +21 -41
- athena/types/chunk_result.py +13 -23
- athena/types/custom_agent_response.py +12 -22
- athena/types/data_frame_request_out.py +11 -21
- athena/types/data_frame_unknown_format_error.py +11 -21
- athena/types/document_chunk.py +12 -22
- athena/types/drive_agent_response.py +12 -22
- athena/types/file_chunk_request_out.py +11 -21
- athena/types/file_too_large_error.py +11 -21
- athena/types/folder_response.py +11 -21
- athena/types/general_agent_config.py +11 -21
- athena/types/general_agent_config_enabled_tools_item.py +0 -1
- athena/types/general_agent_request.py +13 -23
- athena/types/general_agent_response.py +12 -22
- athena/types/image_url_content.py +11 -21
- athena/types/parent_folder_error.py +11 -21
- athena/types/prompt_message.py +12 -22
- athena/types/research_agent_response.py +12 -22
- athena/types/save_asset_request_out.py +11 -21
- athena/types/sql_agent_response.py +13 -23
- athena/types/structured_data_extractor_response.py +15 -25
- athena/types/text_content.py +11 -21
- athena/types/tool.py +1 -13
- athena/types/type.py +1 -21
- athena/version.py +0 -1
- {athena_intelligence-0.1.124.dist-info → athena_intelligence-0.1.126.dist-info}/METADATA +12 -4
- athena_intelligence-0.1.126.dist-info/RECORD +87 -0
- {athena_intelligence-0.1.124.dist-info → athena_intelligence-0.1.126.dist-info}/WHEEL +1 -1
- athena_intelligence-0.1.124.dist-info/RECORD +0 -86
athena/tools/email/client.py
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
# This file was auto-generated by Fern from our API Definition.
|
2
2
|
|
3
|
+
from ...core.client_wrapper import SyncClientWrapper
|
3
4
|
import typing
|
5
|
+
from ...core.request_options import RequestOptions
|
6
|
+
from ...core.pydantic_utilities import parse_obj_as
|
4
7
|
from json.decoder import JSONDecodeError
|
5
|
-
|
6
8
|
from ...core.api_error import ApiError
|
7
|
-
from ...core.client_wrapper import AsyncClientWrapper
|
8
|
-
from ...core.pydantic_utilities import pydantic_v1
|
9
|
-
from ...core.request_options import RequestOptions
|
9
|
+
from ...core.client_wrapper import AsyncClientWrapper
|
10
10
|
|
11
11
|
|
12
12
|
class EmailClient:
|
13
13
|
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
14
14
|
self._client_wrapper = client_wrapper
|
15
15
|
|
16
|
-
def create_draft(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.Any:
|
16
|
+
def create_draft(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.Optional[typing.Any]:
|
17
17
|
"""
|
18
18
|
Coming soon! Create email drafts with specified content and recipients.
|
19
19
|
|
@@ -24,12 +24,12 @@ class EmailClient:
|
|
24
24
|
|
25
25
|
Returns
|
26
26
|
-------
|
27
|
-
typing.Any
|
27
|
+
typing.Optional[typing.Any]
|
28
28
|
Successful Response
|
29
29
|
|
30
30
|
Examples
|
31
31
|
--------
|
32
|
-
from athena
|
32
|
+
from athena import Athena
|
33
33
|
|
34
34
|
client = Athena(
|
35
35
|
api_key="YOUR_API_KEY",
|
@@ -37,17 +37,25 @@ class EmailClient:
|
|
37
37
|
client.tools.email.create_draft()
|
38
38
|
"""
|
39
39
|
_response = self._client_wrapper.httpx_client.request(
|
40
|
-
"api/v0/tools/email/draft",
|
40
|
+
"api/v0/tools/email/draft",
|
41
|
+
method="POST",
|
42
|
+
request_options=request_options,
|
41
43
|
)
|
42
|
-
if 200 <= _response.status_code < 300:
|
43
|
-
return pydantic_v1.parse_obj_as(typing.Any, _response.json()) # type: ignore
|
44
44
|
try:
|
45
|
+
if 200 <= _response.status_code < 300:
|
46
|
+
return typing.cast(
|
47
|
+
typing.Optional[typing.Any],
|
48
|
+
parse_obj_as(
|
49
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
50
|
+
object_=_response.json(),
|
51
|
+
),
|
52
|
+
)
|
45
53
|
_response_json = _response.json()
|
46
54
|
except JSONDecodeError:
|
47
55
|
raise ApiError(status_code=_response.status_code, body=_response.text)
|
48
56
|
raise ApiError(status_code=_response.status_code, body=_response_json)
|
49
57
|
|
50
|
-
def search(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.Any:
|
58
|
+
def search(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.Optional[typing.Any]:
|
51
59
|
"""
|
52
60
|
Coming soon! Search through emails with configurable filters.
|
53
61
|
|
@@ -58,12 +66,12 @@ class EmailClient:
|
|
58
66
|
|
59
67
|
Returns
|
60
68
|
-------
|
61
|
-
typing.Any
|
69
|
+
typing.Optional[typing.Any]
|
62
70
|
Successful Response
|
63
71
|
|
64
72
|
Examples
|
65
73
|
--------
|
66
|
-
from athena
|
74
|
+
from athena import Athena
|
67
75
|
|
68
76
|
client = Athena(
|
69
77
|
api_key="YOUR_API_KEY",
|
@@ -71,17 +79,25 @@ class EmailClient:
|
|
71
79
|
client.tools.email.search()
|
72
80
|
"""
|
73
81
|
_response = self._client_wrapper.httpx_client.request(
|
74
|
-
"api/v0/tools/email/search",
|
82
|
+
"api/v0/tools/email/search",
|
83
|
+
method="GET",
|
84
|
+
request_options=request_options,
|
75
85
|
)
|
76
|
-
if 200 <= _response.status_code < 300:
|
77
|
-
return pydantic_v1.parse_obj_as(typing.Any, _response.json()) # type: ignore
|
78
86
|
try:
|
87
|
+
if 200 <= _response.status_code < 300:
|
88
|
+
return typing.cast(
|
89
|
+
typing.Optional[typing.Any],
|
90
|
+
parse_obj_as(
|
91
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
92
|
+
object_=_response.json(),
|
93
|
+
),
|
94
|
+
)
|
79
95
|
_response_json = _response.json()
|
80
96
|
except JSONDecodeError:
|
81
97
|
raise ApiError(status_code=_response.status_code, body=_response.text)
|
82
98
|
raise ApiError(status_code=_response.status_code, body=_response_json)
|
83
99
|
|
84
|
-
def send(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.Any:
|
100
|
+
def send(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.Optional[typing.Any]:
|
85
101
|
"""
|
86
102
|
Coming soon! Send emails to specified recipients.
|
87
103
|
|
@@ -92,12 +108,12 @@ class EmailClient:
|
|
92
108
|
|
93
109
|
Returns
|
94
110
|
-------
|
95
|
-
typing.Any
|
111
|
+
typing.Optional[typing.Any]
|
96
112
|
Successful Response
|
97
113
|
|
98
114
|
Examples
|
99
115
|
--------
|
100
|
-
from athena
|
116
|
+
from athena import Athena
|
101
117
|
|
102
118
|
client = Athena(
|
103
119
|
api_key="YOUR_API_KEY",
|
@@ -105,11 +121,19 @@ class EmailClient:
|
|
105
121
|
client.tools.email.send()
|
106
122
|
"""
|
107
123
|
_response = self._client_wrapper.httpx_client.request(
|
108
|
-
"api/v0/tools/email/send",
|
124
|
+
"api/v0/tools/email/send",
|
125
|
+
method="POST",
|
126
|
+
request_options=request_options,
|
109
127
|
)
|
110
|
-
if 200 <= _response.status_code < 300:
|
111
|
-
return pydantic_v1.parse_obj_as(typing.Any, _response.json()) # type: ignore
|
112
128
|
try:
|
129
|
+
if 200 <= _response.status_code < 300:
|
130
|
+
return typing.cast(
|
131
|
+
typing.Optional[typing.Any],
|
132
|
+
parse_obj_as(
|
133
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
134
|
+
object_=_response.json(),
|
135
|
+
),
|
136
|
+
)
|
113
137
|
_response_json = _response.json()
|
114
138
|
except JSONDecodeError:
|
115
139
|
raise ApiError(status_code=_response.status_code, body=_response.text)
|
@@ -120,7 +144,9 @@ class AsyncEmailClient:
|
|
120
144
|
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
121
145
|
self._client_wrapper = client_wrapper
|
122
146
|
|
123
|
-
async def create_draft(
|
147
|
+
async def create_draft(
|
148
|
+
self, *, request_options: typing.Optional[RequestOptions] = None
|
149
|
+
) -> typing.Optional[typing.Any]:
|
124
150
|
"""
|
125
151
|
Coming soon! Create email drafts with specified content and recipients.
|
126
152
|
|
@@ -131,30 +157,46 @@ class AsyncEmailClient:
|
|
131
157
|
|
132
158
|
Returns
|
133
159
|
-------
|
134
|
-
typing.Any
|
160
|
+
typing.Optional[typing.Any]
|
135
161
|
Successful Response
|
136
162
|
|
137
163
|
Examples
|
138
164
|
--------
|
139
|
-
|
165
|
+
import asyncio
|
166
|
+
|
167
|
+
from athena import AsyncAthena
|
140
168
|
|
141
169
|
client = AsyncAthena(
|
142
170
|
api_key="YOUR_API_KEY",
|
143
171
|
)
|
144
|
-
|
172
|
+
|
173
|
+
|
174
|
+
async def main() -> None:
|
175
|
+
await client.tools.email.create_draft()
|
176
|
+
|
177
|
+
|
178
|
+
asyncio.run(main())
|
145
179
|
"""
|
146
180
|
_response = await self._client_wrapper.httpx_client.request(
|
147
|
-
"api/v0/tools/email/draft",
|
181
|
+
"api/v0/tools/email/draft",
|
182
|
+
method="POST",
|
183
|
+
request_options=request_options,
|
148
184
|
)
|
149
|
-
if 200 <= _response.status_code < 300:
|
150
|
-
return pydantic_v1.parse_obj_as(typing.Any, _response.json()) # type: ignore
|
151
185
|
try:
|
186
|
+
if 200 <= _response.status_code < 300:
|
187
|
+
return typing.cast(
|
188
|
+
typing.Optional[typing.Any],
|
189
|
+
parse_obj_as(
|
190
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
191
|
+
object_=_response.json(),
|
192
|
+
),
|
193
|
+
)
|
152
194
|
_response_json = _response.json()
|
153
195
|
except JSONDecodeError:
|
154
196
|
raise ApiError(status_code=_response.status_code, body=_response.text)
|
155
197
|
raise ApiError(status_code=_response.status_code, body=_response_json)
|
156
198
|
|
157
|
-
async def search(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.Any:
|
199
|
+
async def search(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.Optional[typing.Any]:
|
158
200
|
"""
|
159
201
|
Coming soon! Search through emails with configurable filters.
|
160
202
|
|
@@ -165,30 +207,46 @@ class AsyncEmailClient:
|
|
165
207
|
|
166
208
|
Returns
|
167
209
|
-------
|
168
|
-
typing.Any
|
210
|
+
typing.Optional[typing.Any]
|
169
211
|
Successful Response
|
170
212
|
|
171
213
|
Examples
|
172
214
|
--------
|
173
|
-
|
215
|
+
import asyncio
|
216
|
+
|
217
|
+
from athena import AsyncAthena
|
174
218
|
|
175
219
|
client = AsyncAthena(
|
176
220
|
api_key="YOUR_API_KEY",
|
177
221
|
)
|
178
|
-
|
222
|
+
|
223
|
+
|
224
|
+
async def main() -> None:
|
225
|
+
await client.tools.email.search()
|
226
|
+
|
227
|
+
|
228
|
+
asyncio.run(main())
|
179
229
|
"""
|
180
230
|
_response = await self._client_wrapper.httpx_client.request(
|
181
|
-
"api/v0/tools/email/search",
|
231
|
+
"api/v0/tools/email/search",
|
232
|
+
method="GET",
|
233
|
+
request_options=request_options,
|
182
234
|
)
|
183
|
-
if 200 <= _response.status_code < 300:
|
184
|
-
return pydantic_v1.parse_obj_as(typing.Any, _response.json()) # type: ignore
|
185
235
|
try:
|
236
|
+
if 200 <= _response.status_code < 300:
|
237
|
+
return typing.cast(
|
238
|
+
typing.Optional[typing.Any],
|
239
|
+
parse_obj_as(
|
240
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
241
|
+
object_=_response.json(),
|
242
|
+
),
|
243
|
+
)
|
186
244
|
_response_json = _response.json()
|
187
245
|
except JSONDecodeError:
|
188
246
|
raise ApiError(status_code=_response.status_code, body=_response.text)
|
189
247
|
raise ApiError(status_code=_response.status_code, body=_response_json)
|
190
248
|
|
191
|
-
async def send(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.Any:
|
249
|
+
async def send(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.Optional[typing.Any]:
|
192
250
|
"""
|
193
251
|
Coming soon! Send emails to specified recipients.
|
194
252
|
|
@@ -199,24 +257,40 @@ class AsyncEmailClient:
|
|
199
257
|
|
200
258
|
Returns
|
201
259
|
-------
|
202
|
-
typing.Any
|
260
|
+
typing.Optional[typing.Any]
|
203
261
|
Successful Response
|
204
262
|
|
205
263
|
Examples
|
206
264
|
--------
|
207
|
-
|
265
|
+
import asyncio
|
266
|
+
|
267
|
+
from athena import AsyncAthena
|
208
268
|
|
209
269
|
client = AsyncAthena(
|
210
270
|
api_key="YOUR_API_KEY",
|
211
271
|
)
|
212
|
-
|
272
|
+
|
273
|
+
|
274
|
+
async def main() -> None:
|
275
|
+
await client.tools.email.send()
|
276
|
+
|
277
|
+
|
278
|
+
asyncio.run(main())
|
213
279
|
"""
|
214
280
|
_response = await self._client_wrapper.httpx_client.request(
|
215
|
-
"api/v0/tools/email/send",
|
281
|
+
"api/v0/tools/email/send",
|
282
|
+
method="POST",
|
283
|
+
request_options=request_options,
|
216
284
|
)
|
217
|
-
if 200 <= _response.status_code < 300:
|
218
|
-
return pydantic_v1.parse_obj_as(typing.Any, _response.json()) # type: ignore
|
219
285
|
try:
|
286
|
+
if 200 <= _response.status_code < 300:
|
287
|
+
return typing.cast(
|
288
|
+
typing.Optional[typing.Any],
|
289
|
+
parse_obj_as(
|
290
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
291
|
+
object_=_response.json(),
|
292
|
+
),
|
293
|
+
)
|
220
294
|
_response_json = _response.json()
|
221
295
|
except JSONDecodeError:
|
222
296
|
raise ApiError(status_code=_response.status_code, body=_response.text)
|
@@ -1,16 +1,17 @@
|
|
1
1
|
# This file was auto-generated by Fern from our API Definition.
|
2
2
|
|
3
3
|
import typing
|
4
|
-
from
|
5
|
-
|
6
|
-
from ...core.api_error import ApiError
|
7
|
-
from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
8
|
-
from ...core.pydantic_utilities import pydantic_v1
|
9
|
-
from ...core.request_options import RequestOptions
|
10
|
-
from ...errors.unprocessable_entity_error import UnprocessableEntityError
|
4
|
+
from ...core.client_wrapper import SyncClientWrapper
|
11
5
|
from ...types.chunk import Chunk
|
12
6
|
from ...types.prompt_message import PromptMessage
|
7
|
+
from ...core.request_options import RequestOptions
|
13
8
|
from ...types.structured_data_extractor_response import StructuredDataExtractorResponse
|
9
|
+
from ...core.serialization import convert_and_respect_annotation_metadata
|
10
|
+
from ...core.pydantic_utilities import parse_obj_as
|
11
|
+
from ...errors.unprocessable_entity_error import UnprocessableEntityError
|
12
|
+
from json.decoder import JSONDecodeError
|
13
|
+
from ...core.api_error import ApiError
|
14
|
+
from ...core.client_wrapper import AsyncClientWrapper
|
14
15
|
|
15
16
|
# this is used as the default value for optional parameters
|
16
17
|
OMIT = typing.cast(typing.Any, ...)
|
@@ -24,17 +25,16 @@ class StructuredDataExtractorClient:
|
|
24
25
|
self,
|
25
26
|
*,
|
26
27
|
chunks: typing.Sequence[Chunk],
|
27
|
-
json_schema: typing.Dict[str, typing.Any],
|
28
|
+
json_schema: typing.Dict[str, typing.Optional[typing.Any]],
|
28
29
|
chunk_messages: typing.Optional[typing.Sequence[PromptMessage]] = OMIT,
|
29
30
|
reduce: typing.Optional[bool] = OMIT,
|
30
31
|
reduce_messages: typing.Optional[typing.Sequence[PromptMessage]] = OMIT,
|
31
|
-
request_options: typing.Optional[RequestOptions] = None
|
32
|
+
request_options: typing.Optional[RequestOptions] = None,
|
32
33
|
) -> StructuredDataExtractorResponse:
|
33
34
|
"""
|
34
35
|
Extract structured data.
|
35
36
|
|
36
37
|
tl;dr:
|
37
|
-
|
38
38
|
- pass a valid JSON schema in `json_schema`
|
39
39
|
- pass the page chunks as a list of `Chunk` objects, by default: `{"type": "text", "content": "..."}`
|
40
40
|
- leave all other fields as default
|
@@ -49,8 +49,8 @@ class StructuredDataExtractorClient:
|
|
49
49
|
|
50
50
|
- map (if your input asset is small enough)
|
51
51
|
- reduce (if your output object is large enough that it will overflow the output length;
|
52
|
-
|
53
|
-
|
52
|
+
if you're extracting a long list of entities; if youre )
|
53
|
+
to extract all instances of the schema).
|
54
54
|
|
55
55
|
You can configure these behaviors with the `map` and `reduce` fields.
|
56
56
|
|
@@ -59,7 +59,7 @@ class StructuredDataExtractorClient:
|
|
59
59
|
chunks : typing.Sequence[Chunk]
|
60
60
|
The chunks from which to extract structured data.
|
61
61
|
|
62
|
-
json_schema : typing.Dict[str, typing.Any]
|
62
|
+
json_schema : typing.Dict[str, typing.Optional[typing.Any]]
|
63
63
|
The JSON schema to use for validation (version draft 2020-12). See the docs [here](https://json-schema.org/learn/getting-started-step-by-step).
|
64
64
|
|
65
65
|
chunk_messages : typing.Optional[typing.Sequence[PromptMessage]]
|
@@ -81,8 +81,7 @@ class StructuredDataExtractorClient:
|
|
81
81
|
|
82
82
|
Examples
|
83
83
|
--------
|
84
|
-
from athena import Chunk, ChunkContentItem_Text
|
85
|
-
from athena.client import Athena
|
84
|
+
from athena import Athena, Chunk, ChunkContentItem_Text
|
86
85
|
|
87
86
|
client = Athena(
|
88
87
|
api_key="YOUR_API_KEY",
|
@@ -123,20 +122,43 @@ class StructuredDataExtractorClient:
|
|
123
122
|
"api/v0/tools/structured-data-extractor/invoke",
|
124
123
|
method="POST",
|
125
124
|
json={
|
126
|
-
"chunk_messages":
|
127
|
-
|
125
|
+
"chunk_messages": convert_and_respect_annotation_metadata(
|
126
|
+
object_=chunk_messages, annotation=typing.Sequence[PromptMessage], direction="write"
|
127
|
+
),
|
128
|
+
"chunks": convert_and_respect_annotation_metadata(
|
129
|
+
object_=chunks, annotation=typing.Sequence[Chunk], direction="write"
|
130
|
+
),
|
128
131
|
"json_schema": json_schema,
|
129
132
|
"reduce": reduce,
|
130
|
-
"reduce_messages":
|
133
|
+
"reduce_messages": convert_and_respect_annotation_metadata(
|
134
|
+
object_=reduce_messages, annotation=typing.Sequence[PromptMessage], direction="write"
|
135
|
+
),
|
136
|
+
},
|
137
|
+
headers={
|
138
|
+
"content-type": "application/json",
|
131
139
|
},
|
132
140
|
request_options=request_options,
|
133
141
|
omit=OMIT,
|
134
142
|
)
|
135
|
-
if 200 <= _response.status_code < 300:
|
136
|
-
return pydantic_v1.parse_obj_as(StructuredDataExtractorResponse, _response.json()) # type: ignore
|
137
|
-
if _response.status_code == 422:
|
138
|
-
raise UnprocessableEntityError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore
|
139
143
|
try:
|
144
|
+
if 200 <= _response.status_code < 300:
|
145
|
+
return typing.cast(
|
146
|
+
StructuredDataExtractorResponse,
|
147
|
+
parse_obj_as(
|
148
|
+
type_=StructuredDataExtractorResponse, # type: ignore
|
149
|
+
object_=_response.json(),
|
150
|
+
),
|
151
|
+
)
|
152
|
+
if _response.status_code == 422:
|
153
|
+
raise UnprocessableEntityError(
|
154
|
+
typing.cast(
|
155
|
+
typing.Optional[typing.Any],
|
156
|
+
parse_obj_as(
|
157
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
158
|
+
object_=_response.json(),
|
159
|
+
),
|
160
|
+
)
|
161
|
+
)
|
140
162
|
_response_json = _response.json()
|
141
163
|
except JSONDecodeError:
|
142
164
|
raise ApiError(status_code=_response.status_code, body=_response.text)
|
@@ -151,17 +173,16 @@ class AsyncStructuredDataExtractorClient:
|
|
151
173
|
self,
|
152
174
|
*,
|
153
175
|
chunks: typing.Sequence[Chunk],
|
154
|
-
json_schema: typing.Dict[str, typing.Any],
|
176
|
+
json_schema: typing.Dict[str, typing.Optional[typing.Any]],
|
155
177
|
chunk_messages: typing.Optional[typing.Sequence[PromptMessage]] = OMIT,
|
156
178
|
reduce: typing.Optional[bool] = OMIT,
|
157
179
|
reduce_messages: typing.Optional[typing.Sequence[PromptMessage]] = OMIT,
|
158
|
-
request_options: typing.Optional[RequestOptions] = None
|
180
|
+
request_options: typing.Optional[RequestOptions] = None,
|
159
181
|
) -> StructuredDataExtractorResponse:
|
160
182
|
"""
|
161
183
|
Extract structured data.
|
162
184
|
|
163
185
|
tl;dr:
|
164
|
-
|
165
186
|
- pass a valid JSON schema in `json_schema`
|
166
187
|
- pass the page chunks as a list of `Chunk` objects, by default: `{"type": "text", "content": "..."}`
|
167
188
|
- leave all other fields as default
|
@@ -176,8 +197,8 @@ class AsyncStructuredDataExtractorClient:
|
|
176
197
|
|
177
198
|
- map (if your input asset is small enough)
|
178
199
|
- reduce (if your output object is large enough that it will overflow the output length;
|
179
|
-
|
180
|
-
|
200
|
+
if you're extracting a long list of entities; if youre )
|
201
|
+
to extract all instances of the schema).
|
181
202
|
|
182
203
|
You can configure these behaviors with the `map` and `reduce` fields.
|
183
204
|
|
@@ -186,7 +207,7 @@ class AsyncStructuredDataExtractorClient:
|
|
186
207
|
chunks : typing.Sequence[Chunk]
|
187
208
|
The chunks from which to extract structured data.
|
188
209
|
|
189
|
-
json_schema : typing.Dict[str, typing.Any]
|
210
|
+
json_schema : typing.Dict[str, typing.Optional[typing.Any]]
|
190
211
|
The JSON schema to use for validation (version draft 2020-12). See the docs [here](https://json-schema.org/learn/getting-started-step-by-step).
|
191
212
|
|
192
213
|
chunk_messages : typing.Optional[typing.Sequence[PromptMessage]]
|
@@ -208,62 +229,92 @@ class AsyncStructuredDataExtractorClient:
|
|
208
229
|
|
209
230
|
Examples
|
210
231
|
--------
|
211
|
-
|
212
|
-
|
232
|
+
import asyncio
|
233
|
+
|
234
|
+
from athena import AsyncAthena, Chunk, ChunkContentItem_Text
|
213
235
|
|
214
236
|
client = AsyncAthena(
|
215
237
|
api_key="YOUR_API_KEY",
|
216
238
|
)
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
"
|
241
|
-
"
|
239
|
+
|
240
|
+
|
241
|
+
async def main() -> None:
|
242
|
+
await client.tools.structured_data_extractor.invoke(
|
243
|
+
chunks=[
|
244
|
+
Chunk(
|
245
|
+
chunk_id="1",
|
246
|
+
content=[
|
247
|
+
ChunkContentItem_Text(
|
248
|
+
text="John Smith is a 35 year old developer. You can reach him at john.smith@example.com",
|
249
|
+
)
|
250
|
+
],
|
251
|
+
),
|
252
|
+
Chunk(
|
253
|
+
chunk_id="2",
|
254
|
+
content=[
|
255
|
+
ChunkContentItem_Text(
|
256
|
+
text="Jane Doe is a 25 year old developer. You can reach her at jane@example.com",
|
257
|
+
)
|
258
|
+
],
|
259
|
+
),
|
260
|
+
],
|
261
|
+
json_schema={
|
262
|
+
"description": "A person",
|
263
|
+
"properties": {
|
264
|
+
"age": {"type": "integer"},
|
265
|
+
"email": {"type": "string"},
|
266
|
+
"name": {"type": "string"},
|
267
|
+
},
|
268
|
+
"required": ["name"],
|
269
|
+
"title": "Person",
|
270
|
+
"type": "object",
|
242
271
|
},
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
)
|
272
|
+
)
|
273
|
+
|
274
|
+
|
275
|
+
asyncio.run(main())
|
248
276
|
"""
|
249
277
|
_response = await self._client_wrapper.httpx_client.request(
|
250
278
|
"api/v0/tools/structured-data-extractor/invoke",
|
251
279
|
method="POST",
|
252
280
|
json={
|
253
|
-
"chunk_messages":
|
254
|
-
|
281
|
+
"chunk_messages": convert_and_respect_annotation_metadata(
|
282
|
+
object_=chunk_messages, annotation=typing.Sequence[PromptMessage], direction="write"
|
283
|
+
),
|
284
|
+
"chunks": convert_and_respect_annotation_metadata(
|
285
|
+
object_=chunks, annotation=typing.Sequence[Chunk], direction="write"
|
286
|
+
),
|
255
287
|
"json_schema": json_schema,
|
256
288
|
"reduce": reduce,
|
257
|
-
"reduce_messages":
|
289
|
+
"reduce_messages": convert_and_respect_annotation_metadata(
|
290
|
+
object_=reduce_messages, annotation=typing.Sequence[PromptMessage], direction="write"
|
291
|
+
),
|
292
|
+
},
|
293
|
+
headers={
|
294
|
+
"content-type": "application/json",
|
258
295
|
},
|
259
296
|
request_options=request_options,
|
260
297
|
omit=OMIT,
|
261
298
|
)
|
262
|
-
if 200 <= _response.status_code < 300:
|
263
|
-
return pydantic_v1.parse_obj_as(StructuredDataExtractorResponse, _response.json()) # type: ignore
|
264
|
-
if _response.status_code == 422:
|
265
|
-
raise UnprocessableEntityError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore
|
266
299
|
try:
|
300
|
+
if 200 <= _response.status_code < 300:
|
301
|
+
return typing.cast(
|
302
|
+
StructuredDataExtractorResponse,
|
303
|
+
parse_obj_as(
|
304
|
+
type_=StructuredDataExtractorResponse, # type: ignore
|
305
|
+
object_=_response.json(),
|
306
|
+
),
|
307
|
+
)
|
308
|
+
if _response.status_code == 422:
|
309
|
+
raise UnprocessableEntityError(
|
310
|
+
typing.cast(
|
311
|
+
typing.Optional[typing.Any],
|
312
|
+
parse_obj_as(
|
313
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
314
|
+
object_=_response.json(),
|
315
|
+
),
|
316
|
+
)
|
317
|
+
)
|
267
318
|
_response_json = _response.json()
|
268
319
|
except JSONDecodeError:
|
269
320
|
raise ApiError(status_code=_response.status_code, body=_response.text)
|