@albatrossai/albatross-sdk 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +35 -67
- package/dist/client.js +53 -24
- package/dist/request.d.ts +7 -0
- package/dist/request.js +16 -0
- package/dist/type.d.ts +33 -0
- package/dist/type.js +2 -0
- package/package.json +4 -5
package/dist/client.d.ts
CHANGED
|
@@ -1,70 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
value?: string;
|
|
4
|
-
eventType: string;
|
|
5
|
-
payload?: Record<string, any>;
|
|
6
|
-
timestamp?: string;
|
|
7
|
-
}
|
|
8
|
-
export interface DataPoint {
|
|
9
|
-
context_features: [];
|
|
10
|
-
actions: string[];
|
|
11
|
-
action_features: any;
|
|
12
|
-
rewards: {};
|
|
13
|
-
ordering: {
|
|
14
|
-
[k: string]: number;
|
|
15
|
-
};
|
|
16
|
-
scores: {
|
|
17
|
-
[k: string]: number;
|
|
18
|
-
};
|
|
19
|
-
is_randomized: boolean;
|
|
20
|
-
propensities: {
|
|
21
|
-
[k: string]: number;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
1
|
+
import * as Request from "./request";
|
|
2
|
+
import { DataPoint, PredictionPayload } from "./type";
|
|
24
3
|
declare class Client {
|
|
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
|
-
datapoint: DataPoint;
|
|
59
|
-
id: string;
|
|
60
|
-
}>;
|
|
61
|
-
feedback: (payload: {
|
|
62
|
-
useCaseUuid?: string;
|
|
63
|
-
modelUuid?: string;
|
|
64
|
-
predictionUuid: string;
|
|
65
|
-
value: {
|
|
66
|
-
[k: string]: any;
|
|
67
|
-
};
|
|
68
|
-
}) => Promise<any>;
|
|
4
|
+
token: string;
|
|
5
|
+
instanceUuid: string;
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
headers: Record<string, string>;
|
|
8
|
+
makeRequest: <A, B extends Record<string, any>>(inputs: Request.MakeRequestInputs<B>) => Promise<A>;
|
|
9
|
+
predictionPreProcessing: (data: PredictionPayload) => PredictionPayload;
|
|
10
|
+
constructor(token: string, instanceUuid: string, baseUrl?: string, options?: Partial<{
|
|
11
|
+
makeRequest: <A, B extends Record<string, any>>(inputs: Request.MakeRequestInputs<B>) => Promise<A>;
|
|
12
|
+
predictionPreProcessing: (data: PredictionPayload) => PredictionPayload;
|
|
13
|
+
}>);
|
|
14
|
+
getVersion(): Promise<unknown>;
|
|
15
|
+
catalogAdd: ({ entity, data, mainUnit, }: {
|
|
16
|
+
entity: string;
|
|
17
|
+
data: {
|
|
18
|
+
[k: string]: any;
|
|
19
|
+
}[];
|
|
20
|
+
mainUnit?: string;
|
|
21
|
+
}) => Promise<unknown>;
|
|
22
|
+
putEvent(payload: Event): Promise<any>;
|
|
23
|
+
prediction: (payload: PredictionPayload) => Promise<{
|
|
24
|
+
ordering: {
|
|
25
|
+
[key: string]: number;
|
|
26
|
+
};
|
|
27
|
+
datapoint: DataPoint;
|
|
28
|
+
id: string;
|
|
29
|
+
}>;
|
|
30
|
+
feedback: (payload: {
|
|
31
|
+
modelUuid?: string;
|
|
32
|
+
predictionUuid: string;
|
|
33
|
+
value: {
|
|
34
|
+
[k: string]: any;
|
|
35
|
+
};
|
|
36
|
+
}) => Promise<unknown>;
|
|
69
37
|
}
|
|
70
38
|
export default Client;
|
package/dist/client.js
CHANGED
|
@@ -1,66 +1,95 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const Request = __importStar(require("./request"));
|
|
3
37
|
const utils_1 = require("./utils");
|
|
4
38
|
const hostDefault = "https://app.usealbatross.ai/api";
|
|
5
39
|
class Client {
|
|
6
|
-
constructor(token, instanceUuid, baseUrl = hostDefault) {
|
|
40
|
+
constructor(token, instanceUuid, baseUrl = hostDefault, options = {}) {
|
|
7
41
|
this.token = token;
|
|
8
42
|
this.instanceUuid = instanceUuid;
|
|
9
43
|
this.baseUrl = baseUrl;
|
|
10
44
|
this.catalogAdd = async ({ entity, data, mainUnit, }) => {
|
|
11
45
|
const formattedData = data.map(utils_1.flattenNested);
|
|
12
|
-
|
|
46
|
+
return this.makeRequest({
|
|
47
|
+
url: this.baseUrl + "/catalog",
|
|
13
48
|
method: "PUT",
|
|
14
|
-
|
|
49
|
+
data: { data: formattedData, entity, mainUnit },
|
|
15
50
|
headers: this.headers,
|
|
16
51
|
});
|
|
17
|
-
await this.handleNotOk(response);
|
|
18
|
-
return response.json();
|
|
19
52
|
};
|
|
20
53
|
this.prediction = async (payload) => {
|
|
21
54
|
const url = `${this.baseUrl}/use-case/prediction`;
|
|
22
|
-
const
|
|
55
|
+
const data = this.predictionPreProcessing(payload);
|
|
56
|
+
return this.makeRequest({
|
|
23
57
|
method: "POST",
|
|
58
|
+
url,
|
|
59
|
+
data,
|
|
24
60
|
headers: this.headers,
|
|
25
|
-
body: JSON.stringify(payload),
|
|
26
61
|
});
|
|
27
|
-
await this.handleNotOk(response);
|
|
28
|
-
return response.json();
|
|
29
62
|
};
|
|
30
63
|
this.feedback = async (payload) => {
|
|
31
64
|
const url = `${this.baseUrl}/feedback`;
|
|
32
|
-
|
|
65
|
+
return this.makeRequest({
|
|
33
66
|
method: "POST",
|
|
67
|
+
url: url,
|
|
68
|
+
data: payload,
|
|
34
69
|
headers: this.headers,
|
|
35
|
-
body: JSON.stringify(payload),
|
|
36
70
|
});
|
|
37
|
-
await this.handleNotOk(response);
|
|
38
|
-
return response.json();
|
|
39
71
|
};
|
|
40
72
|
this.headers = {
|
|
41
73
|
"content-type": "application/json",
|
|
42
74
|
Authorization: "Bearer " + this.token,
|
|
43
75
|
"x-instance-id": this.instanceUuid,
|
|
44
76
|
};
|
|
77
|
+
this.makeRequest = options.makeRequest || Request.makeRequest;
|
|
78
|
+
this.predictionPreProcessing =
|
|
79
|
+
options.predictionPreProcessing || ((data) => data);
|
|
45
80
|
}
|
|
46
81
|
async getVersion() {
|
|
47
|
-
const
|
|
48
|
-
return
|
|
49
|
-
}
|
|
50
|
-
async handleNotOk(response) {
|
|
51
|
-
if (!response.ok) {
|
|
52
|
-
throw new Error(`Request failed: ${response.status} ${response.statusText} ${await response.text()}`);
|
|
53
|
-
}
|
|
82
|
+
const url = this.baseUrl + "/version";
|
|
83
|
+
return this.makeRequest({ url, headers: this.headers });
|
|
54
84
|
}
|
|
55
85
|
async putEvent(payload) {
|
|
56
86
|
const url = `${this.baseUrl}/event`;
|
|
57
|
-
|
|
87
|
+
return this.makeRequest({
|
|
58
88
|
method: "PUT",
|
|
89
|
+
url: url,
|
|
90
|
+
data: payload,
|
|
59
91
|
headers: this.headers,
|
|
60
|
-
body: JSON.stringify(payload),
|
|
61
92
|
});
|
|
62
|
-
await this.handleNotOk(response);
|
|
63
|
-
return response.json();
|
|
64
93
|
}
|
|
65
94
|
}
|
|
66
95
|
exports.default = Client;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const makeRequest: <A, B extends Record<string, any>>({ url, method, data, headers, }: MakeRequestInputs<B>) => Promise<A>;
|
|
2
|
+
export interface MakeRequestInputs<B extends Record<string, any>> {
|
|
3
|
+
url: string;
|
|
4
|
+
method?: string;
|
|
5
|
+
data?: B;
|
|
6
|
+
headers: Record<string, string>;
|
|
7
|
+
}
|
package/dist/request.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeRequest = void 0;
|
|
4
|
+
const makeRequest = async ({ url, method = "GET", data, headers, }) => {
|
|
5
|
+
const body = data ? JSON.stringify(data) : undefined;
|
|
6
|
+
const response = await fetch(url, {
|
|
7
|
+
method,
|
|
8
|
+
body,
|
|
9
|
+
headers,
|
|
10
|
+
});
|
|
11
|
+
if (!response.ok) {
|
|
12
|
+
throw new Error(`Request failed: ${response.status} ${response.statusText} ${await response.text()}`);
|
|
13
|
+
}
|
|
14
|
+
return response.json();
|
|
15
|
+
};
|
|
16
|
+
exports.makeRequest = makeRequest;
|
package/dist/type.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface Event {
|
|
2
|
+
eventType: string;
|
|
3
|
+
payload?: Record<string, any>;
|
|
4
|
+
timestamp?: string;
|
|
5
|
+
units?: Record<string, string>;
|
|
6
|
+
value?: string;
|
|
7
|
+
}
|
|
8
|
+
export type PredictionUnit = {
|
|
9
|
+
[k: string]: string;
|
|
10
|
+
};
|
|
11
|
+
export interface DataPoint {
|
|
12
|
+
actions: string[];
|
|
13
|
+
context_features: any;
|
|
14
|
+
action_features: any;
|
|
15
|
+
rewards: any;
|
|
16
|
+
ordering: {
|
|
17
|
+
[k: string]: number;
|
|
18
|
+
};
|
|
19
|
+
scores: {
|
|
20
|
+
[k: string]: number;
|
|
21
|
+
};
|
|
22
|
+
is_randomized: boolean;
|
|
23
|
+
propensities: {
|
|
24
|
+
[k: string]: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export interface PredictionPayload {
|
|
28
|
+
useCase: {
|
|
29
|
+
uuid: string;
|
|
30
|
+
};
|
|
31
|
+
context: PredictionUnit;
|
|
32
|
+
actions: PredictionUnit[];
|
|
33
|
+
}
|
package/dist/type.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@albatrossai/albatross-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"main": "dist/client.js",
|
|
5
5
|
"types": "dist/client.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -14,9 +14,8 @@
|
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"description": "",
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"typescript": "^5.7.2"
|
|
18
|
-
},
|
|
19
|
-
"dependencies": {
|
|
17
|
+
"typescript": "^5.7.2",
|
|
20
18
|
"@types/bun": "^1.2.2"
|
|
21
|
-
}
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {}
|
|
22
21
|
}
|