-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 63d86cc
Showing
17 changed files
with
2,583 additions
and
0 deletions.
There are no files selected for viewing
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,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 |
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,3 @@ | ||
node_modules/ | ||
|
||
main.js |
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,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" | ||
} | ||
} |
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,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/*' |
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,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 | ||
|
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 @@ | ||
tag-version-prefix="" |
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,7 @@ | ||
{ | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"tabWidth": 2, | ||
"printWidth": 80 | ||
} |
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,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. | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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(); | ||
} |
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,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 }; |
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,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 | ||
} |
Oops, something went wrong.