From 0d14b61cc9c2cdc01c8cc51053769b054fca843f Mon Sep 17 00:00:00 2001 From: Christian Bager Bach Houmann Date: Sun, 3 Mar 2024 19:46:13 +0100 Subject: [PATCH] refactor: fix types --- src/gui/MacroGUIs/AIAssistantCommandSettingsModal.ts | 7 +++++-- .../MacroGUIs/AIAssistantInfiniteCommandSettingsModal.ts | 4 +++- src/types/macros/QuickCommands/AIAssistantCommand.ts | 3 +-- src/types/macros/QuickCommands/IAIAssistantCommand.ts | 5 ++--- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/gui/MacroGUIs/AIAssistantCommandSettingsModal.ts b/src/gui/MacroGUIs/AIAssistantCommandSettingsModal.ts index b85e409..11023a6 100644 --- a/src/gui/MacroGUIs/AIAssistantCommandSettingsModal.ts +++ b/src/gui/MacroGUIs/AIAssistantCommandSettingsModal.ts @@ -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; @@ -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) { diff --git a/src/gui/MacroGUIs/AIAssistantInfiniteCommandSettingsModal.ts b/src/gui/MacroGUIs/AIAssistantInfiniteCommandSettingsModal.ts index 4c6efdc..4e6370c 100644 --- a/src/gui/MacroGUIs/AIAssistantInfiniteCommandSettingsModal.ts +++ b/src/gui/MacroGUIs/AIAssistantInfiniteCommandSettingsModal.ts @@ -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) { diff --git a/src/types/macros/QuickCommands/AIAssistantCommand.ts b/src/types/macros/QuickCommands/AIAssistantCommand.ts index 5ca52f0..80fd8b2 100644 --- a/src/types/macros/QuickCommands/AIAssistantCommand.ts +++ b/src/types/macros/QuickCommands/AIAssistantCommand.ts @@ -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"; @@ -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: { diff --git a/src/types/macros/QuickCommands/IAIAssistantCommand.ts b/src/types/macros/QuickCommands/IAIAssistantCommand.ts index 723aa6b..40b3a61 100644 --- a/src/types/macros/QuickCommands/IAIAssistantCommand.ts +++ b/src/types/macros/QuickCommands/IAIAssistantCommand.ts @@ -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"; @@ -10,7 +9,7 @@ interface IBaseAIAssistantCommand extends ICommand { } export interface IAIAssistantCommand extends IBaseAIAssistantCommand { - model: Models_And_Ask_Me; + model: string; promptTemplate: { enable: boolean; name: string; @@ -18,7 +17,7 @@ export interface IAIAssistantCommand extends IBaseAIAssistantCommand { } export interface IInfiniteAIAssistantCommand extends IBaseAIAssistantCommand { - model: Model; + model: string; resultJoiner: string; chunkSeparator: string; maxChunkTokens: number;