Skip to content

Commit

Permalink
Support delete core models, inherit excluding from Obsidian (#817)
Browse files Browse the repository at this point in the history
  • Loading branch information
Emt-lin authored Nov 27, 2024
1 parent 8f39e53 commit a5b39ff
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
36 changes: 33 additions & 3 deletions src/VectorStoreManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,11 @@ class VectorStoreManager {
private updateIndexingNoticeMessage() {
if (this.indexNoticeMessage) {
const status = this.isIndexingPaused ? " (Paused)" : "";

const folders = this.extractAppIgnoreSettings();
const filterType = this.settings.qaInclusions
? `Inclusions: ${this.settings.qaInclusions}`
: `Exclusions: ${this.settings.qaExclusions || "None"}`;
: `Exclusions: ${folders.join(",") + (folders.length ? ", " : "") + this.settings.qaExclusions || "None"}`;

this.indexNoticeMessage.textContent =
`Copilot is indexing your vault...\n` +
Expand Down Expand Up @@ -359,8 +361,15 @@ class VectorStoreManager {
private async getFilePathsForQA(filterType: "exclusions" | "inclusions"): Promise<Set<string>> {
const targetFiles = new Set<string>();

if (filterType === "exclusions" && this.settings.qaExclusions) {
const exclusions = this.settings.qaExclusions.split(",").map((item) => item.trim());
if (filterType === "exclusions") {
const exclusions: string[] = [];

exclusions.push(...this.extractAppIgnoreSettings());

if (this.settings.qaExclusions) {
exclusions.push(...this.settings.qaExclusions.split(",").map((item) => item.trim()));
}

const excludedFilePaths = await getFilePathsFromPatterns(exclusions, this.app.vault);
excludedFilePaths.forEach((filePath) => targetFiles.add(filePath));
} else if (filterType === "inclusions" && this.settings.qaInclusions) {
Expand All @@ -372,6 +381,27 @@ class VectorStoreManager {
return targetFiles;
}

private extractAppIgnoreSettings() {
const appIgnoreFolders: string[] = [];
try {
// not documented in Obsidian API, but I got this answer from Obsidian's discord
const userIgnoreFilters: unknown = (app.vault as any).getConfig("userIgnoreFilters");

// inherit from the Obsidian "master exclusion" settings
if (!!userIgnoreFilters && Array.isArray(userIgnoreFilters)) {
userIgnoreFilters.forEach((it) => {
if (typeof it === "string") {
appIgnoreFolders.push(it.endsWith("/") ? it.slice(0, -1) : it);
}
});
}
} catch (e) {
console.warn("Error getting userIgnoreFilters from Obsidian config", e);
}

return appIgnoreFolders;
}

public async getAllQAMarkdownContent(): Promise<string> {
let allContent = "";

Expand Down
7 changes: 0 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,13 +532,6 @@ export default class CopilotPlugin extends Plugin {
// Create a unique key for each model, it's model (name + provider)
const getModelKey = (model: CustomModel) => `${model.name}|${model.provider}`;

// Add core models to the map
builtInModels
.filter((model) => model.core)
.forEach((model) => {
modelMap.set(getModelKey(model), { ...model, core: true });
});

// Add or update existing models in the map
existingActiveModels.forEach((model) => {
const key = getModelKey(model);
Expand Down
4 changes: 2 additions & 2 deletions src/settings/components/SettingBlocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ const ModelSettingsComponent: React.FC<ModelSettingsComponentProps> = ({
)}
</td>
<td>
{getModelKey(model) !== defaultModelKey && !model.core && (
{getModelKey(model) !== defaultModelKey && (
<button onClick={() => onDeleteModel(getModelKey(model))}>Delete</button>
)}
</td>
Expand Down Expand Up @@ -399,7 +399,7 @@ const ModelSettingsComponent: React.FC<ModelSettingsComponentProps> = ({
updatedModels[index].enableCors = value;
onUpdateModels(updatedModels);
}}
onDelete={!model.core ? () => onDeleteModel(getModelKey(model)) : undefined}
onDelete={() => onDeleteModel(getModelKey(model))}
disabled={model.isBuiltIn}
/>
))}
Expand Down

0 comments on commit a5b39ff

Please sign in to comment.