Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
tomatyss committed Apr 3, 2024
0 parents commit 63d86cc
Show file tree
Hide file tree
Showing 17 changed files with 2,583 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# top-most EditorConfig file
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = tab
indent_size = 4
tab_width = 4
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/

main.js
26 changes: 26 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"env": { "node": true },
"plugins": [
"@typescript-eslint",
"prettier"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
"@typescript-eslint/ban-ts-comment": "off",
"no-prototype-builtins": "off",
"@typescript-eslint/no-empty-function": "off",
"prettier/prettier": "error"
}
}
40 changes: 40 additions & 0 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Build and Release

on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
releaseVersion:
description: 'Release Version (e.g., v1.0.0)'
required: true

jobs:
release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '21'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Create Release
id: create_release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GH_TOKEN }}
tag: ${{ github.event.inputs.releaseVersion || github.ref_name }}
name: Release ${{ github.event.inputs.releaseVersion || github.ref_name }}
draft: false
prerelease: false
artifacts: 'build/*'
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# vscode
.vscode

# Intellij
*.iml
.idea

# npm
node_modules
build

# Don't include the compiled main.js file in the repo.
# They should be uploaded to GitHub releases instead.
main.js

# Exclude sourcemaps
*.map

# obsidian
data.json

# Exclude macOS Finder (System Explorer) View States
.DS_Store

1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tag-version-prefix=""
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"tabWidth": 2,
"printWidth": 80
}
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# AI21 Jurassic-2 Connector

This connector allows you to access AI21 Labs' Jurassic-2 language model from within Prompt Mixer.

## Features

- Send prompts to the Jurassic-2 language model and display responses
- Supports text completion and text classification tasks
- Configure timeouts, max tokens, temperature, and other settings
- View usage statistics for your AI21 account

## Getting Started

1. Sign up for an API key at [AI21 Labs](https://www.ai21.com/)
2. Install this connector in Prompt Mixer:
- Open the Connectors sidebar
- Search for "AI21 Jurassic-2"
- Install the connector
3. Configure your API key:
- Open the connector settings
- Paste in your API key
4. Start using the Jurassic-2 language model in your prompts

## Usage

Once configured, you can access the Jurassic-2 language model by selecting "j2-ultra" from the models dropdown.

## Contributing

Pull requests are welcome!

## License

This project is licensed under the MIT license.

37 changes: 37 additions & 0 deletions config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import esbuild from 'esbuild';
import process from 'process';

const prod = process.argv[2] === 'production';

const context = await esbuild.context({
entryPoints: ['main.ts'],
bundle: true,
platform: 'node',
target: 'es6',
outfile: './build/main.js',
});

if (prod) {
await context.rebuild();
process.exit(0);
} else {
await context.watch();
}
94 changes: 94 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { config } from './config.js';

const API_KEY = 'API_KEY';

interface Message {
text: string;
role: 'system' | 'user' | 'assistant';
}

interface Completion {
Content: string | null;
TokenUsage: number | undefined;
}

interface ConnectorResponse {
Completions: Completion[];
ModelType: string;
}

interface Response {
id: string;
outputs: {
text: string;
role: string;
}[];
}

const mapToResponse = (apiResponses: Response[]): ConnectorResponse => {
const Completions = apiResponses.flatMap(response =>
response.outputs.map(output => ({
Content: output.text,
TokenUsage: undefined,
}))
);

const ModelType = 'j2-ultra';

return { Completions, ModelType };
};

async function main(
model: string,
prompts: string[],
properties: Record<string, unknown>,
settings: Record<string, unknown>,
): Promise<ConnectorResponse> {
const apiKey = settings?.[API_KEY] as string;

const { prompt, ...restProperties } = properties;
const systemPrompt = (prompt ||
config.properties.find((prop) => prop.id === 'prompt')?.value) as string;

const messageHistory: Message[] = [];
const apiResponses: Response[] = [];

try {
for (const prompt of prompts) {
messageHistory.push({ role: 'user', text: prompt });

const response = await fetch(
'https://api.ai21.com/studio/v1/j2-ultra/chat',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`,
},
body: JSON.stringify({
messages: messageHistory,
'system': systemPrompt,
...restProperties,
}),
},
);

const data: Response = await response.json();

data.outputs.forEach(output => {
if (output.role === 'assistant') {
messageHistory.push({ role: 'assistant', text: output.text });
}
});

apiResponses.push(data);
}

return mapToResponse(apiResponses);
} catch (error) {
console.error('Error in main function:', error);
throw error;
}
}

export { main, config };
11 changes: 11 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": "prompt-mixer-ai21-connector",
"name": "AI21 Prompt Mixer Connector",
"version": "1.0.0",
"minAppVersion": "0.1.0",
"description": "AI21 Jurassic-2 Connector: Seamlessly integrates the powerful Jurassic-2 language model from AI21 Labs into your applications.",
"author": "Prompt Mixer",
"authorUrl": "",
"fundingUrl": "",
"isDesktopOnly": true
}
Loading

0 comments on commit 63d86cc

Please sign in to comment.