Skip to content

Commit 0e2f725

Browse files
committed
Added actions
1 parent 5f75543 commit 0e2f725

File tree

5 files changed

+182
-6
lines changed

5 files changed

+182
-6
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import app from "../../x_ai.app.mjs";
2+
3+
export default {
4+
key: "x_ai-get-model",
5+
name: "Get Model",
6+
description: "List all language and embedding models available. [See the documentation](https://docs.x.ai/api/endpoints#get-model)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
model: {
12+
propDefinition: [
13+
app,
14+
"model"
15+
]
16+
},
17+
},
18+
19+
async run({ $ }) {
20+
const response = await this.app.getModel({
21+
$,
22+
model: this.model,
23+
});
24+
25+
$.export("$summary", `Successfully retrieved the '${this.model}' model`);
26+
27+
return response;
28+
},
29+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import app from "../../x_ai.app.mjs";
2+
3+
export default {
4+
key: "x_ai-post-chat-completion",
5+
name: "Post Chat Completion",
6+
description: "Create a language model response for a chat conversation. [See the documentation](https://docs.x.ai/api/endpoints#chat-completions)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
model: {
12+
propDefinition: [
13+
app,
14+
"model"
15+
]
16+
},
17+
message: {
18+
propDefinition: [
19+
app,
20+
"message"
21+
]
22+
},
23+
},
24+
25+
async run({ $ }) {
26+
const response = await this.app.postChatCompletion({
27+
$,
28+
data: {
29+
model: this.model,
30+
messages: [
31+
{ role: "user", content: this.message },
32+
],
33+
},
34+
});
35+
36+
$.export("$summary", `Successfully sent message to the model '${this.model}'`);
37+
38+
return response;
39+
},
40+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import app from "../../x_ai.app.mjs";
2+
3+
export default {
4+
key: "x_ai-post-completion",
5+
name: "Post Completion",
6+
description: "Create a language model response for a given prompt. [See the documentation](https://docs.x.ai/api/endpoints#completions)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
model: {
12+
propDefinition: [
13+
app,
14+
"model"
15+
]
16+
},
17+
prompt: {
18+
propDefinition: [
19+
app,
20+
"prompt"
21+
]
22+
},
23+
},
24+
25+
async run({ $ }) {
26+
const response = await this.app.postCompletion({
27+
$,
28+
data: {
29+
model: this.model,
30+
prompt: this.prompt,
31+
},
32+
});
33+
34+
$.export("$summary", `Successfully sent prompt to the model '${this.model}'`);
35+
36+
return response;
37+
},
38+
};

components/x_ai/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/x_ai",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream X AI Components",
55
"main": "x_ai.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+
}

components/x_ai/x_ai.app.mjs

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,77 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "x_ai",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
model: {
8+
type: "string",
9+
label: "Model",
10+
description: "Specifies the model to be used for the request",
11+
async options() {
12+
const response = await this.listModels();
13+
const modelsIds = response.data;
14+
return modelsIds.map(({ id }) => ({
15+
value: id
16+
}));
17+
}
18+
},
19+
prompt: {
20+
type: "string",
21+
label: "Prompt",
22+
description: "Prompt for the request",
23+
},
24+
message: {
25+
type: "string",
26+
label: "Message",
27+
description: "Message for the chat completion",
28+
},
29+
},
530
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
31+
_baseUrl() {
32+
return `https://api.x.ai`;
33+
},
34+
async _makeRequest(opts = {}) {
35+
const {
36+
$ = this,
37+
path,
38+
headers,
39+
...otherOpts
40+
} = opts;
41+
return axios($, {
42+
...otherOpts,
43+
url: this._baseUrl() + path,
44+
headers: {
45+
...headers,
46+
Authorization: `Bearer ${this.$auth.api_key}`,
47+
},
48+
});
49+
},
50+
async postChatCompletion(args = {}) {
51+
return this._makeRequest({
52+
path: "/v1/chat/completions",
53+
method: "post",
54+
...args,
55+
});
56+
},
57+
async postCompletion(args = {}) {
58+
return this._makeRequest({
59+
path: `/v1/completions`,
60+
method: "post",
61+
...args,
62+
});
63+
},
64+
async getModel({ model, ...args }) {
65+
return this._makeRequest({
66+
path: `/v1/models/${model}`,
67+
...args,
68+
});
69+
},
70+
async listModels(args = {}) {
71+
return this._makeRequest({
72+
path: "/v1/models",
73+
...args,
74+
});
975
},
1076
},
1177
};

0 commit comments

Comments
 (0)