diff --git a/common.ts b/common.ts index f08cef2..9b89172 100644 --- a/common.ts +++ b/common.ts @@ -8,6 +8,7 @@ export const PROVIDERS = [ "azure-chat", "anthropic", "openrouter", + "openpipe", ]; export type Provider = (typeof PROVIDERS)[number]; @@ -19,6 +20,7 @@ type ProviderProps = { "azure-chat": { url: string }; anthropic: { url: string }; openrouter: { quantization: string }; + openpipe: { url: string }; }; type SharedPresetSettings = { diff --git a/main.ts b/main.ts index 1f55d2f..44cefc8 100644 --- a/main.ts +++ b/main.ts @@ -1325,6 +1325,7 @@ export default class LoomPlugin extends Plugin { "azure-chat": this.completeAzureChat, anthropic: this.completeAnthropic, openrouter: this.completeOpenRouter, + openpipe: this.completeOpenPipe, }; let result; try { @@ -1568,6 +1569,46 @@ export default class LoomPlugin extends Plugin { return result; } + async completeOpenPipe(prompt: string) { + prompt = this.trimOpenAIPrompt(prompt); + + //openpipe doesn't support best-of through the api, according to docs + let body: any = { + model: getPreset(this.settings).model, + messages: [{ role: "user", content: prompt }], + max_tokens: this.settings.maxTokens, + n: this.settings.n, + temperature: this.settings.temperature, + top_p: this.settings.topP + }; + if (this.settings.frequencyPenalty !== 0) + body.frequency_penalty = this.settings.frequencyPenalty; + if (this.settings.presencePenalty !== 0) + body.presence_penalty = this.settings.presencePenalty; + + const response = await requestUrl({ + url: "https://api.openpipe.ai/api/v1/chat/completions", + method: "POST", + headers: { + Authorization: `Bearer ${getPreset(this.settings).apiKey}`, + "Content-Type": "application/json", + }, + throw: false, + body: JSON.stringify(body), + }); + + const result: CompletionResult = + response.status === 200 + ? { + ok: true, + completions: response.json.choices.map( + (choice: any) => choice.message.content + ), + } + : { ok: false, status: response.status, message: response.json.error?.message || "" }; + return result; + } + async completeOpenRouter(prompt: string) { prompt = this.trimOpenAIPrompt(prompt); @@ -2169,6 +2210,7 @@ class LoomSettingTab extends PluginSettingTab { const options: Record = { "openai-compat": "OpenAI-compatible API", "openrouter": "OpenRouter", + openpipe: "OpenPipe", anthropic: "Anthropic", openai: "OpenAI", "openai-chat": "OpenAI (Chat)",