Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Components] perplexity #11743 #11808

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading