feat(perplexity): add perplexity app with send chat prompt action

This commit is contained in:
Ali BARIN
2025-01-22 13:23:04 +00:00
parent e686d3b067
commit adacdced8a
14 changed files with 292 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
import sendChatPrompt from './send-chat-prompt/index.js';
export default [sendChatPrompt];

View File

@@ -0,0 +1,185 @@
import defineAction from '../../../../helpers/define-action.js';
const castFloatOrUndefined = (value) => {
return value === '' ? undefined : parseFloat(value);
};
export default defineAction({
name: 'Send chat prompt',
key: 'sendChatPrompt',
description: `Generates a model's response for the given chat conversation.`,
arguments: [
{
label: 'Model',
key: 'model',
type: 'dropdown',
required: true,
variables: true,
options: [
{
label: 'Sonar Pro',
value: 'sonar-pro',
},
{
label: 'Sonar',
value: 'sonar',
},
],
},
{
label: 'Messages',
key: 'messages',
type: 'dynamic',
required: true,
description: 'Add or remove messages as needed',
value: [{ role: 'system', body: '' }],
fields: [
{
label: 'Role',
key: 'role',
type: 'dropdown',
required: true,
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: [
{
label: 'System',
value: 'system',
},
{
label: 'Assistant',
value: 'assistant',
},
{
label: 'User',
value: 'user',
},
],
},
{
label: 'Content',
key: 'content',
type: 'string',
required: true,
variables: true,
description:
'The contents of the message in this turn of conversation.',
},
],
},
{
label: 'Temperature',
key: 'temperature',
type: 'string',
required: false,
variables: true,
description:
'The amount of randomness in the response, valued between 0 inclusive and 2 exclusive. Higher values are more random, and lower values are more deterministic.',
},
{
label: 'Maximum tokens',
key: 'maxTokens',
type: 'string',
required: false,
variables: true,
description:
'The maximum number of tokens to generate in the completion.',
},
{
label: 'Top P',
key: 'topP',
type: 'string',
required: false,
variables: true,
description:
'The nucleus sampling threshold, valued between 0 and 1 inclusive. For each subsequent token, the model considers the results of the tokens with top_p probability mass. We recommend either altering top_k or top_p, but not both.',
},
{
label: 'Top K',
key: 'topK',
type: 'string',
required: false,
variables: true,
description:
'The number of tokens to keep for highest top-k filtering, specified as an integer between 0 and 2048 inclusive. If set to 0, top-k filtering is disabled. We recommend either altering top_k or top_p, but not both.',
},
{
label: 'Frequency Penalty',
key: 'frequencyPenalty',
type: 'string',
required: false,
variables: true,
description: `A multiplicative penalty greater than 0. Values greater than 1.0 penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. A value of 1.0 means no penalty. Incompatible with presence_penalty.`,
},
{
label: 'Presence Penalty',
key: 'presencePenalty',
type: 'string',
required: false,
variables: true,
description: `A value between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. Incompatible with frequency_penalty.`,
},
{
label: 'Return images',
key: 'returnImages',
type: 'dropdown',
required: false,
variables: true,
value: false,
options: [
{
label: 'Yes',
value: true,
},
{
label: 'No',
value: false,
},
],
},
{
label: 'Return related questions',
key: 'returnRelatedQuestions',
type: 'dropdown',
required: false,
variables: true,
value: false,
options: [
{
label: 'Yes',
value: true,
},
{
label: 'No',
value: false,
},
],
},
],
async run($) {
const payload = {
model: $.step.parameters.model,
temperature: castFloatOrUndefined($.step.parameters.temperature),
max_tokens: castFloatOrUndefined($.step.parameters.maxTokens),
top_p: castFloatOrUndefined($.step.parameters.topP),
top_k: castFloatOrUndefined($.step.parameters.topK),
frequency_penalty: castFloatOrUndefined(
$.step.parameters.frequencyPenalty
),
presence_penalty: castFloatOrUndefined($.step.parameters.presencePenalty),
messages: $.step.parameters.messages.map((message) => ({
role: message.role,
content: message.content,
})),
return_images: $.step.parameters.returnImages,
return_related_questions: $.step.parameters.returnRelatedQuestons,
};
const { data } = await $.http.post('/chat/completions', payload);
$.setActionItem({
raw: data,
});
},
});

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0.13 -0.15 77.31 92.56"><path d="M38.6936 29.9832L12.8633 5.88983V29.9832H38.6936Z" stroke-width="4.30504" stroke-miterlimit="10" stroke="#20b8cd"></path><path d="M39.5005 29.9832L65.3308 5.88983V29.9832H39.5005Z" stroke-width="4.30504" stroke-miterlimit="10" stroke="#20b8cd"></path><path d="M38.7227 2L38.7227 90.2534" stroke-width="4.30504" stroke-miterlimit="10" stroke="#20b8cd"></path><path d="M64.5246 53.7584L38.6943 30.0068V62.9404L64.5246 85.9724V53.7584Z" stroke-width="4.30504" stroke-miterlimit="10" stroke="#20b8cd"></path><path d="M12.8924 53.7584L38.7227 30.0068V62.9404L12.8924 85.9724V53.7584Z" stroke-width="4.30504" stroke-miterlimit="10" stroke="#20b8cd"></path><path d="M2.28711 29.9832V64.4236H12.8863V53.7348L38.7226 29.9832H2.28711Z" stroke-width="4.30504" stroke-miterlimit="10" stroke="#20b8cd"></path><path d="M38.6943 30.3L64.5246 54.0515V64.7403H75.2872V30.3L38.6943 30.3Z" stroke-width="4.30504" stroke-miterlimit="10" stroke="#20b8cd"></path></svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@@ -0,0 +1,34 @@
import verifyCredentials from './verify-credentials.js';
import isStillVerified from './is-still-verified.js';
export default {
fields: [
{
key: 'screenName',
label: 'Screen Name',
type: 'string',
required: true,
readOnly: false,
value: null,
placeholder: null,
description:
'Screen name of your connection to be used on Automatisch UI.',
clickToCopy: false,
},
{
key: 'apiKey',
label: 'API Key',
type: 'string',
required: true,
readOnly: false,
value: null,
placeholder: null,
description: 'Perplexity API key of your account.',
docUrl: 'https://automatisch.io/docs/perplexity#api-key',
clickToCopy: false,
},
],
verifyCredentials,
isStillVerified,
};

View File

@@ -0,0 +1,5 @@
const isStillVerified = async () => {
return true;
};
export default isStillVerified;

View File

@@ -0,0 +1,5 @@
const verifyCredentials = async () => {
return true;
};
export default verifyCredentials;

View File

@@ -0,0 +1,9 @@
const addAuthHeader = ($, requestConfig) => {
if ($.auth.data?.apiKey) {
requestConfig.headers.Authorization = `Bearer ${$.auth.data.apiKey}`;
}
return requestConfig;
};
export default addAuthHeader;

View File

@@ -0,0 +1,18 @@
import defineApp from '../../helpers/define-app.js';
import addAuthHeader from './common/add-auth-header.js';
import auth from './auth/index.js';
import actions from './actions/index.js';
export default defineApp({
name: 'Perplexity',
key: 'perplexity',
baseUrl: 'https://perplexity.ai',
apiBaseUrl: 'https://api.perplexity.ai',
iconUrl: '{BASE_URL}/apps/perplexity/assets/favicon.svg',
authDocUrl: '{DOCS_URL}/apps/perplexity/connection',
primaryColor: '#091717',
supportsConnections: true,
beforeRequest: [addAuthHeader],
auth,
actions,
});

View File

@@ -41,6 +41,7 @@ exports[`App model > list should have list of applications keys 1`] = `
"ntfy",
"odoo",
"openai",
"perplexity",
"pipedrive",
"placetel",
"postgresql",

View File

@@ -350,6 +350,15 @@ export default defineConfig({
{ text: 'Connection', link: '/apps/openai/connection' },
],
},
{
text: 'Perplexity',
collapsible: true,
collapsed: true,
items: [
{ text: 'Actions', link: '/apps/perplexity/actions' },
{ text: 'Connection', link: '/apps/perplexity/connection' },
],
},
{
text: 'Pipedrive',
collapsible: true,

View File

@@ -0,0 +1,12 @@
---
favicon: /favicons/perplexity.svg
items:
- name: Send chat prompt
desc: Generates a model's response for the given chat conversation.
---
<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>
<CustomListing />

View File

@@ -0,0 +1,8 @@
# Perplexity
1. Go to [API page](https://www.perplexity.ai/settings/api) on Perplexity.
2. Generate a new API key.
3. Paste the key into the `API Key` field in Automatisch.
4. Write any screen name to be displayed in Automatisch.
5. Click `Save`.
6. Start using Perplexity integration with Automatisch!

View File

@@ -35,6 +35,7 @@ The following integrations are currently supported by Automatisch.
- [Ntfy](/apps/ntfy/actions)
- [Odoo](/apps/odoo/actions)
- [OpenAI](/apps/openai/actions)
- [Perplexity](/apps/perplexity/actions)
- [Pipedrive](/apps/pipedrive/triggers)
- [Placetel](/apps/placetel/triggers)
- [PostgreSQL](/apps/postgresql/actions)

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0.13 -0.15 77.31 92.56"><path d="M38.6936 29.9832L12.8633 5.88983V29.9832H38.6936Z" stroke-width="4.30504" stroke-miterlimit="10" stroke="#20b8cd"></path><path d="M39.5005 29.9832L65.3308 5.88983V29.9832H39.5005Z" stroke-width="4.30504" stroke-miterlimit="10" stroke="#20b8cd"></path><path d="M38.7227 2L38.7227 90.2534" stroke-width="4.30504" stroke-miterlimit="10" stroke="#20b8cd"></path><path d="M64.5246 53.7584L38.6943 30.0068V62.9404L64.5246 85.9724V53.7584Z" stroke-width="4.30504" stroke-miterlimit="10" stroke="#20b8cd"></path><path d="M12.8924 53.7584L38.7227 30.0068V62.9404L12.8924 85.9724V53.7584Z" stroke-width="4.30504" stroke-miterlimit="10" stroke="#20b8cd"></path><path d="M2.28711 29.9832V64.4236H12.8863V53.7348L38.7226 29.9832H2.28711Z" stroke-width="4.30504" stroke-miterlimit="10" stroke="#20b8cd"></path><path d="M38.6943 30.3L64.5246 54.0515V64.7403H75.2872V30.3L38.6943 30.3Z" stroke-width="4.30504" stroke-miterlimit="10" stroke="#20b8cd"></path></svg>

After

Width:  |  Height:  |  Size: 1.0 KiB