-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
131 additions
and
8 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
components/perplexity/actions/chat-completions/chat-completions.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [ | ||
|
@@ -11,5 +11,8 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^1.6.5" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}, | ||
}, | ||
}; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.