Answers endpoint fix (#10176)

This commit is contained in:
jacekpluta
2024-09-06 13:22:40 +02:00
committed by Aleksander Sklorz
parent a21dc4d6a0
commit 13fc92e62c
10 changed files with 33 additions and 144 deletions

View File

@@ -20,10 +20,10 @@ Manages search AI in Content Services.
Ask a question to the AI. Ask a question to the AI.
- _question:_ [`QuestionRequest`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#questionrequest) - The question to ask. - _question:_ [`QuestionRequest`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#questionrequest) - The question to ask.
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`QuestionModel`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#questionmodel)`>` - QuestionModel object containing information about questions. - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`QuestionModel`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#questionmodel)`>` - QuestionModel object containing information about questions.
- **getAnswer**(questionId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`AiAnswerPaging`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#aianswerpaging)`>`<br/> - **getAnswer**(questionId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`AiAnswerEntry`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#aianswerentry)`>`<br/>
Get an answer to specific question. Get an answer to specific question.
- _questionId:_ `string` - The ID of the question to get an answer for. - _questionId:_ `string` - The ID of the question to get an answer for.
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`AiAnswerPaging`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#aianswerpaging)`>` - AiAnswerPaging object containing the answer. - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`AiAnswerEntry`](../../../lib/js-api/src/api/content-rest-api/docs/SearchAiApi.md#aianswerentry)`>` - AiAnswerEntry object containing the answer.
- **checkSearchAvailability**(selectedNodesState: `SelectionState`, maxSelectedNodes: `number`): `string`<br/> - **checkSearchAvailability**(selectedNodesState: `SelectionState`, maxSelectedNodes: `number`): `string`<br/>
Check if using of search is possible (if all conditions are met). Check if using of search is possible (if all conditions are met).
- _selectedNodesState:_ `SelectionState` - information about selected nodes. - _selectedNodesState:_ `SelectionState` - information about selected nodes.

View File

@@ -16,7 +16,7 @@
*/ */
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { AiAnswerPaging, Node, QuestionModel, QuestionRequest } from '@alfresco/js-api'; import { AiAnswerEntry, Node, QuestionModel, QuestionRequest } from '@alfresco/js-api';
import { ContentTestingModule } from '../../testing/content.testing.module'; import { ContentTestingModule } from '../../testing/content.testing.module';
import { SearchAiService } from './search-ai.service'; import { SearchAiService } from './search-ai.service';
import { SearchAiInputState } from '../models/search-ai-input-state'; import { SearchAiInputState } from '../models/search-ai-input-state';
@@ -57,16 +57,7 @@ describe('SearchAiService', () => {
describe('getAnswer', () => { describe('getAnswer', () => {
it('should load information about question', (done) => { it('should load information about question', (done) => {
const questionId = 'some id'; const questionId = 'some id';
const answer: AiAnswerPaging = { const answer: AiAnswerEntry = {
list: {
pagination: {
count: 2,
hasMoreItems: false,
skipCount: 0,
maxItems: 100
},
entries: [
{
entry: { entry: {
answer: 'Some answer 1', answer: 'Some answer 1',
questionId, questionId,
@@ -77,21 +68,6 @@ describe('SearchAiService', () => {
} }
] ]
} }
},
{
entry: {
answer: 'Some answer 2',
questionId,
references: [
{
referenceId: 'some reference id 2',
referenceText: 'some reference text 2'
}
]
}
}
]
}
}; };
spyOn(service.searchAiApi, 'getAnswer').and.returnValue(Promise.resolve(answer)); spyOn(service.searchAiApi, 'getAnswer').and.returnValue(Promise.resolve(answer));

View File

@@ -16,7 +16,7 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AiAnswerPaging, QuestionModel, QuestionRequest, SearchAiApi } from '@alfresco/js-api'; import { AiAnswerEntry, QuestionModel, QuestionRequest, SearchAiApi } from '@alfresco/js-api';
import { AlfrescoApiService } from '@alfresco/adf-core'; import { AlfrescoApiService } from '@alfresco/adf-core';
import { BehaviorSubject, from, Observable } from 'rxjs'; import { BehaviorSubject, from, Observable } from 'rxjs';
import { SelectionState } from '@alfresco/adf-extensions'; import { SelectionState } from '@alfresco/adf-extensions';
@@ -64,9 +64,9 @@ export class SearchAiService {
* Get an answer to specific question. * Get an answer to specific question.
* *
* @param questionId The ID of the question to get an answer for. * @param questionId The ID of the question to get an answer for.
* @returns AiAnswerPaging object containing the answer. * @returns AiAnswerEntry object containing the answer.
*/ */
getAnswer(questionId: string): Observable<AiAnswerPaging> { getAnswer(questionId: string): Observable<AiAnswerEntry> {
return from(this.searchAiApi.getAnswer(questionId)); return from(this.searchAiApi.getAnswer(questionId));
} }

View File

@@ -18,7 +18,7 @@
import { QuestionModel } from '../model/questionModel'; import { QuestionModel } from '../model/questionModel';
import { BaseApi } from '../../hxi-connector-api/api/base.api'; import { BaseApi } from '../../hxi-connector-api/api/base.api';
import { QuestionRequest } from '../model/questionRequest'; import { QuestionRequest } from '../model/questionRequest';
import { AiAnswerPaging } from '../model/aiAnswerPaging'; import { AiAnswerEntry } from '../model';
/** /**
* Search AI API. * Search AI API.
@@ -45,11 +45,11 @@ export class SearchAiApi extends BaseApi {
* Get an answer to specific question. * Get an answer to specific question.
* *
* @param questionId The ID of the question to get an answer for. * @param questionId The ID of the question to get an answer for.
* @returns AiAnswerPaging object containing the answer. * @returns AiAnswerEntry object containing the answer.
*/ */
getAnswer(questionId: string): Promise<AiAnswerPaging> { getAnswer(questionId: string): Promise<AiAnswerEntry> {
return this.get({ return this.get({
path: `questions/${questionId}/answers` path: `questions/${questionId}/answers/-default-`
}); });
} }
} }

View File

@@ -1,9 +1,9 @@
# SearchAiApi # SearchAiApi
| Method | HTTP request | Description | | Method | HTTP request | Description |
|-------------------------|--------------------|-------------------------------------| |-------------------------|----------------------------|-------------------------------------|
| [ask](#ask) | **GET** /questions | Ask a question to the AI. | | [ask](#ask) | **GET** /questions | Ask a question to the AI. |
| [getAnswer](#getAnswer) | **GET** /answers | Get an answer to specific question. | | [getAnswer](#getAnswer) | **GET** /answers/-default- | Get an answer to specific question. |
## ask ## ask
@@ -95,27 +95,10 @@ searchAiApi.getAnswer('some question id').then((answer) => {
|----------------|--------|----------------------------------------------| |----------------|--------|----------------------------------------------|
| **questionId** | string | The ID of the question to get an answer for. | | **questionId** | string | The ID of the question to get an answer for. |
**Return type**: [AiAnswerPaging](#AiAnswerPaging) **Return type**: [AiAnswerEntry](#AiAnswerEntry)
# Models # Models
## AiAnswerPaging
**Properties**
| Name | Type |
|------|-------------------------------------------|
| list | [AiAnswerPagingList](#AiAnswerPagingList) |
## AiAnswerPagingList
**Properties**
| Name | Type |
|----------------|-----------------------------------|
| **pagination** | [Pagination](Pagination.md) |
| **entries** | [AiAnswerEntry[]](#AiAnswerEntry) |
## AiAnswerEntry ## AiAnswerEntry
**Properties** **Properties**

View File

@@ -1,22 +0,0 @@
/*!
* @license
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { AiAnswerPagingList } from './aiAnswerPagingList';
export interface AiAnswerPaging {
list?: AiAnswerPagingList;
}

View File

@@ -1,24 +0,0 @@
/*!
* @license
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Pagination } from './pagination';
import { AiAnswerEntry } from './aiAnswerEntry';
export interface AiAnswerPagingList {
entries?: AiAnswerEntry[];
pagination?: Pagination;
}

View File

@@ -34,8 +34,6 @@ export * from './agentPaging';
export * from './agentPagingList'; export * from './agentPagingList';
export * from './aiAnswer'; export * from './aiAnswer';
export * from './aiAnswerEntry'; export * from './aiAnswerEntry';
export * from './aiAnswerPaging';
export * from './aiAnswerPagingList';
export * from './aiAnswerReference'; export * from './aiAnswerReference';
export * from './association'; export * from './association';
export * from './associationBody'; export * from './associationBody';

View File

@@ -43,11 +43,13 @@ describe('SearchAiApi', () => {
.ask([ .ask([
{ {
question: 'some question 1', question: 'some question 1',
nodeIds: ['some node id 1'] nodeIds: ['some node id 1'],
agentId: 'some id 1'
}, },
{ {
question: 'some question 2', question: 'some question 2',
nodeIds: ['some node id 2', 'some node id 3'] nodeIds: ['some node id 2', 'some node id 3'],
agentId: 'some id 2'
} }
]) ])
.then((questions) => { .then((questions) => {
@@ -74,15 +76,6 @@ describe('SearchAiApi', () => {
searchAiApi.getAnswer('id1').then((answer) => { searchAiApi.getAnswer('id1').then((answer) => {
assert.deepStrictEqual(answer, { assert.deepStrictEqual(answer, {
list: {
pagination: {
count: 2,
hasMoreItems: false,
skipCount: 0,
maxItems: 100
},
entries: [
{
entry: { entry: {
answer: 'Some answer 1', answer: 'Some answer 1',
questionId: 'some id 1', questionId: 'some id 1',
@@ -93,21 +86,6 @@ describe('SearchAiApi', () => {
} }
] ]
} }
},
{
entry: {
answer: 'Some answer 2',
questionId: 'some id 2',
references: [
{
referenceId: 'some reference id 2',
referenceText: 'some reference text 2'
}
]
}
}
]
}
}); });
done(); done();
}); });

View File

@@ -47,7 +47,7 @@ export class SearchAiMock extends BaseMock {
mockGetAnswer200Response(): void { mockGetAnswer200Response(): void {
nock(this.host, { encodedQueryParams: true }) nock(this.host, { encodedQueryParams: true })
.get('/alfresco/api/-default-/private/hxi/versions/1/answers?questionId=id1') .get('/alfresco/api/-default-/private/hxi/versions/1/answers/-default-?questionId=id1')
.reply(200, { .reply(200, {
list: { list: {
pagination: { pagination: {