Skip to content

Commit

Permalink
Auto save settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Zero Liu committed Nov 30, 2024
1 parent 68b8ad7 commit b1a662b
Show file tree
Hide file tree
Showing 43 changed files with 905 additions and 1,328 deletions.
21 changes: 21 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"crypto-js": "^4.1.1",
"esbuild-plugin-svg": "^0.1.0",
"eventsource-parser": "^1.0.0",
"jotai": "^2.10.3",
"koa": "^2.14.2",
"koa-proxies": "^0.12.3",
"langchain": "^0.3.2",
Expand Down
20 changes: 7 additions & 13 deletions src/LLMProviders/brevilabsClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BREVILABS_API_BASE_URL } from "@/constants";
import { Notice } from "obsidian";

import { getSettings } from "@/settings/model";
import { getDecryptedKey } from "@/encryptionService";
export interface BrocaResponse {
response: {
tool_calls: Array<{
Expand Down Expand Up @@ -59,23 +60,16 @@ export interface Youtube4llmResponse {

export class BrevilabsClient {
private static instance: BrevilabsClient;
private licenseKey: string;
private options: any;

private constructor(licenseKey: string, options?: { debug?: boolean }) {
this.licenseKey = licenseKey;
this.options = options;
}

static getInstance(licenseKey: string, options?: { debug?: boolean }): BrevilabsClient {
static getInstance(): BrevilabsClient {
if (!BrevilabsClient.instance) {
BrevilabsClient.instance = new BrevilabsClient(licenseKey, options);
BrevilabsClient.instance = new BrevilabsClient();
}
return BrevilabsClient.instance;
}

private checkLicenseKey() {
if (!this.licenseKey) {
if (!getSettings().plusLicenseKey) {
new Notice(
"Copilot Plus license key not found. Please enter your license key in the settings."
);
Expand All @@ -98,13 +92,13 @@ export class BrevilabsClient {
method,
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${this.licenseKey}`,
Authorization: `Bearer ${getDecryptedKey(getSettings().plusLicenseKey)}`,
},
...(method === "POST" && { body: JSON.stringify(body) }),
});

const data = await response.json();
if (this.options?.debug) {
if (getSettings().debug) {
console.log(`==== ${endpoint} request ====:`, data);
}

Expand Down
Loading

0 comments on commit b1a662b

Please sign in to comment.