Skip to content

Commit 1110202

Browse files
authored
Added actions (#11808)
1 parent 8d49749 commit 1110202

File tree

5 files changed

+120
-8
lines changed

5 files changed

+120
-8
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import app from "../../perplexity.app.mjs";
2+
3+
export default {
4+
key: "perplexity-chat-completions",
5+
name: "Chat Completions",
6+
description: "Generates a model's response for the given chat conversation. [See the documentation](https://docs.perplexity.ai/reference/post_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+
content: {
18+
propDefinition: [
19+
app,
20+
"content",
21+
],
22+
},
23+
role: {
24+
propDefinition: [
25+
app,
26+
"role",
27+
],
28+
},
29+
},
30+
async run({ $ }) {
31+
const response = await this.app.chatCompletions({
32+
$,
33+
data: {
34+
model: this.model,
35+
messages: [
36+
{
37+
role: this.role,
38+
content: this.content,
39+
},
40+
],
41+
},
42+
});
43+
44+
$.export("$summary", "Successfully generated a response from the selected model");
45+
46+
return response;
47+
},
48+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default {
2+
MODELS: [
3+
"sonar-small-chat",
4+
"sonar-small-online",
5+
"sonar-medium-chat",
6+
"sonar-medium-online",
7+
"mistral-7b-instruct",
8+
"mixtral-8x7b-instruct",
9+
],
10+
ROLES: [
11+
"system",
12+
"user",
13+
"assistant",
14+
],
15+
};

components/perplexity/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/perplexity",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Perplexity Components",
55
"main": "perplexity.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^1.6.5"
1417
}
15-
}
18+
}
Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,54 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "perplexity",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
model: {
9+
type: "string",
10+
label: "Model",
11+
description: "The name of the model that will complete your prompt",
12+
options: constants.MODELS,
13+
},
14+
content: {
15+
type: "string",
16+
label: "Content",
17+
description: "The contents of the message in this turn of conversation",
18+
},
19+
role: {
20+
type: "string",
21+
label: "Role",
22+
description: "The role of the speaker in this turn of conversation. After the (optional) system message, user and assistant roles should alternate with 'user' then 'assistant', ending in 'user'.",
23+
options: constants.ROLES,
24+
},
25+
},
526
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
27+
_baseUrl() {
28+
return "https://api.perplexity.ai";
29+
},
30+
async _makeRequest(opts = {}) {
31+
const {
32+
$ = this,
33+
path,
34+
headers,
35+
...otherOpts
36+
} = opts;
37+
return axios($, {
38+
...otherOpts,
39+
url: this._baseUrl() + path,
40+
headers: {
41+
...headers,
42+
Authorization: `Bearer ${this.$auth.api_key}`,
43+
},
44+
});
45+
},
46+
async chatCompletions(args = {}) {
47+
return this._makeRequest({
48+
method: "post",
49+
path: "/chat/completions",
50+
...args,
51+
});
952
},
1053
},
11-
};
54+
};

pnpm-lock.yaml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)