Skip to content

Commit

Permalink
feat: point to server
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminshafii committed Apr 9, 2024
1 parent 7da3a15 commit 305f967
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 19 deletions.
17 changes: 17 additions & 0 deletions src/FileOrganizerSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,23 @@ export class FileOrganizerSettingTab extends PluginSettingTab {
);

new Setting(containerEl).setName("Experimental features").setHeading();
new Setting(containerEl)
.setName("Custom Server URL")
.setDesc(
"You can run this locally by going on the File Organizer 2000 repo and following the GitHub instructions."
)
.addText((text) =>
text
.setPlaceholder("Enter your server URL")
.setValue(
this.plugin.settings.customServerUrl ||
"file-organizer-2000.vercel.app"
)
.onChange(async (value) => {
this.plugin.settings.customServerUrl = value;
await this.plugin.saveSettings();
})
);

new Setting(containerEl)
.setName("Custom vision prompt")
Expand Down
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class FileOrganizerSettings {
useSimilarTags = true; // default value is true
customVisionPrompt = ""; // default value is an empty string
useAutoAppend = false; // default value is true
customServerUrl = "app.fileorganizer2000.com";
}

const validAudioExtensions = ["mp3", "wav", "webm", "m4a"];
Expand Down Expand Up @@ -190,9 +191,12 @@ export default class FileOrganizer extends Plugin {
async generateTranscriptFromAudio(file: TFile) {
new Notice(`Generating transcription for ${file.basename}`, 3000);
// @ts-ignore
const filePath = file.vault.adapter.basePath + "/" + file.path;
const arrayBuffer = await this.app.vault.readBinary(file);
const fileContent = Buffer.from(arrayBuffer);
const encodedAudio = fileContent.toString("base64");
logMessage(`Encoded: ${encodedAudio.substring(0, 20)}...`);

const transcribedText = await useAudio(filePath);
const transcribedText = await useAudio(encodedAudio);
const postProcessedText = transcribedText;
this.appendToCustomLogFile(
`Generated transcription for [[${file.basename}.${file.extension}]]`
Expand Down
35 changes: 24 additions & 11 deletions src/modules/audio.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
async function useAudio(filePath: string) {
const result = await fetch("http://localhost:3000/api/audio", {
method: "POST",
body: JSON.stringify({ filePath }),
headers: {
"Content-Type": "application/json",
},
});
const data = await result.json();
console.log("audio data", data);
return data.text;
import { requestUrl } from "obsidian";
import { logMessage } from "../../utils";

// audio type of type base64
async function useAudio(audioFileBase64: string) {
const baseUrl = "https://file-organizer-2000.vercel.app/";

const endpoint = "api/audio";
const url = `${baseUrl}/${endpoint}`;
try {
const result = await requestUrl({
url: url,
method: "POST",
body: JSON.stringify({ file: audioFileBase64 }),
headers: {
"Content-Type": "application/json",
},
});
const data = await result.json;
logMessage(data.text);
return data.text;
} catch (error) {
console.error("Error uploading audio file:", error);
}
}

export default useAudio;
11 changes: 7 additions & 4 deletions src/modules/name.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { requestUrl } from "obsidian";
import { logMessage } from "../../utils";

// Generates titles for documents
async function useName(document) {
async function useName(document, apiKey) {
const data = {
model: "gpt-4-1106-preview",
messages: [
Expand All @@ -17,18 +16,22 @@ async function useName(document) {
},
],
};
const baseUrl = "https://file-organizer-2000.vercel.app/";
const endpoint = "api/name";
const url = `${baseUrl}/${endpoint}`;

const response = await requestUrl({
url: "http://localhost:3000/api/name",
url: url,
method: "POST",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiKey}`,
},
});

const result = await response.json;
logMessage("name result", result.choices[0].message.content);
logMessage(result.choices[0].message.content);
return result.choices[0].message.content.trim();
}

Expand Down
5 changes: 4 additions & 1 deletion src/modules/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ async function useText(content: string, systemPrompt: string) {
},
],
};
const baseUrl = "https://file-organizer-2000.vercel.app/";
const endpoint = "api/text";
const url = `${baseUrl}/${endpoint}`;

const response = await requestUrl({
url: "http://localhost:3000/api/text",
url: url,
method: "POST",
body: JSON.stringify(data),
headers: {
Expand Down
5 changes: 4 additions & 1 deletion src/modules/vision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ async function useVision(encodedImage, systemPrompt = defaultPrompt) {
},
],
};
const baseUrl = "https://file-organizer-2000.vercel.app/";
const endpoint = "api/vision";
const url = `${baseUrl}/${endpoint}`;

const response = await fetch("http://localhost:3000/api/vision", {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down

0 comments on commit 305f967

Please sign in to comment.