-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathwlmai-operations.ts
More file actions
34 lines (31 loc) · 1.2 KB
/
wlmai-operations.ts
File metadata and controls
34 lines (31 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import {getAiEngines, getKnowledgeBases} from "../lib/netapp/wlmai/wlmai";
async function* getKnowledgeBasesGenerator(aiEngineId:string){
let { knowledgeBases, nextToken } = await getKnowledgeBases(aiEngineId);
yield knowledgeBases;
while (nextToken) {
({ knowledgeBases, nextToken } = await getKnowledgeBases(aiEngineId, nextToken));
yield knowledgeBases;
}
}
async function listAllKnowledgeBases(aiEngineId:string){
const knowledgeBases = [];
for await (const knowledgeBasesPage of getKnowledgeBasesGenerator(aiEngineId)){
knowledgeBases.push(...knowledgeBasesPage);
}
return knowledgeBases;
}
export async function listAllAvailableKnowledgeBases() {
const [deployment,] = await getAiEngines(); // only one ai engine per tenancy account
if (deployment){
const {id,status} = deployment;
if (status.server){
const {server:{statusCode:serverStatusCode}} = status;
if (serverStatusCode===200){
const knowledgeBases = await listAllKnowledgeBases(id);
return { aiEngineId: id,
knowledgeBases};
}
}
}
throw new Error('No Active AI-Engine found');
}