Skip to content
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

feat: add cut-off frontmatter and cut-off text on %%---%% #144

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const DEFAULT_SETTINGS = {
header_exclusions: "",
path_only: "",
show_full_path: false,
cut_off_frontmatter: false,
expanded_view: true,
group_nearest_by_file: false,
language: "en",
Expand Down Expand Up @@ -2556,6 +2557,7 @@ class SmartConnectionsSettingsTab extends Obsidian.PluginSettingTab {
const self_ref_pronouns_list = containerEl.createEl("span", {
text: this.get_self_ref_list()
});
new Obsidian.Setting(containerEl).setName("Cut off frontmatter").setDesc("Cut off frontmatter in the prompt to gain characters in reply generation").addToggle((toggle) => { toggle.setValue(this.plugin.settings.cut_off_frontmatter).onChange(async (value) => { this.plugin.settings.cut_off_frontmatter = value; await this.plugin.saveSettings(); }); });
containerEl.createEl("h2", {
text: "Exclusions"
});
Expand Down Expand Up @@ -3609,6 +3611,7 @@ class SmartConnectionsChatModel {
// max chars for this note is max_chars divided by number of notes left
const this_max_chars = (notes.length - i > 1) ? Math.floor(max_chars / (notes.length - i)) : max_chars;
const note_content = await this.get_note_contents(notes[i], {char_limit: this_max_chars});
console.log(note_content);
system_input += `---BEGIN NOTE: [[${notes[i].basename}]]---\n`
system_input += note_content;
system_input += `---END NOTE---\n`
Expand Down Expand Up @@ -3680,11 +3683,17 @@ class SmartConnectionsChatModel {
if(!(note instanceof Obsidian.TFile)) return "";
// get file content
let file_content = await this.app.vault.cachedRead(note);
//cut off front matter
if (this.plugin.settings.cut_off_frontmatter) {
file_content = file_content.replace(/\s*---[\s\S]*?---/,"");
}
// check if contains dataview code block
if(file_content.indexOf("```dataview") > -1){
// if contains dataview code block get all dataview code blocks
file_content = await this.render_dataview_queries(file_content, note.path, opts);
}
// cut off note if %%---%% is found
file_content = file_content.replace(/%%---%%[\s\S]*/, "");
return file_content.substring(0, opts.char_limit);
}

Expand Down