Skip to content

Commit 3943af2

Browse files
box-sdk-buildbox-sdk-build
andauthored
feat(boxsdkgen): Add new parameters to ai extract structured method (box/box-openapi#604) (#1479)
Co-authored-by: box-sdk-build <box-sdk-build@box.com>
1 parent edf938e commit 3943af2

15 files changed

Lines changed: 262 additions & 21 deletions

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "a87c352", "specHash": "ded99bf", "version": "4.11.0" }
1+
{ "engineHash": "a87c352", "specHash": "0ac3d31", "version": "4.11.0" }

box_sdk_gen/managers/ai.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
from box_sdk_gen.serialization.json import deserialize
1616

17+
from box_sdk_gen.schemas.ai_extract_sub_field import AiExtractSubField
18+
19+
from box_sdk_gen.schemas.ai_options_rules import AiOptionsRules
20+
1721
from box_sdk_gen.schemas.ai_item_ask import AiItemAsk
1822

1923
from box_sdk_gen.schemas.ai_dialogue_history import AiDialogueHistory
@@ -40,6 +44,12 @@
4044

4145
from box_sdk_gen.schemas.ai_extract_structured_agent import AiExtractStructuredAgent
4246

47+
from box_sdk_gen.schemas.ai_taxonomy_reference import AiTaxonomyReference
48+
49+
from box_sdk_gen.schemas.ai_taxonomy_file_reference import AiTaxonomyFileReference
50+
51+
from box_sdk_gen.schemas.ai_taxonomy_source import AiTaxonomySource
52+
4353
from box_sdk_gen.schemas.ai_response_full import AiResponseFull
4454

4555
from box_sdk_gen.schemas.client_error import ClientError
@@ -185,6 +195,10 @@ def __init__(
185195
prompt: Optional[str] = None,
186196
type: Optional[str] = None,
187197
options: Optional[List[CreateAiExtractStructuredFieldsOptionsField]] = None,
198+
fields: Optional[List[AiExtractSubField]] = None,
199+
taxonomy_key: Optional[str] = None,
200+
namespace: Optional[str] = None,
201+
options_rules: Optional[AiOptionsRules] = None,
188202
**kwargs
189203
):
190204
"""
@@ -196,10 +210,16 @@ def __init__(
196210
:type display_name: Optional[str], optional
197211
:param prompt: The context about the key that may include how to find and format it., defaults to None
198212
:type prompt: Optional[str], optional
199-
:param type: The type of the field. It can include but is not limited to `string`, `float`, `date`, `enum`, and `multiSelect`., defaults to None
213+
:param type: The type of the field. It can include but is not limited to `string`, `float`, `date`, `enum`, `multiSelect`,`taxonomy`, `struct`, and `table`., defaults to None
200214
:type type: Optional[str], optional
201215
:param options: A list of options for this field. This is most often used in combination with the `enum` and `multiSelect` field types., defaults to None
202216
:type options: Optional[List[CreateAiExtractStructuredFieldsOptionsField]], optional
217+
:param fields: The nested fields for this field. Used with `struct` and `table` field types to define the nested structure., defaults to None
218+
:type fields: Optional[List[AiExtractSubField]], optional
219+
:param taxonomy_key: The identifier for a taxonomy, which corresponds to the `key` of the taxonomy source. Required if using `taxonomy` type field., defaults to None
220+
:type taxonomy_key: Optional[str], optional
221+
:param namespace: The namespace of the taxonomy source. Required if using `taxonomy` type field from an existing taxonomy., defaults to None
222+
:type namespace: Optional[str], optional
203223
"""
204224
super().__init__(**kwargs)
205225
self.key = key
@@ -208,6 +228,10 @@ def __init__(
208228
self.prompt = prompt
209229
self.type = type
210230
self.options = options
231+
self.fields = fields
232+
self.taxonomy_key = taxonomy_key
233+
self.namespace = namespace
234+
self.options_rules = options_rules
211235

212236

213237
class AiManager:
@@ -428,6 +452,7 @@ def create_ai_extract_structured(
428452
ai_agent: Optional[AiExtractStructuredAgent] = None,
429453
include_confidence_score: Optional[bool] = None,
430454
include_reference: Optional[bool] = None,
455+
taxonomy_sources: Optional[List[AiTaxonomySource]] = None,
431456
extra_headers: Optional[Dict[str, Optional[str]]] = None
432457
) -> AiExtractStructuredResponse:
433458
"""
@@ -456,6 +481,9 @@ def create_ai_extract_structured(
456481
:type include_confidence_score: Optional[bool], optional
457482
:param include_reference: A flag to indicate whether references for every extracted field should be returned., defaults to None
458483
:type include_reference: Optional[bool], optional
484+
:param taxonomy_sources: The taxonomy sources to be used for the structured extraction. They can either be an existing file or a taxonomy.
485+
For your request to work, `fields` must also be provided. `taxonomy_sources` is not supported with `metadata_template`., defaults to None
486+
:type taxonomy_sources: Optional[List[AiTaxonomySource]], optional
459487
:param extra_headers: Extra headers that will be included in the HTTP request., defaults to None
460488
:type extra_headers: Optional[Dict[str, Optional[str]]], optional
461489
"""
@@ -468,6 +496,7 @@ def create_ai_extract_structured(
468496
'ai_agent': ai_agent,
469497
'include_confidence_score': include_confidence_score,
470498
'include_reference': include_reference,
499+
'taxonomy_sources': taxonomy_sources,
471500
}
472501
headers_map: Dict[str, str] = prepare_params({**extra_headers})
473502
response: FetchResponse = self.network_session.network_client.fetch(

box_sdk_gen/managers/user_collaborations.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,19 +350,13 @@ def create_collaboration(
350350
this endpoint is dependent on the group's ability to be invited.
351351
352352
353-
If collaboration is in `pending` status, the following fields
353+
If collaboration is in `pending` status, field `name` is redacted when:
354354
355355
356-
are redacted:
356+
- a collaboration was created using `user_id`,
357357
358358
359-
- `login` and `name` are hidden if a collaboration was created
360-
361-
362-
using `user_id`,
363-
364-
365-
- `name` is hidden if a collaboration was created using `login`.
359+
- a collaboration was created using `login`.
366360
367361
:param item: The item to attach the comment to.
368362
:type item: CreateCollaborationItem

box_sdk_gen/schemas/__init__.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
from box_sdk_gen.schemas.ai_dialogue_history import *
1212

13+
from box_sdk_gen.schemas.ai_extract_field_option import *
14+
15+
from box_sdk_gen.schemas.ai_extract_sub_field import *
16+
1317
from box_sdk_gen.schemas.ai_extract_structured_response import *
1418

1519
from box_sdk_gen.schemas.ai_item_base import *
@@ -78,8 +82,6 @@
7882

7983
from box_sdk_gen.schemas.ai_extract_structured_agent import *
8084

81-
from box_sdk_gen.schemas.ai_extract_structured import *
82-
8385
from box_sdk_gen.schemas.ai_agent_extract import *
8486

8587
from box_sdk_gen.schemas.ai_extract_agent import *
@@ -94,6 +96,16 @@
9496

9597
from box_sdk_gen.schemas.ai_agent import *
9698

99+
from box_sdk_gen.schemas.ai_options_rules import *
100+
101+
from box_sdk_gen.schemas.ai_taxonomy_file_reference import *
102+
103+
from box_sdk_gen.schemas.ai_taxonomy_reference import *
104+
105+
from box_sdk_gen.schemas.ai_taxonomy_source import *
106+
107+
from box_sdk_gen.schemas.ai_extract_structured import *
108+
97109
from box_sdk_gen.schemas.app_item import *
98110

99111
from box_sdk_gen.schemas.classification import *
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from box_sdk_gen.internal.base_object import BaseObject
2+
3+
from box_sdk_gen.box.errors import BoxSDKError
4+
5+
6+
class AiExtractFieldOption(BaseObject):
7+
def __init__(self, key: str, **kwargs):
8+
"""
9+
:param key: A unique identifier for the option.
10+
:type key: str
11+
"""
12+
super().__init__(**kwargs)
13+
self.key = key

box_sdk_gen/schemas/ai_extract_structured.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,20 @@
1212

1313
from box_sdk_gen.schemas.ai_agent_extract_structured import AiAgentExtractStructured
1414

15+
from box_sdk_gen.schemas.ai_taxonomy_reference import AiTaxonomyReference
16+
17+
from box_sdk_gen.schemas.ai_taxonomy_file_reference import AiTaxonomyFileReference
18+
1519
from box_sdk_gen.schemas.ai_item_base import AiItemBase
1620

21+
from box_sdk_gen.schemas.ai_extract_sub_field import AiExtractSubField
22+
23+
from box_sdk_gen.schemas.ai_options_rules import AiOptionsRules
24+
1725
from box_sdk_gen.schemas.ai_extract_structured_agent import AiExtractStructuredAgent
1826

27+
from box_sdk_gen.schemas.ai_taxonomy_source import AiTaxonomySource
28+
1929
from box_sdk_gen.box.errors import BoxSDKError
2030

2131

@@ -82,6 +92,10 @@ def __init__(
8292
prompt: Optional[str] = None,
8393
type: Optional[str] = None,
8494
options: Optional[List[AiExtractStructuredFieldsOptionsField]] = None,
95+
fields: Optional[List[AiExtractSubField]] = None,
96+
taxonomy_key: Optional[str] = None,
97+
namespace: Optional[str] = None,
98+
options_rules: Optional[AiOptionsRules] = None,
8599
**kwargs
86100
):
87101
"""
@@ -93,10 +107,16 @@ def __init__(
93107
:type display_name: Optional[str], optional
94108
:param prompt: The context about the key that may include how to find and format it., defaults to None
95109
:type prompt: Optional[str], optional
96-
:param type: The type of the field. It can include but is not limited to `string`, `float`, `date`, `enum`, and `multiSelect`., defaults to None
110+
:param type: The type of the field. It can include but is not limited to `string`, `float`, `date`, `enum`, `multiSelect`,`taxonomy`, `struct`, and `table`., defaults to None
97111
:type type: Optional[str], optional
98112
:param options: A list of options for this field. This is most often used in combination with the `enum` and `multiSelect` field types., defaults to None
99113
:type options: Optional[List[AiExtractStructuredFieldsOptionsField]], optional
114+
:param fields: The nested fields for this field. Used with `struct` and `table` field types to define the nested structure., defaults to None
115+
:type fields: Optional[List[AiExtractSubField]], optional
116+
:param taxonomy_key: The identifier for a taxonomy, which corresponds to the `key` of the taxonomy source. Required if using `taxonomy` type field., defaults to None
117+
:type taxonomy_key: Optional[str], optional
118+
:param namespace: The namespace of the taxonomy source. Required if using `taxonomy` type field from an existing taxonomy., defaults to None
119+
:type namespace: Optional[str], optional
100120
"""
101121
super().__init__(**kwargs)
102122
self.key = key
@@ -105,6 +125,10 @@ def __init__(
105125
self.prompt = prompt
106126
self.type = type
107127
self.options = options
128+
self.fields = fields
129+
self.taxonomy_key = taxonomy_key
130+
self.namespace = namespace
131+
self.options_rules = options_rules
108132

109133

110134
class AiExtractStructured(BaseObject):
@@ -117,6 +141,7 @@ def __init__(
117141
ai_agent: Optional[AiExtractStructuredAgent] = None,
118142
include_confidence_score: Optional[bool] = None,
119143
include_reference: Optional[bool] = None,
144+
taxonomy_sources: Optional[List[AiTaxonomySource]] = None,
120145
**kwargs
121146
):
122147
"""
@@ -132,6 +157,9 @@ def __init__(
132157
:type include_confidence_score: Optional[bool], optional
133158
:param include_reference: A flag to indicate whether references for every extracted field should be returned., defaults to None
134159
:type include_reference: Optional[bool], optional
160+
:param taxonomy_sources: The taxonomy sources to be used for the structured extraction. They can either be an existing file or a taxonomy.
161+
For your request to work, `fields` must also be provided. `taxonomy_sources` is not supported with `metadata_template`., defaults to None
162+
:type taxonomy_sources: Optional[List[AiTaxonomySource]], optional
135163
"""
136164
super().__init__(**kwargs)
137165
self.items = items
@@ -140,3 +168,4 @@ def __init__(
140168
self.ai_agent = ai_agent
141169
self.include_confidence_score = include_confidence_score
142170
self.include_reference = include_reference
171+
self.taxonomy_sources = taxonomy_sources
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from typing import Optional
2+
3+
from typing import List
4+
5+
from typing import Dict
6+
7+
from box_sdk_gen.internal.base_object import BaseObject
8+
9+
from box_sdk_gen.schemas.ai_extract_field_option import AiExtractFieldOption
10+
11+
from box_sdk_gen.box.errors import BoxSDKError
12+
13+
14+
class AiExtractSubField(BaseObject):
15+
_fields_to_json_mapping: Dict[str, str] = {
16+
'display_name': 'displayName',
17+
**BaseObject._fields_to_json_mapping,
18+
}
19+
_json_to_fields_mapping: Dict[str, str] = {
20+
'displayName': 'display_name',
21+
**BaseObject._json_to_fields_mapping,
22+
}
23+
24+
def __init__(
25+
self,
26+
key: str,
27+
*,
28+
description: Optional[str] = None,
29+
display_name: Optional[str] = None,
30+
prompt: Optional[str] = None,
31+
type: Optional[str] = None,
32+
options: Optional[List[AiExtractFieldOption]] = None,
33+
**kwargs
34+
):
35+
"""
36+
:param key: A unique identifier for the nested field.
37+
:type key: str
38+
:param description: A description of the nested field., defaults to None
39+
:type description: Optional[str], optional
40+
:param display_name: The display name of the nested field., defaults to None
41+
:type display_name: Optional[str], optional
42+
:param prompt: Context about the nested field that may include how to find and how to format it., defaults to None
43+
:type prompt: Optional[str], optional
44+
:param type: The type of the nested field. Allowed types include `string`, `float`, `date`, `number`, `text`, `boolean`, `enum` and `multiSelect`., defaults to None
45+
:type type: Optional[str], optional
46+
:param options: A list of options for this nested field. Used with `enum` and `multiSelect` types., defaults to None
47+
:type options: Optional[List[AiExtractFieldOption]], optional
48+
"""
49+
super().__init__(**kwargs)
50+
self.key = key
51+
self.description = description
52+
self.display_name = display_name
53+
self.prompt = prompt
54+
self.type = type
55+
self.options = options
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from typing import Optional
2+
3+
from typing import List
4+
5+
from box_sdk_gen.internal.base_object import BaseObject
6+
7+
from box_sdk_gen.box.errors import BoxSDKError
8+
9+
10+
class AiOptionsRules(BaseObject):
11+
def __init__(
12+
self,
13+
*,
14+
multi_select: Optional[bool] = None,
15+
selectable_levels: Optional[List[int]] = None,
16+
**kwargs
17+
):
18+
"""
19+
:param multi_select: Indicates whether the field is a multi-select field.
20+
If true, the field can have multiple values., defaults to None
21+
:type multi_select: Optional[bool], optional
22+
:param selectable_levels: The selectable levels for the field.
23+
This is used to limit the levels of the taxonomy that can be selected., defaults to None
24+
:type selectable_levels: Optional[List[int]], optional
25+
"""
26+
super().__init__(**kwargs)
27+
self.multi_select = multi_select
28+
self.selectable_levels = selectable_levels
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from enum import Enum
2+
3+
from typing import Optional
4+
5+
from box_sdk_gen.internal.base_object import BaseObject
6+
7+
from box_sdk_gen.box.errors import BoxSDKError
8+
9+
10+
class AiTaxonomyFileReferenceTypeField(str, Enum):
11+
FILE = 'file'
12+
13+
14+
class AiTaxonomyFileReference(BaseObject):
15+
_discriminator = 'type', {'file'}
16+
17+
def __init__(
18+
self,
19+
*,
20+
type: Optional[AiTaxonomyFileReferenceTypeField] = None,
21+
taxonomy_key: Optional[str] = None,
22+
id: Optional[str] = None,
23+
**kwargs
24+
):
25+
"""
26+
:param type: The type of the taxonomy source., defaults to None
27+
:type type: Optional[AiTaxonomyFileReferenceTypeField], optional
28+
:param taxonomy_key: The identifier for a taxonomy, which corresponds to the `taxonomy_key` of the taxonomy source., defaults to None
29+
:type taxonomy_key: Optional[str], optional
30+
:param id: The ID of the taxonomy source. Required if the type is `file` and unsupported if the type is `taxonomy`., defaults to None
31+
:type id: Optional[str], optional
32+
"""
33+
super().__init__(**kwargs)
34+
self.type = type
35+
self.taxonomy_key = taxonomy_key
36+
self.id = id

0 commit comments

Comments
 (0)