Skip to content

Commit

Permalink
test: Box AI integration tests (box/box-codegen#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
box-sdk-build committed May 9, 2024
1 parent d05a650 commit bb19976
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "36bf5da", "specHash": "f7e92ba", "version": "0.6.4" }
{ "engineHash": "c2589f6", "specHash": "f7e92ba", "version": "0.6.4" }
12 changes: 10 additions & 2 deletions docs/ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_
<!-- sample post_ai_ask -->

```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

Expand Down Expand Up @@ -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_
<!-- sample post_ai_text_gen -->

```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

Expand Down
103 changes: 103 additions & 0 deletions test/ai.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit bb19976

Please sign in to comment.