Skip to content

Commit 7bd4d1a

Browse files
committed
init
0 parents  commit 7bd4d1a

17 files changed

+2677
-0
lines changed

.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
insert_final_newline = true
8+
indent_style = tab
9+
indent_size = 4
10+
tab_width = 4

.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
3+
main.js

.eslintrc

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"env": { "node": true },
5+
"plugins": [
6+
"@typescript-eslint",
7+
"prettier"
8+
],
9+
"extends": [
10+
"eslint:recommended",
11+
"plugin:@typescript-eslint/eslint-recommended",
12+
"plugin:@typescript-eslint/recommended",
13+
"prettier"
14+
],
15+
"parserOptions": {
16+
"sourceType": "module"
17+
},
18+
"rules": {
19+
"no-unused-vars": "off",
20+
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
21+
"@typescript-eslint/ban-ts-comment": "off",
22+
"no-prototype-builtins": "off",
23+
"@typescript-eslint/no-empty-function": "off",
24+
"prettier/prettier": "error"
25+
}
26+
}
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
inputs:
9+
releaseVersion:
10+
description: 'Release Version (e.g., v1.0.0)'
11+
required: true
12+
13+
jobs:
14+
release:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: '21'
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Build
29+
run: npm run build
30+
31+
- name: Create Release
32+
id: create_release
33+
uses: ncipollo/release-action@v1
34+
with:
35+
token: ${{ secrets.GH_TOKEN }}
36+
tag: ${{ github.event.inputs.releaseVersion || github.ref_name }}
37+
name: Release ${{ github.event.inputs.releaseVersion || github.ref_name }}
38+
draft: false
39+
prerelease: false
40+
artifacts: 'build/*'

.gitignore

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# vscode
2+
.vscode
3+
4+
# Intellij
5+
*.iml
6+
.idea
7+
8+
# npm
9+
node_modules
10+
11+
# Don't include the compiled main.js file in the repo.
12+
# They should be uploaded to GitHub releases instead.
13+
main.js
14+
15+
# Exclude sourcemaps
16+
*.map
17+
18+
# obsidian
19+
data.json
20+
21+
# Exclude macOS Finder (System Explorer) View States
22+
.DS_Store

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tag-version-prefix=""

.prettierrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"trailingComma": "all",
5+
"tabWidth": 2,
6+
"printWidth": 80
7+
}

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Prompt Mixer - Preplexite AI Connector
2+
3+
This connector allows you to access Preplexite's AI API from within Prompt Mixer.
4+
5+
## Features
6+
7+
- Send prompts to Preplexite's generative AI models and display responses
8+
- Supports text completion, generation, and classification tasks
9+
- Configure timeouts, max tokens, temperature, etc.
10+
11+
## Getting Started
12+
13+
1. Sign up for an API key at [Preplexite](https://docs.perplexity.ai/docs/getting-started)
14+
2. Install this connector in Prompt Mixer
15+
- Open Connectors sidebar
16+
- Search for "Preplexite"
17+
- Install
18+
3. Configure your API key
19+
- Open connector settings
20+
- Paste in your API key
21+
4. Start using Preplexite generative AI models in your prompts
22+
23+
## Usage
24+
25+
Once configured, you can access Preplexite AI by:
26+
27+
- Selecting "Preplexite AI" from the models dropdown
28+
29+
## Contributing
30+
31+
Pull requests welcome!
32+
33+
## License
34+
35+
This project is licensed under the MIT license.

config.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
export const config = {
2+
connectorName: 'Perplexity Connector',
3+
models: [
4+
'sonar-small-chat',
5+
'sonar-small-online',
6+
'sonar-medium-chat',
7+
'sonar-medium-online',
8+
'mistral-7b-instruct',
9+
'mixtral-8x7b-instruct',
10+
],
11+
properties: [
12+
{
13+
id: 'max_tokens',
14+
name: 'Max Tokens',
15+
value: 2048,
16+
type: 'number',
17+
},
18+
{
19+
id: 'temperature',
20+
name: 'Temperature',
21+
value: 1,
22+
type: 'number',
23+
},
24+
{
25+
id: 'top_p',
26+
name: 'Top P',
27+
value: 1,
28+
type: 'number',
29+
},
30+
{
31+
id: 'top_k',
32+
name: 'Top K',
33+
value: 0,
34+
type: 'number',
35+
},
36+
{
37+
id: 'frequency_penalty',
38+
name: 'Frequency Penalty',
39+
value: 0.5,
40+
type: 'number',
41+
},
42+
{
43+
id: 'presence_penalty',
44+
name: 'Presence Penalty',
45+
value: 0.5,
46+
type: 'number',
47+
},
48+
],
49+
settings: [
50+
{
51+
id: 'API_KEY',
52+
name: 'API Key',
53+
value: '',
54+
type: 'string',
55+
},
56+
],
57+
description:
58+
'This connector allows you to access Preplexite AI API from within Prompt Mixer.',
59+
author: 'Prompt Mixer',
60+
iconBase64:
61+
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTExLjMxOTIgMi4xOTcwOEw4LjAwMDM1IDUuNTE5MDRIMTEuMzE5MlYyLjE5NzA4Wk0xMS4zMTkyIDIuMTk3MDhWMy4xMDY1Nk03Ljk5MjY2IDEuNzA4NDRWMTQuMjkxNk0xMS4zMTkyIDguODQwMjlMOC4wMDAzNSA1LjUxODM0TTExLjMxOTIgOC44NDAyOVYxMy42MDI3TDguMDAwMzUgMTAuMjgwN00xMS4zMTkyIDguODQwMjlMOCA1LjUxODM0TTExLjMxOTIgOC44NDAyOUwxMS4zMTg4IDEwLjI2MTVIMTIuNzQzMlY1LjUxODM0SDhNOC4wMDAzNSA1LjUxODM0VjEwLjI4MDdNOC4wMDAzNSA1LjUxODM0TDQuNjgxMiA4Ljg0MDI5TTguMDAwMzUgMTAuMjgwN0w0LjY4MTIgMTMuNjAyN1Y4Ljg0MDI5TTQuNjgxMiA4Ljg0MDI5TDQuNjgwODUgMTAuMjYxNUgzLjI1Njg1VjUuNTE4MzRIOE00LjY4MTIgOC44NDAyOUw4IDUuNTE4MzRNOCA1LjUxOTA0TDQuNjgwODUgMi4xOTcwOFY1LjUxOTA0SDhaIiBzdHJva2U9IiM2RjczN0EiIHN0cm9rZS13aWR0aD0iMC41IiBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiLz4KPC9zdmc+Cg==',
62+
};

esbuild.config.mjs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import esbuild from 'esbuild';
2+
import process from 'process';
3+
4+
const prod = process.argv[2] === 'production';
5+
6+
const context = await esbuild.context({
7+
entryPoints: ['main.ts'],
8+
bundle: true,
9+
platform: 'node',
10+
target: 'es6',
11+
outfile: './build/main.js',
12+
});
13+
14+
if (prod) {
15+
await context.rebuild();
16+
process.exit(0);
17+
} else {
18+
await context.watch();
19+
}

main.ts

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import { config } from './config.js';
2+
3+
const API_KEY = 'API_KEY';
4+
5+
interface Message {
6+
role: 'system' | 'user' | 'assistant';
7+
content: string;
8+
}
9+
10+
interface Completion {
11+
Content: string | null;
12+
TokenUsage: number | undefined;
13+
}
14+
15+
interface ConnectorResponse {
16+
Completions: Completion[];
17+
ModelType: string;
18+
}
19+
20+
interface PreplexiteResponse {
21+
id: string;
22+
model: string;
23+
created: number;
24+
usage: {
25+
prompt_tokens: number;
26+
completion_tokens: number;
27+
total_tokens: number;
28+
};
29+
object: string;
30+
choices: {
31+
index: number;
32+
finish_reason: string;
33+
message: {
34+
role: string;
35+
content: string;
36+
};
37+
delta: {
38+
role: string;
39+
content: string;
40+
};
41+
}[];
42+
}
43+
44+
const mapToResponse = (outputs: PreplexiteResponse[]): ConnectorResponse => {
45+
return {
46+
Completions: outputs.map((output) => ({
47+
Content: output.choices[0].message.content,
48+
TokenUsage: output.usage.total_tokens,
49+
})),
50+
ModelType: outputs[0].model,
51+
};
52+
};
53+
54+
async function main(
55+
model: string,
56+
prompts: string[],
57+
properties: Record<string, unknown>,
58+
settings: Record<string, unknown>,
59+
): Promise<ConnectorResponse> {
60+
const apiKey = settings?.[API_KEY] as string;
61+
62+
const messageHistory: Message[] = [];
63+
const outputs: PreplexiteResponse[] = [];
64+
65+
try {
66+
for (const prompt of prompts) {
67+
messageHistory.push({ role: 'user', content: prompt });
68+
69+
const response = await fetch(
70+
'https://api.perplexity.ai/chat/completions',
71+
{
72+
method: 'POST',
73+
headers: {
74+
'Content-Type': 'application/json',
75+
Authorization: `Bearer ${apiKey}`,
76+
},
77+
body: JSON.stringify({
78+
model: model,
79+
messages: messageHistory,
80+
...properties,
81+
}),
82+
},
83+
);
84+
85+
const data: PreplexiteResponse = await response.json();
86+
87+
const assistantResponse = data.choices[0].message.content;
88+
89+
messageHistory.push({ role: 'assistant', content: assistantResponse });
90+
91+
outputs.push(data);
92+
}
93+
94+
return mapToResponse(outputs);
95+
} catch (error) {
96+
console.error('Error in main function:', error);
97+
throw error;
98+
}
99+
}
100+
101+
export { main, config };

manifest.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"id": "prompt-mixer-preplexite-connector",
3+
"name": "Preplexite Prompt Mixer Connector",
4+
"version": "1.0.0",
5+
"minAppVersion": "0.1.0",
6+
"description": "This connector allows you to access Preplexite's AI API from within Prompt Mixer.",
7+
"author": "Prompt Mixer",
8+
"authorUrl": "",
9+
"fundingUrl": "",
10+
"isDesktopOnly": true
11+
}

0 commit comments

Comments
 (0)