-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathwlmai.ts
More file actions
95 lines (91 loc) · 2.72 KB
/
wlmai.ts
File metadata and controls
95 lines (91 loc) · 2.72 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import got from 'got';
import {WLMAI_URL} from "../../../utils/consts";
import {getToken} from "../../../utils/service-token-utils";
export interface Deployment {
id:string,
stackId:string,
credentialsId:string,
creationDate:number,
placement:{
awsAccountId:string,
regionInfo:{
code:string,
name:string
},
subnetId:string,
vpceId:string
keyPair:string
instanceType:string
instanceId:string
},
status:{
ssm:{status:string},
instance:{status:string},
server:{statusCode:number}
}
}
export interface Document {
text:string, fileName:string
}
export interface KnowledgeBase {
id: string,
name: string,
description?: string,
isPublished: boolean,
isClassificationEnabled: boolean,
embeddingModelInfo: {
id: string,
name?: string
},
rerankingModelInfo: {
id: string,
name?: string
},
chatModelInfo: {
id: string,
name?: string
},
conversationStartersMode: string,
date: number,
conversationStarters: string[],
authSetting: {},
volumeName: string,
fsxId: string,
fsxName?: string,
fsxSvmId: string,
fsxSvmName?: string,
volumeId: string,
scheduleScan: boolean,
nextScan: number,
lastScanned?: number,
dataSourcesSummary: { embedding: number, embedded: number, failed: number }
}
export async function getAiEngines(){
console.log(`${WLMAI_URL}/accounts/${process.env.ACCOUNT_ID}/wlmai/v1/deployments`);
const {deployments = []} = await got.get(`${WLMAI_URL}/accounts/${process.env.ACCOUNT_ID}/wlmai/v1/deployments`, {
headers:{
authorization: await getToken()
}
}).json<{deployments:Deployment[]}>();
return deployments;
}
export async function getKnowledgeBases( deploymentId:string, token?:string){
const {knowledgeBases = [], nextToken} = await got.get(`${WLMAI_URL}/accounts/${process.env.ACCOUNT_ID}/wlmai/v2/deployments/${deploymentId}/knowledge-bases`, {
headers:{
authorization: await getToken()
},
searchParams: token ? {token} : {}
}).json<{knowledgeBases:KnowledgeBase[], nextToken?:string}>()
return {knowledgeBases, nextToken};
}
export async function searchKnowledgeBase(aiEngineId:string, knowledgeBaseId:string, question:string){
const {documents = []} = await got.post(`${WLMAI_URL}/accounts/${process.env.ACCOUNT_ID}/wlmai/v1/deployments/${aiEngineId}/knowledge-bases/${knowledgeBaseId}/search`, {
headers:{
authorization: await getToken()
},
json:{
question
}
}).json<{documents:Document[]}>();
return documents;
}