Skip to content

Commit 9a4b071

Browse files
authored
New Components - akkio (#13897)
* akkio init * [Components] akkio #13850 Actions - Make Prediction * pnpm update
1 parent f3dfbba commit 9a4b071

File tree

5 files changed

+177
-72
lines changed

5 files changed

+177
-72
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import akkio from "../../akkio.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "akkio-make-prediction",
6+
name: "Make Prediction",
7+
description: "Makes a prediction based on the input props. [See the documentation](https://docs.akkio.com/akkio-docs/rest-api/api-options/curl-commands)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
akkio,
12+
data: {
13+
type: "string[]",
14+
label: "Data",
15+
description: "Data in the format of: [{'field name 1': 'value 1', 'field name 2': 0}, {...}, ...]",
16+
},
17+
modelId: {
18+
type: "string",
19+
label: "Model ID",
20+
description: "The ID of the model to make the prediction with",
21+
async options() {
22+
const { models } = await this.akkio.getAllModels();
23+
24+
return models.map(({
25+
id: value, name: label,
26+
}) => ({
27+
label,
28+
value,
29+
}));
30+
},
31+
},
32+
33+
},
34+
async run({ $ }) {
35+
const response = await this.akkio.makePrediction({
36+
$,
37+
data: {
38+
data: parseObject(this.data),
39+
id: this.modelId,
40+
},
41+
});
42+
43+
$.export("$summary", `Successfully made prediction with model ID ${this.modelId}`);
44+
return response;
45+
},
46+
};

components/akkio/akkio.app.mjs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "akkio",
4-
propDefinitions: {},
56
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
7+
_baseUrl() {
8+
return "https://api.akkio.com/v1";
9+
},
10+
_headers() {
11+
return {
12+
api_key: `${this.$auth.api_key}`,
13+
};
14+
},
15+
_makeRequest({
16+
$ = this, path, ...opts
17+
}) {
18+
return axios($, {
19+
url: this._baseUrl() + path,
20+
headers: this._headers(),
21+
...opts,
22+
});
23+
},
24+
getAllModels(opts = {}) {
25+
return this._makeRequest({
26+
...opts,
27+
method: "GET",
28+
path: "/models",
29+
});
30+
},
31+
makePrediction(opts = {}) {
32+
return this._makeRequest({
33+
method: "POST",
34+
path: "/models",
35+
...opts,
36+
});
937
},
1038
},
11-
};
39+
};

components/akkio/common/utils.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

components/akkio/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/akkio",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Akkio Components",
55
"main": "akkio.app.mjs",
66
"keywords": [
@@ -11,5 +11,9 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.1"
1417
}
15-
}
18+
}
19+

pnpm-lock.yaml

Lines changed: 68 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)