Skip to content

Openpipe extend #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const PROVIDERS = [
"azure-chat",
"anthropic",
"openrouter",
"openpipe",
];
export type Provider = (typeof PROVIDERS)[number];

Expand All @@ -19,6 +20,7 @@ type ProviderProps = {
"azure-chat": { url: string };
anthropic: { url: string };
openrouter: { quantization: string };
openpipe: { url: string };
};

type SharedPresetSettings = {
Expand Down
42 changes: 42 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -2169,6 +2210,7 @@ class LoomSettingTab extends PluginSettingTab {
const options: Record<string, string> = {
"openai-compat": "OpenAI-compatible API",
"openrouter": "OpenRouter",
openpipe: "OpenPipe",
anthropic: "Anthropic",
openai: "OpenAI",
"openai-chat": "OpenAI (Chat)",
Expand Down