Skip to content

Commit 2a46442

Browse files
feat(metadata-sidebar): Accommodate changes to ai/extract_structured API (#3849)
* feat(metadata-sidebar): Accommodate changes to ai/extract_structured API * feat(metadata-sidebar): Accommodate changes to ai/extract_structured API --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent f39a65e commit 2a46442

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

src/api/Intelligence.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* @author Box
55
*/
66

7-
import getProp from 'lodash/get';
87
import type { QuestionType } from '@box/box-ai-content-answers';
98
import Base from './Base';
109
import { AiExtractResponse } from './schemas/AiExtractResponse';
@@ -86,7 +85,9 @@ class Intelligence extends Base {
8685
id: `file_${item.id}`,
8786
});
8887

89-
return getProp(suggestionsResponse, 'data');
88+
return !!suggestionsResponse?.data?.answer && typeof suggestionsResponse.data.answer === 'object'
89+
? suggestionsResponse.data.answer
90+
: suggestionsResponse.data;
9091
}
9192
}
9293

src/api/__tests__/Intelligence.test.js

+19-18
Original file line numberDiff line numberDiff line change
@@ -124,25 +124,26 @@ describe('api/Intelligence', () => {
124124
}
125125
});
126126

127-
test('should return a successful response including the answer from the LLM', async () => {
128-
const suggestionsFromServer = {
129-
stringFieldKey: 'fieldVal1',
130-
floatFieldKey: 124.0,
131-
enumFieldKey: 'EnumOptionKey',
132-
multiSelectFieldKey: ['multiSelectOption1', 'multiSelectOption5'],
133-
};
134-
intelligence.xhr.post = jest.fn().mockReturnValueOnce({
135-
data: suggestionsFromServer,
136-
});
127+
test.each`
128+
suggestionsFromServer | responseData
129+
${{ stringFieldKey: 'fieldVal1', floatFieldKey: 124.0, enumFieldKey: 'EnumOptionKey', multiSelectFieldKey: ['multiSelectOption1', 'multiSelectOption5'] }} | ${{ data: { stringFieldKey: 'fieldVal1', floatFieldKey: 124.0, enumFieldKey: 'EnumOptionKey', multiSelectFieldKey: ['multiSelectOption1', 'multiSelectOption5'] } }}
130+
${{ stringFieldKey: 'fieldVal1', floatFieldKey: 124.0, enumFieldKey: 'EnumOptionKey', multiSelectFieldKey: ['multiSelectOption1', 'multiSelectOption5'] }} | ${{ data: { answer: { stringFieldKey: 'fieldVal1', floatFieldKey: 124.0, enumFieldKey: 'EnumOptionKey', multiSelectFieldKey: ['multiSelectOption1', 'multiSelectOption5'] }, create_at: '2025-01-14T00:00:00-00:00' } }}
131+
${{}} | ${{ data: {} }}
132+
${{}} | ${{ data: { answer: {}, create_at: '2025-01-14T00:00:00-00:00' } }}
133+
`(
134+
'should return a successful response including the answer from the LLM',
135+
async ({ suggestionsFromServer, responseData }) => {
136+
intelligence.xhr.post = jest.fn().mockReturnValueOnce(responseData);
137137

138-
const suggestions = await intelligence.extractStructured(request);
139-
expect(suggestions).toEqual(suggestionsFromServer);
140-
expect(intelligence.xhr.post).toHaveBeenCalledWith({
141-
url: `${intelligence.getBaseApiUrl()}/ai/extract_structured`,
142-
id: 'file_123',
143-
data: request,
144-
});
145-
});
138+
const suggestions = await intelligence.extractStructured(request);
139+
expect(suggestions).toEqual(suggestionsFromServer);
140+
expect(intelligence.xhr.post).toHaveBeenCalledWith({
141+
url: `${intelligence.getBaseApiUrl()}/ai/extract_structured`,
142+
id: 'file_123',
143+
data: request,
144+
});
145+
},
146+
);
146147

147148
test('should not return any suggestions when error is 400', async () => {
148149
const error = new Error();

0 commit comments

Comments
 (0)