diff --git a/.codegen.json b/.codegen.json index f3353ce..0aa85b2 100644 --- a/.codegen.json +++ b/.codegen.json @@ -1 +1 @@ -{ "engineHash": "36bf5da", "specHash": "f7e92ba", "version": "0.6.4" } +{ "engineHash": "c2589f6", "specHash": "f7e92ba", "version": "0.6.4" } diff --git a/docs/ai.md b/docs/ai.md index 6c319a1..68e5cab 100644 --- a/docs/ai.md +++ b/docs/ai.md @@ -12,7 +12,11 @@ This operation is performed by calling function `create_ai_ask`. See the endpoint docs at [API Reference](https://developer.box.com/reference/post-ai-ask/). -_Currently we don't have an example for calling `create_ai_ask` in integration tests_ + + +```python +client.ai.create_ai_ask(CreateAiAskMode.MULTIPLE_ITEM_QA.value, 'Which direction sun rises?', [CreateAiAskItems(id=file_to_ask_1.id, type=CreateAiAskItemsTypeField.FILE.value, content='Earth goes around the sun'), CreateAiAskItems(id=file_to_ask_2.id, type=CreateAiAskItemsTypeField.FILE.value, content='Sun rises in the East in the morning')]) +``` ### Arguments @@ -40,7 +44,11 @@ This operation is performed by calling function `create_ai_text_gen`. See the endpoint docs at [API Reference](https://developer.box.com/reference/post-ai-text-gen/). -_Currently we don't have an example for calling `create_ai_text_gen` in integration tests_ + + +```python +client.ai.create_ai_text_gen('Parapharse the document.s', [CreateAiTextGenItems(id=file_to_ask.id, type=CreateAiTextGenItemsTypeField.FILE.value, content='The Earth goes around the sun. Sun rises in the East in the morning.')], dialogue_history=[CreateAiTextGenDialogueHistory(prompt='What does the earth go around?', answer='The sun', created_at=date_time_from_string('2021-01-01T00:00:00Z')), CreateAiTextGenDialogueHistory(prompt='On Earth, where does the sun rise?', answer='East', created_at=date_time_from_string('2021-01-01T00:00:00Z'))]) +``` ### Arguments diff --git a/test/ai.py b/test/ai.py new file mode 100644 index 0000000..e6d2543 --- /dev/null +++ b/test/ai.py @@ -0,0 +1,103 @@ +from box_sdk_gen.client import BoxClient + +from box_sdk_gen.schemas import FileFull + +from box_sdk_gen.schemas import AiResponse + +from box_sdk_gen.managers.ai import CreateAiAskMode + +from box_sdk_gen.managers.ai import CreateAiAskItems + +from box_sdk_gen.managers.ai import CreateAiAskItemsTypeField + +from box_sdk_gen.managers.ai import CreateAiTextGenItems + +from box_sdk_gen.managers.ai import CreateAiTextGenItemsTypeField + +from box_sdk_gen.managers.ai import CreateAiTextGenDialogueHistory + +from test.commons import get_default_client + +from box_sdk_gen.internal.utils import get_uuid + +from box_sdk_gen.internal.utils import generate_byte_stream + +from box_sdk_gen.internal.utils import date_time_from_string + +from box_sdk_gen.internal.utils import date_time_to_string + +from test.commons import upload_new_file + +client: BoxClient = get_default_client() + + +def testAskAISingleItem(): + file_to_ask: FileFull = upload_new_file() + response: AiResponse = client.ai.create_ai_ask( + CreateAiAskMode.SINGLE_ITEM_QA.value, + 'which direction sun rises', + [ + CreateAiAskItems( + id=file_to_ask.id, + type=CreateAiAskItemsTypeField.FILE.value, + content='Sun rises in the East', + ) + ], + ) + assert 'East' in response.answer + assert response.completion_reason == 'done' + client.files.delete_file_by_id(file_to_ask.id) + + +def testAskAIMultipleItems(): + file_to_ask_1: FileFull = upload_new_file() + file_to_ask_2: FileFull = upload_new_file() + response: AiResponse = client.ai.create_ai_ask( + CreateAiAskMode.MULTIPLE_ITEM_QA.value, + 'Which direction sun rises?', + [ + CreateAiAskItems( + id=file_to_ask_1.id, + type=CreateAiAskItemsTypeField.FILE.value, + content='Earth goes around the sun', + ), + CreateAiAskItems( + id=file_to_ask_2.id, + type=CreateAiAskItemsTypeField.FILE.value, + content='Sun rises in the East in the morning', + ), + ], + ) + assert 'East' in response.answer + assert response.completion_reason == 'done' + client.files.delete_file_by_id(file_to_ask_1.id) + client.files.delete_file_by_id(file_to_ask_2.id) + + +def testAITextGenWithDialogueHistory(): + file_to_ask: FileFull = upload_new_file() + response: AiResponse = client.ai.create_ai_text_gen( + 'Parapharse the document.s', + [ + CreateAiTextGenItems( + id=file_to_ask.id, + type=CreateAiTextGenItemsTypeField.FILE.value, + content='The Earth goes around the sun. Sun rises in the East in the morning.', + ) + ], + dialogue_history=[ + CreateAiTextGenDialogueHistory( + prompt='What does the earth go around?', + answer='The sun', + created_at=date_time_from_string('2021-01-01T00:00:00Z'), + ), + CreateAiTextGenDialogueHistory( + prompt='On Earth, where does the sun rise?', + answer='East', + created_at=date_time_from_string('2021-01-01T00:00:00Z'), + ), + ], + ) + assert 'sun' in response.answer + assert response.completion_reason == 'done' + client.files.delete_file_by_id(file_to_ask.id)