Skip to content

Commit 63d86cc

Browse files
committed
init
0 parents  commit 63d86cc

17 files changed

+2583
-0
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
3+
main.js

.eslintrc

Lines changed: 26 additions & 0 deletions
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+
}
Lines changed: 40 additions & 0 deletions
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

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

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tag-version-prefix=""

.prettierrc

Lines changed: 7 additions & 0 deletions
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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# AI21 Jurassic-2 Connector
2+
3+
This connector allows you to access AI21 Labs' Jurassic-2 language model from within Prompt Mixer.
4+
5+
## Features
6+
7+
- Send prompts to the Jurassic-2 language model and display responses
8+
- Supports text completion and text classification tasks
9+
- Configure timeouts, max tokens, temperature, and other settings
10+
- View usage statistics for your AI21 account
11+
12+
## Getting Started
13+
14+
1. Sign up for an API key at [AI21 Labs](https://www.ai21.com/)
15+
2. Install this connector in Prompt Mixer:
16+
- Open the Connectors sidebar
17+
- Search for "AI21 Jurassic-2"
18+
- Install the connector
19+
3. Configure your API key:
20+
- Open the connector settings
21+
- Paste in your API key
22+
4. Start using the Jurassic-2 language model in your prompts
23+
24+
## Usage
25+
26+
Once configured, you can access the Jurassic-2 language model by selecting "j2-ultra" from the models dropdown.
27+
28+
## Contributing
29+
30+
Pull requests are welcome!
31+
32+
## License
33+
34+
This project is licensed under the MIT license.
35+

config.js

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

esbuild.config.mjs

Lines changed: 19 additions & 0 deletions
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

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { config } from './config.js';
2+
3+
const API_KEY = 'API_KEY';
4+
5+
interface Message {
6+
text: string;
7+
role: 'system' | 'user' | 'assistant';
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 Response {
21+
id: string;
22+
outputs: {
23+
text: string;
24+
role: string;
25+
}[];
26+
}
27+
28+
const mapToResponse = (apiResponses: Response[]): ConnectorResponse => {
29+
const Completions = apiResponses.flatMap(response =>
30+
response.outputs.map(output => ({
31+
Content: output.text,
32+
TokenUsage: undefined,
33+
}))
34+
);
35+
36+
const ModelType = 'j2-ultra';
37+
38+
return { Completions, ModelType };
39+
};
40+
41+
async function main(
42+
model: string,
43+
prompts: string[],
44+
properties: Record<string, unknown>,
45+
settings: Record<string, unknown>,
46+
): Promise<ConnectorResponse> {
47+
const apiKey = settings?.[API_KEY] as string;
48+
49+
const { prompt, ...restProperties } = properties;
50+
const systemPrompt = (prompt ||
51+
config.properties.find((prop) => prop.id === 'prompt')?.value) as string;
52+
53+
const messageHistory: Message[] = [];
54+
const apiResponses: Response[] = [];
55+
56+
try {
57+
for (const prompt of prompts) {
58+
messageHistory.push({ role: 'user', text: prompt });
59+
60+
const response = await fetch(
61+
'https://api.ai21.com/studio/v1/j2-ultra/chat',
62+
{
63+
method: 'POST',
64+
headers: {
65+
'Content-Type': 'application/json',
66+
'Authorization': `Bearer ${apiKey}`,
67+
},
68+
body: JSON.stringify({
69+
messages: messageHistory,
70+
'system': systemPrompt,
71+
...restProperties,
72+
}),
73+
},
74+
);
75+
76+
const data: Response = await response.json();
77+
78+
data.outputs.forEach(output => {
79+
if (output.role === 'assistant') {
80+
messageHistory.push({ role: 'assistant', text: output.text });
81+
}
82+
});
83+
84+
apiResponses.push(data);
85+
}
86+
87+
return mapToResponse(apiResponses);
88+
} catch (error) {
89+
console.error('Error in main function:', error);
90+
throw error;
91+
}
92+
}
93+
94+
export { main, config };

manifest.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"id": "prompt-mixer-ai21-connector",
3+
"name": "AI21 Prompt Mixer Connector",
4+
"version": "1.0.0",
5+
"minAppVersion": "0.1.0",
6+
"description": "AI21 Jurassic-2 Connector: Seamlessly integrates the powerful Jurassic-2 language model from AI21 Labs into your applications.",
7+
"author": "Prompt Mixer",
8+
"authorUrl": "",
9+
"fundingUrl": "",
10+
"isDesktopOnly": true
11+
}

0 commit comments

Comments
 (0)