Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
chhoumann committed Sep 28, 2023
2 parents cd6f152 + b24f8dd commit a9633fb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
8 changes: 5 additions & 3 deletions src/ai/AIAssistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ type ChunkedPromptParams = Omit<
resultJoiner: string;
text: string;
promptTemplate: string;
shouldMerge: boolean;
},
"prompt"
>;
Expand Down Expand Up @@ -368,7 +369,7 @@ export async function ChunkedPrompt(
const systemPromptLength = getTokenCount(systemPrompt, model);
// We need the prompt template to be rendered to get the token count of it, except the chunk variable.
const renderedPromptTemplate = await formatter(promptTemplate, {
chunk: "",
chunk: " ", // empty would make QA ask for a value, which we don't want
});
const promptTemplateTokenCount = getTokenCount(
renderedPromptTemplate,
Expand All @@ -378,7 +379,8 @@ export async function ChunkedPrompt(
const maxChunkTokenSize =
getModelMaxTokens(model) / 2 - systemPromptLength; // temp, need to impl. config

const shouldMerge = true; // temp, need to impl. config
// Whether we should strictly enforce the chunking rules or we should merge chunks that are too small
const shouldMerge = settings.shouldMerge ?? true; // temp, need to impl. config

const chunkedPrompts = [];
const maxCombinedChunkSize =
Expand Down Expand Up @@ -448,7 +450,7 @@ export async function ChunkedPrompt(
];
notice.setMessage(promptingMsg[0], promptingMsg[1]);

const rateLimiter = new RateLimiter(5, 1000); // 5 requests per second
const rateLimiter = new RateLimiter(5, 1000 * 30); // 5 requests per half minute
const results = Promise.all(
chunkedPrompts.map((prompt) =>
rateLimiter.add(() => makeRequest(prompt))
Expand Down
48 changes: 34 additions & 14 deletions src/gui/MacroGUIs/UserScriptSettingsModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { FormatDisplayFormatter } from "../../formatters/formatDisplayFormatter"
import { FormatSyntaxSuggester } from "../suggesters/formatSyntaxSuggester";
import { setPasswordOnBlur } from "../../utils/setPasswordOnBlur";

type Option =
type Option = { description?: string } & (
| {
type: "text" | "input";
value: string;
Expand All @@ -32,7 +32,8 @@ type Option =
value: string;
placeholder?: string;
defaultValue: string;
};
}
);

export class UserScriptSettingsModal extends Modal {
constructor(
Expand Down Expand Up @@ -92,20 +93,33 @@ export class UserScriptSettingsModal extends Modal {
value = this.command.settings[option] as string | boolean;
}

let setting;
const type = entry.type;
if (type === "text" || type === "input") {
this.addInputBox(
setting = this.addInputBox(
option,
value as string,
entry?.placeholder,
entry.secret
);
} else if (type === "checkbox" || type === "toggle") {
this.addToggle(option, value as boolean);
setting = this.addToggle(option, value as boolean);
} else if (type === "dropdown" || type === "select") {
this.addDropdown(option, entry.options, value as string);
setting = this.addDropdown(
option,
entry.options,
value as string
);
} else if (type === "format") {
this.addFormatInput(option, value as string, entry.placeholder);
setting = this.addFormatInput(
option,
value as string,
entry.placeholder
);
}

if (entry.description && setting) {
setting.setDesc(entry.description);
}
}
}
Expand All @@ -116,7 +130,7 @@ export class UserScriptSettingsModal extends Modal {
placeholder?: string,
passwordOnBlur?: boolean
) {
new Setting(this.contentEl).setName(name).addText((input) => {
return new Setting(this.contentEl).setName(name).addText((input) => {
input
.setValue(value)
.onChange((value) => (this.command.settings[name] = value))
Expand All @@ -129,7 +143,7 @@ export class UserScriptSettingsModal extends Modal {
}

private addToggle(name: string, value: boolean) {
new Setting(this.contentEl)
return new Setting(this.contentEl)
.setName(name)
.addToggle((toggle) =>
toggle
Expand All @@ -139,15 +153,19 @@ export class UserScriptSettingsModal extends Modal {
}

private addDropdown(name: string, options: string[], value: string) {
new Setting(this.contentEl).setName(name).addDropdown((dropdown) => {
options.forEach((item) => void dropdown.addOption(item, item));
dropdown.setValue(value);
dropdown.onChange((value) => (this.command.settings[name] = value));
});
return new Setting(this.contentEl)
.setName(name)
.addDropdown((dropdown) => {
options.forEach((item) => void dropdown.addOption(item, item));
dropdown.setValue(value);
dropdown.onChange(
(value) => (this.command.settings[name] = value)
);
});
}

private addFormatInput(name: string, value: string, placeholder?: string) {
new Setting(this.contentEl).setName(name);
const setting = new Setting(this.contentEl).setName(name);

const formatDisplay = this.contentEl.createEl("span");
const input = new TextAreaComponent(this.contentEl);
Expand All @@ -171,5 +189,7 @@ export class UserScriptSettingsModal extends Modal {

void (async () =>
(formatDisplay.innerText = await displayFormatter.format(value)))();

return setting;
}
}
2 changes: 2 additions & 0 deletions src/quickAddApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export class QuickAddApi {
systemPrompt: string;
chunkSeparator: RegExp;
chunkJoiner: string;
shouldMerge: boolean;
}>
) => {
const pluginSettings = settingsStore.getState();
Expand Down Expand Up @@ -203,6 +204,7 @@ export class QuickAddApi {
settings?.systemPrompt ??
AISettings.defaultSystemPrompt,
resultJoiner: settings?.chunkJoiner ?? "\n",
shouldMerge: settings?.shouldMerge ?? true,
},
(txt: string, variables?: Record<string, unknown>) => {
return formatter(txt, variables, false);
Expand Down

1 comment on commit a9633fb

@vercel
Copy link

@vercel vercel bot commented on a9633fb Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

quickadd – ./

quickadd-git-master-chrisbbh.vercel.app
quickadd.obsidian.guide
quickadd-chrisbbh.vercel.app

Please sign in to comment.