Skip to content

Commit

Permalink
Added actions
Browse files Browse the repository at this point in the history
  • Loading branch information
lcaresia committed May 2, 2024
1 parent 102ab54 commit abeb4b4
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import app from "../../perplexity.app.mjs";

export default {
key: "perplexity-chat-completions",
name: "Chat Completions",
description: "Generates a model's response for the given chat conversation. [See the documentation](https://docs.perplexity.ai/reference/post_chat_completions)",
version: "0.0.1",
type: "action",
props: {
app,
model: {
propDefinition: [
app,
"model",
],
},
content: {
propDefinition: [
app,
"content",
],
},
role: {
propDefinition: [
app,
"role",
],
},
},
async run({ $ }) {
const response = await this.app.chatCompletions({
$,
data: {
model: this.model,
messages: [
{
role: this.role,
content: this.content,
},
],
},
});

$.export("$summary", "Successfully generated a response from the selected model");

return response;
},
};
15 changes: 15 additions & 0 deletions components/perplexity/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
MODELS: [
"sonar-small-chat",
"sonar-small-online",
"sonar-medium-chat",
"sonar-medium-online",
"mistral-7b-instruct",
"mixtral-8x7b-instruct",
],
ROLES: [
"system",
"user",
"assistant",
],
};
7 changes: 5 additions & 2 deletions components/perplexity/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/perplexity",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Perplexity Components",
"main": "perplexity.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.6.5"
}
}
}
53 changes: 48 additions & 5 deletions components/perplexity/perplexity.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,54 @@
import { axios } from "@pipedream/platform";
import constants from "./common/constants.mjs";

export default {
type: "app",
app: "perplexity",
propDefinitions: {},
propDefinitions: {
model: {
type: "string",
label: "Model",
description: "The name of the model that will complete your prompt",
options: constants.MODELS,
},
content: {
type: "string",
label: "Content",
description: "The contents of the message in this turn of conversation",
},
role: {
type: "string",
label: "Role",
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'.",
options: constants.ROLES,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.perplexity.ai";
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
...headers,
Authorization: `Bearer ${this.$auth.api_key}`,
},
});
},
async chatCompletions(args = {}) {
return this._makeRequest({
method: "post",
path: "/chat/completions",
...args,
});
},
},
};
};
16 changes: 15 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit abeb4b4

Please sign in to comment.