Skip to content

Commit

Permalink
refactor: fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
chhoumann committed Mar 3, 2024
1 parent 4db9991 commit 0d14b61
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/gui/MacroGUIs/AIAssistantCommandSettingsModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
DEFAULT_TOP_P,
} from "src/ai/OpenAIModelParameters";
import { getTokenCount } from "src/ai/AIAssistant";
import { getModelNames } from "src/ai/aiHelpers";
import { getModelByName, getModelNames } from "src/ai/aiHelpers";

export class AIAssistantCommandSettingsModal extends Modal {
public waitForClose: Promise<IAIAssistantCommand>;
Expand All @@ -28,7 +28,10 @@ export class AIAssistantCommandSettingsModal extends Modal {
private get systemPromptTokenLength(): number {
if (this.settings.model === "Ask me") return Number.POSITIVE_INFINITY;

return getTokenCount(this.settings.systemPrompt, this.settings.model);
const model = getModelByName(this.settings.model);
if (!model) return Number.POSITIVE_INFINITY;

return getTokenCount(this.settings.systemPrompt, model);
}

constructor(settings: IAIAssistantCommand) {
Expand Down
4 changes: 3 additions & 1 deletion src/gui/MacroGUIs/AIAssistantInfiniteCommandSettingsModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export class InfiniteAIAssistantCommandSettingsModal extends Modal {
private showAdvancedSettings = false;

private get systemPromptTokenLength(): number {
return getTokenCount(this.settings.systemPrompt, this.settings.model);
const model = getModelByName(this.settings.model);
if (!model) return Number.POSITIVE_INFINITY;
return getTokenCount(this.settings.systemPrompt, model);
}

constructor(settings: IInfiniteAIAssistantCommand) {
Expand Down
3 changes: 1 addition & 2 deletions src/types/macros/QuickCommands/AIAssistantCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Models_And_Ask_Me } from "src/ai/models";
import { Command } from "../Command";
import { CommandType } from "../CommandType";
import type { IAIAssistantCommand } from "./IAIAssistantCommand";
Expand All @@ -11,7 +10,7 @@ export class AIAssistantCommand extends Command implements IAIAssistantCommand {
name: string;
type: CommandType;

model: Models_And_Ask_Me;
model: string;
systemPrompt: string;
outputVariableName: string;
promptTemplate: {
Expand Down
5 changes: 2 additions & 3 deletions src/types/macros/QuickCommands/IAIAssistantCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Model, Models_And_Ask_Me } from "src/ai/models";
import type { ICommand } from "../ICommand";
import type { OpenAIModelParameters } from "src/ai/OpenAIModelParameters";

Expand All @@ -10,15 +9,15 @@ interface IBaseAIAssistantCommand extends ICommand {
}

export interface IAIAssistantCommand extends IBaseAIAssistantCommand {
model: Models_And_Ask_Me;
model: string;
promptTemplate: {
enable: boolean;
name: string;
};
}

export interface IInfiniteAIAssistantCommand extends IBaseAIAssistantCommand {
model: Model;
model: string;
resultJoiner: string;
chunkSeparator: string;
maxChunkTokens: number;
Expand Down

0 comments on commit 0d14b61

Please sign in to comment.