Skip to content

Commit cc775a1

Browse files
authored
[Components] wolfram_alpha - new action component (#15527)
1 parent ad37d81 commit cc775a1

File tree

5 files changed

+118
-9
lines changed

5 files changed

+118
-9
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import app from "../../wolfram_alpha.app.mjs";
2+
3+
export default {
4+
key: "wolfram_alpha-perform-computation",
5+
name: "Perform Computation",
6+
description: "Executes a computation query using the Wolfram Alpha API. [See the documentation](https://products.wolframalpha.com/api/documentation)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
input: {
12+
type: "string",
13+
label: "Input",
14+
description: "Text specifying the input string.",
15+
},
16+
width: {
17+
type: "string",
18+
label: "Width",
19+
description: "Specify an approximate width limit for text and tables. Eg. `200`, `500`. This parameter does not affect plots or graphics. Width values are approximate; behavior may vary for different content.",
20+
optional: true,
21+
},
22+
maxWidth: {
23+
type: "string",
24+
label: "Max Width",
25+
description: "Specify an extended maximum width for large objects. Eg. `200`, `500`. This parameter does not affect plots or graphics. Width values are approximate; behavior may vary for different content.",
26+
optional: true,
27+
},
28+
plotWidth: {
29+
type: "string",
30+
label: "Plot Width",
31+
description: "Specify an approximate width limit for plots and graphics. Eg. `100`, `200`. This parameter does not affect text or tables. Width values are approximate; behavior may vary for different content.",
32+
optional: true,
33+
},
34+
mag: {
35+
type: "string",
36+
label: "Magnification",
37+
description: "Specify magnification of objects within a pod. Eg. `0.5`, `1.0`, `2.0`. Changing this parameter does not affect the overall size of pods.",
38+
optional: true,
39+
},
40+
assumption: {
41+
type: "string",
42+
label: "Assumption",
43+
description: "Specifies an assumption, such as the meaning of a word or the value of a formula variable. Eg. `*C.pi-_*Movie`, `DateOrder_**Day.Month.Year--`. Assumptions made implicitly by the API. Values for this parameter are given by the input properties of `<value>` subelements of `<assumption>` elements in XML results.",
44+
optional: true,
45+
},
46+
},
47+
methods: {
48+
performComputation(args = {}) {
49+
return this.app.makeRequest({
50+
path: "/llm-api",
51+
...args,
52+
});
53+
},
54+
},
55+
async run({ $ }) {
56+
const {
57+
performComputation,
58+
input,
59+
width,
60+
maxWidth,
61+
plotWidth,
62+
mag,
63+
assumption,
64+
} = this;
65+
66+
const response = await performComputation({
67+
$,
68+
params: {
69+
input,
70+
width,
71+
maxwidth: maxWidth,
72+
plotwidth: plotWidth,
73+
mag,
74+
assumption,
75+
},
76+
});
77+
78+
$.export("$summary", "Computation performed successfully");
79+
return response;
80+
},
81+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const BASE_URL = "https://www.wolframalpha.com";
2+
const VERSION_PATH = "/api/v1";
3+
4+
export default {
5+
BASE_URL,
6+
VERSION_PATH,
7+
};

components/wolfram_alpha/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/wolfram_alpha",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Wolfram Alpha Components",
55
"main": "wolfram_alpha.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "wolfram_alpha",
4-
propDefinitions: {},
57
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
8+
getUrl(path) {
9+
return `${constants.BASE_URL}${constants.VERSION_PATH}${path}`;
10+
},
11+
getAuthParams(params) {
12+
return {
13+
...params,
14+
appid: this.$auth.app_id,
15+
};
16+
},
17+
makeRequest({
18+
$ = this, path, params, ...args
19+
} = {}) {
20+
return axios($, {
21+
...args,
22+
url: this.getUrl(path),
23+
params: this.getAuthParams(params),
24+
});
925
},
1026
},
1127
};

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)