[ACS-8202] basic flow getting ai response for one or more selected files (#9944)

* ACS-8202 Getting list of agents

* ACS-8202 Mocked agents, used base api from hxi connector

* ACS-8202 Search Ai service

* ACS-8202 Small correction and mocked data

* ACS-8202 Renamed variable

* ACS-8202 Added documentation

* ACS-8202 Addressed PR comments

* ACS-8202 Type change

* ACS-8202 Reverted unwatend change

* ACS-8202 Reverted unwanted change
This commit is contained in:
AleksanderSklorz
2024-07-16 15:12:13 +02:00
committed by Aleksander Sklorz
parent 7506c109d8
commit fd32667c1a
33 changed files with 1018 additions and 4 deletions

View File

@@ -0,0 +1,35 @@
/*!
* @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 { AgentPaging } from '../model/agentPaging';
import { BaseApi } from '../../hxi-connector-api/api/base.api';
/**
* Agents Api.
*/
export class AgentsApi extends BaseApi {
/**
* Gets all agents.
*
* @returns AgentPaging object containing the agents.
*/
getAgents(): Promise<AgentPaging> {
return this.get({
path: '/agents'
});
}
}

View File

@@ -18,6 +18,7 @@
export * from './types';
export * from './actions.api';
export * from './activities.api';
export * from './agents.api';
export * from './audit.api';
export * from './categories.api';
export * from './comments.api';
@@ -32,6 +33,7 @@ export * from './probes.api';
export * from './queries.api';
export * from './ratings.api';
export * from './renditions.api';
export * from './search-ai.api';
export * from './sharedlinks.api';
export * from './sites.api';
export * from './tags.api';

View File

@@ -0,0 +1,57 @@
/*!
* @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 { QuestionModel } from '../model/questionModel';
import { BaseApi } from '../../hxi-connector-api/api/base.api';
import { QuestionRequest } from '../model/questionRequest';
import { AiAnswerPaging } from '../model/aiAnswerPaging';
/**
* Search AI API.
*/
export class SearchAiApi extends BaseApi {
/**
* Ask a question to the AI.
*
* @param questions The questions to ask.
* @returns QuestionModel object containing information about questions.
*/
ask(questions: QuestionRequest[]): Promise<QuestionModel[]> {
return this.get({
path: 'questions',
bodyParam: questions.map((question) => ({
...question,
restrictionQuery: question.nodeIds.join(',')
}))
});
}
/**
* Get an answer to specific question.
*
* @param questionId The ID of the question to get an answer for.
* @returns AiAnswerPaging object containing the answer.
*/
getAnswer(questionId: string): Promise<AiAnswerPaging> {
return this.get({
path: 'answers',
queryParams: {
questionId
}
});
}
}

View File

@@ -0,0 +1,83 @@
# AgentsApi
| Method | HTTP request | Description |
|-------------------------|-----------------|------------------|
| [getAgents](#getAgents) | **GET** /agents | Gets all agents. |
## getAgents
Gets all agents.
A paginated list is returned in the response body. For example:
```json
{
"list": {
"pagination": {
"count": 2,
"hasMoreItems": false,
"totalItems": 2,
"skipCount": 0,
"maxItems": 100
},
"entries": [
{
"entry": {
"id": "Some id",
"name": "Some name"
}
}
]
}
}
```
**Example**
```javascript
import { AlfrescoApi, AgentsApi } from '@alfresco/js-api';
const alfrescoApi = new AlfrescoApi(/*..*/);
const agentsApi = new AgentsApi(alfrescoApi);
agentsApi.getAgents().then((agents) => {
console.log('API called successfully. Returned data: ' + agents);
});
```
**Return type**: [AgentPaging](#AgentPaging)
# Models
## AgentPaging
**Properties**
| Name | Type |
|------|-------------------------------------|
| list | [AgentPagingList](#AgentPagingList) |
## AgentPagingList
**Properties**
| Name | Type |
|----------------|-----------------------------|
| **pagination** | [Pagination](Pagination.md) |
| **entries** | [AgentEntry[]](#AgentEntry) |
## AgentEntry
**Properties**
| Name | Type |
|-----------|-----------------|
| **entry** | [Agent](#Agent) |
## Agent
**Properties**
| Name | Type |
|----------|--------|
| **id** | string |
| **name** | string |

View File

@@ -0,0 +1,162 @@
# SearchAiApi
| Method | HTTP request | Description |
|-------------------------|--------------------|-------------------------------------|
| [ask](#ask) | **GET** /questions | Ask a question to the AI. |
| [getAnswer](#getAnswer) | **GET** /answers | Get an answer to specific question. |
## ask
Ask a question to the AI.
A list is returned in the response body. For example:
```json
[
{
"question": "Some question",
"questionId": "Some question id",
"restrictionQuery": "Some restriction query"
}
]
```
**Example**
```javascript
import { AlfrescoApi, AgentsApi } from '@alfresco/js-api';
const alfrescoApi = new AlfrescoApi(/*..*/);
const searchAiApi = new SearchAiApi(alfrescoApi);
searchAiApi.ask([{
question: 'Some question',
restrictionQuery: 'Some restriction query'
}]).then((questionInformation) => {
console.log('API called successfully. Returned data: ' + questionInformation);
});
```
**Parameters**
| Name | Type | Description |
|---------------|---------------------------------------|-----------------------|
| **questions** | [QuestionRequest](#QuestionRequest)[] | The questions to ask. |
**Return type**: [QuestionModel](#QuestionModel)[]
## getAnswer
Get an answer to specific question.
A paginated list is returned in the response body. For example:
```json
{
"list": {
"pagination": {
"count": 2,
"hasMoreItems": false,
"totalItems": 2,
"skipCount": 0,
"maxItems": 100
},
"entries": [
{
"entry": {
"answer": "Some answer",
"questionId": "Some question id",
"references": [
{
"referenceId": "Some reference id",
"referenceText": "Some reference text"
}
]
}
}
]
}
}
```
**Example**
```javascript
import { AlfrescoApi, AgentsApi } from '@alfresco/js-api';
const alfrescoApi = new AlfrescoApi(/*..*/);
const searchAiApi = new SearchAiApi(alfrescoApi);
searchAiApi.getAnswer('some question id').then((answer) => {
console.log('API called successfully. Returned data: ' + answer);
});
```
**Parameters**
| Name | Type | Description |
|----------------|--------|----------------------------------------------|
| **questionId** | string | The ID of the question to get an answer for. |
**Return type**: [AiAnswerPaging](#AiAnswerPaging)
# Models
## AiAnswerPaging
**Properties**
| Name | Type |
|------|-------------------------------------------|
| list | [AiAnswerPagingList](#AiAnswerPagingList) |
## AiAnswerPagingList
**Properties**
| Name | Type |
|----------------|-----------------------------------|
| **pagination** | [Pagination](Pagination.md) |
| **entries** | [AiAnswerEntry[]](#AiAnswerEntry) |
## AiAnswerEntry
**Properties**
| Name | Type |
|-----------|-----------------------|
| **entry** | [AiAnswer](#AiAnswer) |
## AiAnswer
**Properties**
| Name | Type |
|----------------|-------------------------------------------|
| **answer** | string |
| **questionId** | string |
| **references** | [AiAnswerReference](#AiAnswerReference)[] |
## AiAnswerReference
**Properties**
| Name | Type |
|-------------------|--------|
| **referenceId** | string |
| **referenceText** | string |
## QuestionModel
**Properties**
| Name | Type |
|----------------------|--------|
| **question** | string |
| **questionId** | string |
| **restrictionQuery** | string |
## QuestionRequest
**Properties**
| Name | Type |
|--------------|----------|
| **question** | string |
| **nodeIds** | string[] |

View File

@@ -0,0 +1,21 @@
/*!
* @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.
*/
export interface Agent {
id: string;
name: string;
}

View File

@@ -0,0 +1,22 @@
/*!
* @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 { Agent } from './agent';
export interface AgentEntry {
entry: Agent;
}

View File

@@ -0,0 +1,22 @@
/*!
* @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 { AgentPagingList } from './agentPagingList';
export interface AgentPaging {
list?: AgentPagingList;
}

View File

@@ -0,0 +1,24 @@
/*!
* @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 { AgentEntry } from './agentEntry';
export interface AgentPagingList {
entries?: AgentEntry[];
pagination?: Pagination;
}

View File

@@ -0,0 +1,24 @@
/*!
* @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 { AiAnswerReference } from './aiAnswerReference';
export interface AiAnswer {
answer: string;
questionId: string;
references: AiAnswerReference[];
}

View File

@@ -0,0 +1,22 @@
/*!
* @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 { AiAnswer } from './aiAnswer';
export interface AiAnswerEntry {
entry: AiAnswer;
}

View File

@@ -0,0 +1,22 @@
/*!
* @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

@@ -0,0 +1,24 @@
/*!
* @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

@@ -0,0 +1,21 @@
/*!
* @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.
*/
export interface AiAnswerReference {
referenceId: string;
referenceText: string;
}

View File

@@ -27,6 +27,15 @@ export * from './activity';
export * from './activityEntry';
export * from './activityPaging';
export * from './activityPagingList';
export * from './agent';
export * from './agentEntry';
export * from './agentPaging';
export * from './agentPagingList';
export * from './aiAnswer';
export * from './aiAnswerEntry';
export * from './aiAnswerPaging';
export * from './aiAnswerPagingList';
export * from './aiAnswerReference';
export * from './association';
export * from './associationBody';
export * from './associationEntry';
@@ -133,6 +142,8 @@ export * from './preferencePagingList';
export * from './probeEntry';
export * from './probeEntryEntry';
export * from './property';
export * from './questionModel';
export * from './questionRequest';
export * from './rating';
export * from './ratingAggregate';
export * from './ratingBody';

View File

@@ -0,0 +1,22 @@
/*!
* @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.
*/
export interface QuestionModel {
question: string;
questionId: string;
restrictionQuery: string;
}

View File

@@ -0,0 +1,21 @@
/*!
* @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.
*/
export interface QuestionRequest {
question: string;
nodeIds: string[];
}