Skip to content

Commit 1e11ddd

Browse files
test(boxsdkgen): Fix Box AI tests (box/box-codegen#886) (#1200)
1 parent dfd62bd commit 1e11ddd

File tree

3 files changed

+28
-54
lines changed

3 files changed

+28
-54
lines changed

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "2ac72c4", "specHash": "e7ce024", "version": "4.0.0" }
1+
{ "engineHash": "a17cbb6", "specHash": "e7ce024", "version": "4.0.0" }

docs/box_sdk_gen/ai.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ See the endpoint docs at
1818
<!-- sample post_ai_ask -->
1919

2020
```python
21-
client.ai.create_ai_ask(CreateAiAskMode.SINGLE_ITEM_QA, 'which direction sun rises', [AiItemAsk(id=file_to_ask.id, type=AiItemAskTypeField.FILE, content='Sun rises in the East')], ai_agent=ai_ask_agent_config)
21+
client.ai.create_ai_ask(CreateAiAskMode.SINGLE_ITEM_QA, 'Which direction does the Sun rise?', [AiItemAsk(id=file_to_ask.id, type=AiItemAskTypeField.FILE, content='The Sun rises in the east')], ai_agent=ai_ask_agent_basic_text_config)
2222
```
2323

2424
### Arguments
@@ -55,7 +55,7 @@ See the endpoint docs at
5555
<!-- sample post_ai_text_gen -->
5656

5757
```python
58-
client.ai.create_ai_text_gen('Parapharse the document.s', [CreateAiTextGenItems(id=file_to_ask.id, type=CreateAiTextGenItemsTypeField.FILE, content='The Earth goes around the sun. Sun rises in the East in the morning.')], dialogue_history=[AiDialogueHistory(prompt='What does the earth go around?', answer='The sun', created_at=date_time_from_string('2021-01-01T00:00:00Z')), AiDialogueHistory(prompt='On Earth, where does the sun rise?', answer='East', created_at=date_time_from_string('2021-01-01T00:00:00Z'))], ai_agent=ai_text_gen_agent_config)
58+
client.ai.create_ai_text_gen('Paraphrase the documents', [CreateAiTextGenItems(id=file_to_ask.id, type=CreateAiTextGenItemsTypeField.FILE, content='The Earth goes around the Sun. The Sun rises in the east in the morning.')], dialogue_history=[AiDialogueHistory(prompt='What does the earth go around?', answer='The Sun', created_at=date_time_from_string('2021-01-01T00:00:00Z')), AiDialogueHistory(prompt='On Earth, where does the Sun rise?', answer='east', created_at=date_time_from_string('2021-01-01T00:00:00Z'))])
5959
```
6060

6161
### Arguments
@@ -129,7 +129,7 @@ See the endpoint docs at
129129
<!-- sample post_ai_extract -->
130130

131131
```python
132-
client.ai.create_ai_extract('firstName, lastName, location, yearOfBirth, company', [AiItemBase(id=file.id)], ai_agent=agent_ignoring_overriding_embeddings_model)
132+
client.ai.create_ai_extract('firstName, lastName, location, yearOfBirth, company', [AiItemBase(id=file.id)], ai_agent=ai_extract_agent_basic_text_config)
133133
```
134134

135135
### Arguments
@@ -167,7 +167,7 @@ See the endpoint docs at
167167
<!-- sample post_ai_extract_structured -->
168168

169169
```python
170-
client.ai.create_ai_extract_structured([AiItemBase(id=file.id)], fields=[CreateAiExtractStructuredFields(key='firstName', display_name='First name', description='Person first name', prompt='What is the your first name?', type='string'), CreateAiExtractStructuredFields(key='lastName', display_name='Last name', description='Person last name', prompt='What is the your last name?', type='string'), CreateAiExtractStructuredFields(key='dateOfBirth', display_name='Birth date', description='Person date of birth', prompt='What is the date of your birth?', type='date'), CreateAiExtractStructuredFields(key='age', display_name='Age', description='Person age', prompt='How old are you?', type='float'), CreateAiExtractStructuredFields(key='hobby', display_name='Hobby', description='Person hobby', prompt='What is your hobby?', type='multiSelect', options=[CreateAiExtractStructuredFieldsOptionsField(key='guitar'), CreateAiExtractStructuredFieldsOptionsField(key='books')])], ai_agent=agent_ignoring_overriding_embeddings_model)
170+
client.ai.create_ai_extract_structured([AiItemBase(id=file.id)], fields=[CreateAiExtractStructuredFields(key='firstName', display_name='First name', description='Person first name', prompt='What is the your first name?', type='string'), CreateAiExtractStructuredFields(key='lastName', display_name='Last name', description='Person last name', prompt='What is the your last name?', type='string'), CreateAiExtractStructuredFields(key='dateOfBirth', display_name='Birth date', description='Person date of birth', prompt='What is the date of your birth?', type='date'), CreateAiExtractStructuredFields(key='age', display_name='Age', description='Person age', prompt='How old are you?', type='float'), CreateAiExtractStructuredFields(key='hobby', display_name='Hobby', description='Person hobby', prompt='What is your hobby?', type='multiSelect', options=[CreateAiExtractStructuredFieldsOptionsField(key='guitar'), CreateAiExtractStructuredFieldsOptionsField(key='books')])], ai_agent=ai_extract_structured_agent_basic_text_config)
171171
```
172172

173173
### Arguments

test/box_sdk_gen/test/ai.py

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,8 @@
6666

6767
from box_sdk_gen.internal.utils import delay_in_seconds
6868

69-
from box_sdk_gen.internal.utils import generate_byte_stream
70-
7169
from box_sdk_gen.internal.utils import date_time_from_string
7270

73-
from box_sdk_gen.internal.utils import date_time_to_string
74-
75-
from box_sdk_gen.internal.utils import get_value_from_object_raw_data
76-
7771
from test.box_sdk_gen.test.commons import upload_new_file
7872

7973
from box_sdk_gen.schemas.ai_agent_ask import AiAgentAsk
@@ -84,8 +78,6 @@
8478

8579
from box_sdk_gen.schemas.ai_agent_extract_structured import AiAgentExtractStructured
8680

87-
from box_sdk_gen.schemas.ai_agent_long_text_tool import AiAgentLongTextTool
88-
8981
client: BoxClient = get_default_client()
9082

9183

@@ -94,20 +86,23 @@ def testAskAISingleItem():
9486
GetAiAgentDefaultConfigMode.ASK, language='en-US'
9587
)
9688
ai_ask_agent_config: AiAgentAsk = ai_agent_config
89+
ai_ask_agent_basic_text_config: AiAgentAsk = AiAgentAsk(
90+
basic_text=ai_ask_agent_config.basic_text
91+
)
9792
file_to_ask: FileFull = upload_new_file()
9893
response: Optional[AiResponseFull] = client.ai.create_ai_ask(
9994
CreateAiAskMode.SINGLE_ITEM_QA,
100-
'which direction sun rises',
95+
'Which direction does the Sun rise?',
10196
[
10297
AiItemAsk(
10398
id=file_to_ask.id,
10499
type=AiItemAskTypeField.FILE,
105-
content='Sun rises in the East',
100+
content='The Sun rises in the east',
106101
)
107102
],
108-
ai_agent=ai_ask_agent_config,
103+
ai_agent=ai_ask_agent_basic_text_config,
109104
)
110-
assert 'East' in response.answer
105+
assert 'east' in response.answer
111106
assert response.completion_reason == 'done'
112107
client.files.delete_file_by_id(file_to_ask.id)
113108

@@ -117,56 +112,51 @@ def testAskAIMultipleItems():
117112
file_to_ask_2: FileFull = upload_new_file()
118113
response: Optional[AiResponseFull] = client.ai.create_ai_ask(
119114
CreateAiAskMode.MULTIPLE_ITEM_QA,
120-
'Which direction sun rises?',
115+
'Which direction does the Sun rise?',
121116
[
122117
AiItemAsk(
123118
id=file_to_ask_1.id,
124119
type=AiItemAskTypeField.FILE,
125-
content='Earth goes around the sun',
120+
content='Earth goes around the Sun',
126121
),
127122
AiItemAsk(
128123
id=file_to_ask_2.id,
129124
type=AiItemAskTypeField.FILE,
130-
content='Sun rises in the East in the morning',
125+
content='The Sun rises in the east in the morning',
131126
),
132127
],
133128
)
134-
assert 'East' in response.answer
129+
assert 'east' in response.answer
135130
assert response.completion_reason == 'done'
136131
client.files.delete_file_by_id(file_to_ask_1.id)
137132
client.files.delete_file_by_id(file_to_ask_2.id)
138133

139134

140135
def testAITextGenWithDialogueHistory():
141136
file_to_ask: FileFull = upload_new_file()
142-
ai_agent_config: AiAgent = client.ai.get_ai_agent_default_config(
143-
GetAiAgentDefaultConfigMode.TEXT_GEN, language='en-US'
144-
)
145-
ai_text_gen_agent_config: AiAgentTextGen = ai_agent_config
146137
response: AiResponse = client.ai.create_ai_text_gen(
147-
'Parapharse the document.s',
138+
'Paraphrase the documents',
148139
[
149140
CreateAiTextGenItems(
150141
id=file_to_ask.id,
151142
type=CreateAiTextGenItemsTypeField.FILE,
152-
content='The Earth goes around the sun. Sun rises in the East in the morning.',
143+
content='The Earth goes around the Sun. The Sun rises in the east in the morning.',
153144
)
154145
],
155146
dialogue_history=[
156147
AiDialogueHistory(
157148
prompt='What does the earth go around?',
158-
answer='The sun',
149+
answer='The Sun',
159150
created_at=date_time_from_string('2021-01-01T00:00:00Z'),
160151
),
161152
AiDialogueHistory(
162-
prompt='On Earth, where does the sun rise?',
163-
answer='East',
153+
prompt='On Earth, where does the Sun rise?',
154+
answer='east',
164155
created_at=date_time_from_string('2021-01-01T00:00:00Z'),
165156
),
166157
],
167-
ai_agent=ai_text_gen_agent_config,
168158
)
169-
assert 'sun' in response.answer
159+
assert 'Sun' in response.answer
170160
assert response.completion_reason == 'done'
171161
client.files.delete_file_by_id(file_to_ask.id)
172162

@@ -219,16 +209,8 @@ def testAIExtract():
219209
GetAiAgentDefaultConfigMode.EXTRACT, language='en-US'
220210
)
221211
ai_extract_agent_config: AiAgentExtract = ai_agent_config
222-
long_text_config_with_no_embeddings: AiAgentLongTextTool = AiAgentLongTextTool(
223-
system_message=ai_extract_agent_config.long_text.system_message,
224-
prompt_template=ai_extract_agent_config.long_text.prompt_template,
225-
model=ai_extract_agent_config.long_text.model,
226-
num_tokens_for_completion=ai_extract_agent_config.long_text.num_tokens_for_completion,
227-
llm_endpoint_params=ai_extract_agent_config.long_text.llm_endpoint_params,
228-
)
229-
agent_ignoring_overriding_embeddings_model: AiAgentExtract = AiAgentExtract(
230-
basic_text=ai_extract_agent_config.basic_text,
231-
long_text=long_text_config_with_no_embeddings,
212+
ai_extract_agent_basic_text_config: AiAgentExtract = AiAgentExtract(
213+
basic_text=ai_extract_agent_config.basic_text
232214
)
233215
uploaded_files: Files = client.uploads.upload_file(
234216
UploadFileAttributes(
@@ -244,7 +226,7 @@ def testAIExtract():
244226
response: AiResponse = client.ai.create_ai_extract(
245227
'firstName, lastName, location, yearOfBirth, company',
246228
[AiItemBase(id=file.id)],
247-
ai_agent=agent_ignoring_overriding_embeddings_model,
229+
ai_agent=ai_extract_agent_basic_text_config,
248230
)
249231
expected_response: str = (
250232
'{"firstName": "John", "lastName": "Doe", "location": "San Francisco", "yearOfBirth": "1990", "company": "Box"}'
@@ -259,17 +241,9 @@ def testAIExtractStructuredWithFields():
259241
GetAiAgentDefaultConfigMode.EXTRACT_STRUCTURED, language='en-US'
260242
)
261243
ai_extract_structured_agent_config: AiAgentExtractStructured = ai_agent_config
262-
long_text_config_with_no_embeddings: AiAgentLongTextTool = AiAgentLongTextTool(
263-
system_message=ai_extract_structured_agent_config.long_text.system_message,
264-
prompt_template=ai_extract_structured_agent_config.long_text.prompt_template,
265-
model=ai_extract_structured_agent_config.long_text.model,
266-
num_tokens_for_completion=ai_extract_structured_agent_config.long_text.num_tokens_for_completion,
267-
llm_endpoint_params=ai_extract_structured_agent_config.long_text.llm_endpoint_params,
268-
)
269-
agent_ignoring_overriding_embeddings_model: AiAgentExtractStructured = (
244+
ai_extract_structured_agent_basic_text_config: AiAgentExtractStructured = (
270245
AiAgentExtractStructured(
271-
basic_text=ai_extract_structured_agent_config.basic_text,
272-
long_text=long_text_config_with_no_embeddings,
246+
basic_text=ai_extract_structured_agent_config.basic_text
273247
)
274248
)
275249
uploaded_files: Files = client.uploads.upload_file(
@@ -326,7 +300,7 @@ def testAIExtractStructuredWithFields():
326300
],
327301
),
328302
],
329-
ai_agent=agent_ignoring_overriding_embeddings_model,
303+
ai_agent=ai_extract_structured_agent_basic_text_config,
330304
)
331305
assert to_string(response.answer.get('hobby')) == to_string(['guitar'])
332306
assert to_string(response.answer.get('firstName')) == 'John'

0 commit comments

Comments
 (0)