generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Showing
7 changed files
with
458 additions
and
2 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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
@import "completers/openai/openai.sass" | ||
@import "completers/chatgpt/chatgpt.sass" | ||
@import "completers/chatgpt/chatgpt.sass" | ||
@import "completers/ai21/ai21.sass" |
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { Completer } from "./complete"; | ||
import { OpenAIComplete } from "./completers/openai/openai"; | ||
import { ChatGPTComplete } from "./completers/chatgpt/chatgpt"; | ||
import { JurassicJ2Complete } from "./completers/ai21/ai21"; | ||
|
||
export const available: Completer[] = [ | ||
new ChatGPTComplete(), | ||
new OpenAIComplete(), | ||
new JurassicJ2Complete(), | ||
]; |
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,5 @@ | ||
.ai-complete-jurassic-expandable | ||
display: flex | ||
flex-direction: row | ||
align-items: center | ||
gap: 0.5rem |
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,72 @@ | ||
import { Completer, Model, Prompt } from "../../complete"; | ||
import available_models from "./models.json"; | ||
import { | ||
SettingsUI as ProviderSettingsUI, | ||
Settings, | ||
parse_settings, | ||
} from "./provider_settings"; | ||
|
||
export default class J2Model implements Model { | ||
id: string; | ||
name: string; | ||
description: string; | ||
|
||
provider_settings: Settings; | ||
|
||
constructor( | ||
id: string, | ||
name: string, | ||
description: string, | ||
provider_settings: string | ||
) { | ||
this.id = id; | ||
this.name = name; | ||
this.description = description; | ||
this.provider_settings = parse_settings(provider_settings); | ||
} | ||
|
||
async complete(prompt: Prompt): Promise<string> { | ||
if (this.provider_settings.api_key === "") { | ||
throw new Error("API Key not set"); | ||
} | ||
const response = await fetch( | ||
`https://api.ai21.com/studio/v1/j2-${this.id}/complete`, | ||
{ | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${this.provider_settings.api_key}`, | ||
}, | ||
body: JSON.stringify({ | ||
prompt: prompt.prefix, | ||
numResults: 1, | ||
...this.provider_settings.generation_settings, | ||
}), | ||
} | ||
); | ||
if (!response.ok) { | ||
throw new Error( | ||
`Jurassic-j2 API returned ${response.status} ${ | ||
(await response.json()).detail | ||
}` | ||
); | ||
} | ||
const data = await response.json(); | ||
return data.completions[0].data.text; | ||
} | ||
} | ||
|
||
export class JurassicJ2Complete implements Completer { | ||
id: string = "jurassic"; | ||
name: string = "AI21 Jurassic"; | ||
description: string = "AI21's Jurassic-j2 models"; | ||
|
||
async get_models(settings: string) { | ||
return available_models.map( | ||
(model) => | ||
new J2Model(model.id, model.name, model.description, settings) | ||
); | ||
} | ||
|
||
Settings = ProviderSettingsUI; | ||
} |
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,17 @@ | ||
[ | ||
{ | ||
"id": "large", | ||
"name": "J2-Large", | ||
"description": "Designed for fast responses." | ||
}, | ||
{ | ||
"id": "grande", | ||
"name": "J2-Grande", | ||
"description": "Offers enhanced text generation capabilities, making it well-suited to language tasks with a greater degree of complexity." | ||
}, | ||
{ | ||
"id": "jumbo", | ||
"name": "J2-Jumbo", | ||
"description": "As the largest and most powerful model in the Jurassic series, J2-Jumbo is an ideal choice for the most complex language processing tasks and generative text applications." | ||
} | ||
] |
Oops, something went wrong.