mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-8201] Knowledge Retrieval - getting AI response for one or more selected files (#10229)
* [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 * ACS-8201 Small correction after rebasing with Angular 15 * [ACS-8398] Unit tests for agents and search ai (#9974) * ACS-8398 Unit tests for search ai api and agents api * ACS-8398 Unit tests for getAnswer function from SearchAiApi, corrections for unit tests for SearchAiApi and AgentsApi * ACS-8398 Unit tests for SearchAiService and AgentService * [ACS-8210] Agent basic details popup (#9956) * [ACS-8573] Allow user to ask question without file selection * [ACS-8312] Display warning about losing response (#10059) * [ACS-8312] Display warning about losing response * [ACS-8312] Display warning about losing response - fixes * [ACS-8432] Sending all file types to HX instead of only the text file types (#10087) * ACS-8201 Fixed issues after rebase * [ACS-8588] Navigation is triggered twice when leaving Knowledge Retrieval page (#10132) * [ACS-8588] Navigation is triggered twice when leaving Knowledge Retrieval page * [ACS-8588] Navigation is triggered twice when leaving Knowledge Retrieval page - review fixes * [ACS-8588] Navigation is triggered twice when leaving Knowledge Retrieval page - review fixes 2 * [ACS-8399] Integrate all changes with backend (#10163) * Answers endpoint fix (#10176) * [ACS-8664] generic question redirection to hx insight (#10174) * ACS-8664 Loading HX insight url * ACS-8664 Added documentation for loading config of Knowledge Retrieval * ACS-8664 Unit tests * ACS-8664 Fixed unit tests * ACS-8664 Fixed unit tests after rebase * ACS-8664 Addressed comment * ACS-8201 Fixed issues after rebase * [ACS-8695] Getting Agent avatar (#10189) * [ACS-8695] Getting Agent avatar * [ACS-8695] Getting Agent avatar - on image load error * [ACS-8695] Getting Agent avatar - removed getAgentAvatar call (#10209) * [ACS-8201] Review fixes --------- Co-authored-by: AleksanderSklorz <115619721+AleksanderSklorz@users.noreply.github.com> Co-authored-by: Aleksander Sklorz <Aleksander.Sklorz@hyland.com>
This commit is contained in:
18
lib/content-services/src/lib/agent/index.ts
Normal file
18
lib/content-services/src/lib/agent/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*!
|
||||
* @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 * from './public-api';
|
18
lib/content-services/src/lib/agent/public-api.ts
Normal file
18
lib/content-services/src/lib/agent/public-api.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*!
|
||||
* @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 * from './services/agent.service';
|
@@ -0,0 +1,72 @@
|
||||
/*!
|
||||
* @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 { TestBed } from '@angular/core/testing';
|
||||
import { CoreTestingModule } from '@alfresco/adf-core';
|
||||
import { AgentService } from './agent.service';
|
||||
import { Agent, AgentPaging } from '@alfresco/js-api';
|
||||
|
||||
const agent1: Agent = {
|
||||
id: '1',
|
||||
name: 'HR Agent',
|
||||
description: 'Your Claims Doc Agent streamlines the extraction, analysis, and management of data from insurance claims documents.',
|
||||
avatarUrl: ''
|
||||
};
|
||||
|
||||
const agent2: Agent = {
|
||||
id: '2',
|
||||
name: 'Policy Agent',
|
||||
description: 'Your Claims Doc Agent streamlines the extraction, analysis, and management of data from insurance claims documents.',
|
||||
avatarUrl: ''
|
||||
};
|
||||
|
||||
const agentPagingObjectMock: AgentPaging = {
|
||||
list: {
|
||||
entries: [
|
||||
{
|
||||
entry: agent1
|
||||
},
|
||||
{
|
||||
entry: agent2
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
const agentListMock: Agent[] = [agent1, agent2];
|
||||
|
||||
describe('AgentService', () => {
|
||||
let agentService: AgentService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
|
||||
agentService = TestBed.inject(AgentService);
|
||||
});
|
||||
|
||||
it('should load agents', (done) => {
|
||||
spyOn(agentService.agentsApi, 'getAgents').and.returnValue(Promise.resolve(agentPagingObjectMock));
|
||||
|
||||
agentService.getAgents().subscribe((pagingResponse) => {
|
||||
expect(pagingResponse).toEqual(agentListMock);
|
||||
expect(agentService.agentsApi.getAgents).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
61
lib/content-services/src/lib/agent/services/agent.service.ts
Normal file
61
lib/content-services/src/lib/agent/services/agent.service.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
/*!
|
||||
* @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 { Injectable } from '@angular/core';
|
||||
import { Agent, AgentsApi } from '@alfresco/js-api';
|
||||
import { BehaviorSubject, from, Observable, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { AlfrescoApiService } from '../../services';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AgentService {
|
||||
private _agentsApi: AgentsApi;
|
||||
private agents = new BehaviorSubject<Agent[]>([]);
|
||||
|
||||
get agentsApi(): AgentsApi {
|
||||
this._agentsApi = this._agentsApi ?? new AgentsApi(this.apiService.getInstance());
|
||||
return this._agentsApi;
|
||||
}
|
||||
|
||||
agents$ = this.agents.asObservable();
|
||||
|
||||
constructor(private apiService: AlfrescoApiService) {}
|
||||
|
||||
/**
|
||||
* Gets all agents from cache. If cache is empty, fetches agents from backend.
|
||||
*
|
||||
* @returns Agent[] list containing agents.
|
||||
*/
|
||||
getAgents(): Observable<Agent[]> {
|
||||
return this.agents$.pipe(
|
||||
switchMap((agentsList) => {
|
||||
if (agentsList.length) {
|
||||
return of(agentsList);
|
||||
}
|
||||
return from(this.agentsApi.getAgents()).pipe(
|
||||
map((paging) => {
|
||||
const agentEntries = paging.list.entries.map((agentEntry) => agentEntry.entry);
|
||||
this.agents.next(agentEntries);
|
||||
return agentEntries;
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
@@ -701,5 +701,13 @@
|
||||
"JOIN_CANCELED": "Canceled the request to join the library",
|
||||
"JOIN_REQUESTED": "Request sent to join this library"
|
||||
}
|
||||
},
|
||||
"KNOWLEDGE_RETRIEVAL": {
|
||||
"SEARCH": {
|
||||
"WARNINGS": {
|
||||
"TOO_MANY_FILES_SELECTED": "Please select no more than {{ maxFiles }} files.",
|
||||
"FOLDER_SELECTED": "Folders are not compatible with AI Agents."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
18
lib/content-services/src/lib/search-ai/index.ts
Normal file
18
lib/content-services/src/lib/search-ai/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*!
|
||||
* @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 * from './public-api';
|
@@ -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 SearchAiInputState {
|
||||
active: boolean;
|
||||
selectedAgentId?: string;
|
||||
}
|
19
lib/content-services/src/lib/search-ai/public-api.ts
Normal file
19
lib/content-services/src/lib/search-ai/public-api.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
/*!
|
||||
* @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 * from './services/search-ai.service';
|
||||
export * from './models/search-ai-input-state';
|
@@ -0,0 +1,220 @@
|
||||
/*!
|
||||
* @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 { TestBed } from '@angular/core/testing';
|
||||
import { AiAnswerEntry, KnowledgeRetrievalConfigEntry, Node, QuestionModel, QuestionRequest } from '@alfresco/js-api';
|
||||
import { ContentTestingModule } from '../../testing/content.testing.module';
|
||||
import { SearchAiService } from './search-ai.service';
|
||||
import { SearchAiInputState } from '../models/search-ai-input-state';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
|
||||
describe('SearchAiService', () => {
|
||||
let service: SearchAiService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [ContentTestingModule]
|
||||
});
|
||||
service = TestBed.inject(SearchAiService);
|
||||
});
|
||||
|
||||
describe('ask', () => {
|
||||
it('should load information about question', (done) => {
|
||||
const question: QuestionModel = {
|
||||
question: 'some question',
|
||||
questionId: 'some id',
|
||||
restrictionQuery: { nodesIds: ['nodeId1', 'nodeId2'] }
|
||||
};
|
||||
spyOn(service.searchAiApi, 'ask').and.returnValue(Promise.resolve(question));
|
||||
const questionRequest: QuestionRequest = {
|
||||
question: 'some question',
|
||||
nodeIds: ['nodeId1', 'nodeId2'],
|
||||
agentId: 'some id'
|
||||
};
|
||||
|
||||
service.ask(questionRequest).subscribe((questionResponse) => {
|
||||
expect(questionResponse).toBe(question);
|
||||
expect(service.searchAiApi.ask).toHaveBeenCalledWith([questionRequest]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getAnswer', () => {
|
||||
it('should load information about question', (done) => {
|
||||
const questionId = 'some id';
|
||||
const answer: AiAnswerEntry = {
|
||||
entry: {
|
||||
answer: 'Some answer 1',
|
||||
questionId,
|
||||
references: [
|
||||
{
|
||||
referenceId: 'some reference id 1',
|
||||
referenceText: 'some reference text 1'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
spyOn(service.searchAiApi, 'getAnswer').and.returnValue(Promise.resolve(answer));
|
||||
|
||||
service.getAnswer(questionId).subscribe((answerResponse) => {
|
||||
expect(answerResponse).toBe(answer);
|
||||
expect(service.searchAiApi.getAnswer).toHaveBeenCalledWith(questionId);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getConfig', () => {
|
||||
it('should load knowledge retrieval configuration', (done) => {
|
||||
const config: KnowledgeRetrievalConfigEntry = {
|
||||
entry: {
|
||||
knowledgeRetrievalUrl: 'https://some-url'
|
||||
}
|
||||
};
|
||||
spyOn(service.searchAiApi, 'getConfig').and.returnValue(Promise.resolve(config));
|
||||
|
||||
service.getConfig().subscribe((configResponse) => {
|
||||
expect(configResponse).toBe(config);
|
||||
expect(service.searchAiApi.getConfig).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateSearchAiInputState', () => {
|
||||
it('should trigger toggleSearchAiInput$', () => {
|
||||
const state: SearchAiInputState = {
|
||||
active: true,
|
||||
selectedAgentId: 'some id'
|
||||
};
|
||||
service.updateSearchAiInputState(state);
|
||||
|
||||
service.toggleSearchAiInput$.subscribe((receivedState) => {
|
||||
expect(receivedState).toBe(state);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkSearchAvailability', () => {
|
||||
let translateService: TranslateService;
|
||||
|
||||
const tooManyFilesSelectedError = 'Please select no more than 100 files.';
|
||||
const folderSelectedError = 'Folders are not compatible with AI Agents.';
|
||||
|
||||
beforeEach(() => {
|
||||
translateService = TestBed.inject(TranslateService);
|
||||
spyOn(translateService, 'instant').and.callFake((key) => {
|
||||
switch (key) {
|
||||
case 'KNOWLEDGE_RETRIEVAL.SEARCH.WARNINGS.TOO_MANY_FILES_SELECTED':
|
||||
return tooManyFilesSelectedError;
|
||||
case 'KNOWLEDGE_RETRIEVAL.SEARCH.WARNINGS.FOLDER_SELECTED':
|
||||
return folderSelectedError;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should not return error if user did not select any files', () => {
|
||||
expect(
|
||||
service.checkSearchAvailability({
|
||||
count: 0,
|
||||
nodes: [],
|
||||
libraries: [],
|
||||
isEmpty: true
|
||||
})
|
||||
).toEqual('');
|
||||
});
|
||||
|
||||
it('should return error for too many files selected', () => {
|
||||
expect(
|
||||
service.checkSearchAvailability({
|
||||
count: 101,
|
||||
nodes: [],
|
||||
libraries: [],
|
||||
isEmpty: false
|
||||
})
|
||||
).toBe(tooManyFilesSelectedError);
|
||||
expect(translateService.instant).toHaveBeenCalledWith('KNOWLEDGE_RETRIEVAL.SEARCH.WARNINGS.TOO_MANY_FILES_SELECTED', {
|
||||
maxFiles: 100,
|
||||
key: 'KNOWLEDGE_RETRIEVAL.SEARCH.WARNINGS.TOO_MANY_FILES_SELECTED'
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error for folder selected', () => {
|
||||
expect(
|
||||
service.checkSearchAvailability({
|
||||
count: 1,
|
||||
nodes: [
|
||||
{
|
||||
entry: {
|
||||
isFolder: true
|
||||
} as Node
|
||||
}
|
||||
],
|
||||
libraries: [],
|
||||
isEmpty: false
|
||||
})
|
||||
).toBe(folderSelectedError);
|
||||
});
|
||||
|
||||
it('should return error for folder and if non text mime type node is selected', () => {
|
||||
expect(
|
||||
service.checkSearchAvailability({
|
||||
count: 1,
|
||||
nodes: [
|
||||
{
|
||||
entry: {
|
||||
isFolder: true,
|
||||
content: {
|
||||
mimeType: 'some mime type',
|
||||
mimeTypeName: 'some mime type',
|
||||
sizeInBytes: 100
|
||||
}
|
||||
} as Node
|
||||
}
|
||||
],
|
||||
libraries: [],
|
||||
isEmpty: false
|
||||
})
|
||||
).toBe(folderSelectedError);
|
||||
});
|
||||
|
||||
it('should return more than one error if more validators detected issues', () => {
|
||||
expect(
|
||||
service.checkSearchAvailability({
|
||||
count: 101,
|
||||
nodes: [
|
||||
{
|
||||
entry: {
|
||||
isFolder: true,
|
||||
content: {
|
||||
mimeType: 'image/jpeg',
|
||||
mimeTypeName: 'image/jpeg',
|
||||
sizeInBytes: 100
|
||||
}
|
||||
} as Node
|
||||
}
|
||||
],
|
||||
libraries: [],
|
||||
isEmpty: false
|
||||
})
|
||||
).toBe(`${tooManyFilesSelectedError} ${folderSelectedError}`);
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,110 @@
|
||||
/*!
|
||||
* @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 { Injectable } from '@angular/core';
|
||||
import { AiAnswerEntry, KnowledgeRetrievalConfigEntry, QuestionModel, QuestionRequest, SearchAiApi } from '@alfresco/js-api';
|
||||
import { BehaviorSubject, from, Observable } from 'rxjs';
|
||||
import { SelectionState } from '@alfresco/adf-extensions';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { SearchAiInputState } from '../models/search-ai-input-state';
|
||||
import { AlfrescoApiService } from '../../services';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SearchAiService {
|
||||
private toggleSearchAiInput = new BehaviorSubject<SearchAiInputState>({
|
||||
active: false
|
||||
});
|
||||
private _searchAiApi: SearchAiApi;
|
||||
|
||||
get searchAiApi(): SearchAiApi {
|
||||
this._searchAiApi = this._searchAiApi ?? new SearchAiApi(this.apiService.getInstance());
|
||||
return this._searchAiApi;
|
||||
}
|
||||
|
||||
toggleSearchAiInput$ = this.toggleSearchAiInput.asObservable();
|
||||
|
||||
constructor(
|
||||
private apiService: AlfrescoApiService,
|
||||
private translateService: TranslateService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Update the state of the search AI input.
|
||||
*
|
||||
* @param state The new state of the search AI input.
|
||||
*/
|
||||
updateSearchAiInputState(state: SearchAiInputState): void {
|
||||
this.toggleSearchAiInput.next(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask a question to the AI.
|
||||
*
|
||||
* @param question The question to ask.
|
||||
* @returns QuestionModel object containing information about questions.
|
||||
*/
|
||||
ask(question: QuestionRequest): Observable<QuestionModel> {
|
||||
return from(this.searchAiApi.ask([question]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an answer to specific question.
|
||||
*
|
||||
* @param questionId The ID of the question to get an answer for.
|
||||
* @returns AiAnswerEntry object containing the answer.
|
||||
*/
|
||||
getAnswer(questionId: string): Observable<AiAnswerEntry> {
|
||||
return from(this.searchAiApi.getAnswer(questionId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the knowledge retrieval configuration.
|
||||
*
|
||||
* @returns KnowledgeRetrievalConfigEntry object containing the configuration.
|
||||
*/
|
||||
getConfig(): Observable<KnowledgeRetrievalConfigEntry> {
|
||||
return from(this.searchAiApi.getConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if using of search is possible (if all conditions are met).
|
||||
*
|
||||
* @param selectedNodesState information about selected nodes.
|
||||
* @param maxSelectedNodes max number of selected nodes. Default 100.
|
||||
* @returns string with error if any condition is not met, empty string otherwise.
|
||||
*/
|
||||
checkSearchAvailability(selectedNodesState: SelectionState, maxSelectedNodes = 100): string {
|
||||
const messages: {
|
||||
key: string;
|
||||
[parameter: string]: number | string;
|
||||
}[] = [];
|
||||
if (selectedNodesState.count > maxSelectedNodes) {
|
||||
messages.push({
|
||||
key: 'KNOWLEDGE_RETRIEVAL.SEARCH.WARNINGS.TOO_MANY_FILES_SELECTED',
|
||||
maxFiles: maxSelectedNodes
|
||||
});
|
||||
}
|
||||
if (selectedNodesState.nodes.some((node) => node.entry.isFolder)) {
|
||||
messages.push({
|
||||
key: 'KNOWLEDGE_RETRIEVAL.SEARCH.WARNINGS.FOLDER_SELECTED'
|
||||
});
|
||||
}
|
||||
return messages.map((message) => this.translateService.instant(message.key, message)).join(' ');
|
||||
}
|
||||
}
|
@@ -49,6 +49,8 @@ export * from './lib/prediction/index';
|
||||
export * from './lib/legal-hold/index';
|
||||
export * from './lib/api-factories';
|
||||
export * from './lib/mock/alfresco-api.service.mock';
|
||||
export * from './lib/agent/index';
|
||||
export * from './lib/search-ai/index';
|
||||
|
||||
export * from './lib/content.module';
|
||||
export * from './lib/material.module';
|
||||
|
Reference in New Issue
Block a user