6666
6767from box_sdk_gen .internal .utils import delay_in_seconds
6868
69- from box_sdk_gen .internal .utils import generate_byte_stream
70-
7169from 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-
7771from test .commons import upload_new_file
7872
7973from box_sdk_gen .schemas .ai_agent_ask import AiAgentAsk
8478
8579from 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-
8981client : 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
140135def 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