Skip to content

Commit

Permalink
createPrompt responsible for assigning completionParams
Browse files Browse the repository at this point in the history
  • Loading branch information
nvms committed Dec 4, 2023
1 parent d1bd7ef commit 9bca37a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 36 deletions.
56 changes: 28 additions & 28 deletions extension/dist/extension.umd.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions extension/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export async function createPrompt(prompt: PromptDefinition & { promptId: string
const editor = vscode.window.activeTextEditor;
const readable = getHumanReadableLanguageName(languageid(editor), extension(editor));
const selection = getSelectionInfo(editor);
const completionParams = getActiveModeActivePresetKeyValue("completionParams") as Preset["completionParams"];

const substitute = async (text: string) => {
text = text.replaceAll("{{ft}}", languageid(editor));
Expand Down Expand Up @@ -53,11 +54,10 @@ export async function createPrompt(prompt: PromptDefinition & { promptId: string
if (matchGroups && matchGroups.length === 3) {
const paramName = matchGroups[1];
const paramValue = matchGroups[2];
const activePresetCompletionParameters = getActiveModeActivePresetKeyValue("completionParams") as Preset["completionParams"];

// If the active preset has a completion parameter with this name, overwrite it with this value.
if (Object.hasOwnProperty.call(activePresetCompletionParameters, paramName)) {
activePresetCompletionParameters[paramName] = paramValue;
if (Object.hasOwnProperty.call(completionParams, paramName)) {
const numberRegex = /^[0-9]+(\.[0-9]+)?$/;
completionParams[paramName] = numberRegex.test(paramValue) ? Number(paramValue) : paramValue;
}

text = text.replace(match, "");
Expand All @@ -74,5 +74,5 @@ export async function createPrompt(prompt: PromptDefinition & { promptId: string
const message = await substitute(prompt.message);
const system = await substitute(prompt.system ?? getActiveModeActivePresetKeyValue("system") as Preset["system"]);

return { message, system };
return { message, system, completionParams };
}
5 changes: 2 additions & 3 deletions extension/src/dispatcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from "vscode";
import { ChatEvents, InsertionMethod, PromptDefinition } from "../../shared";
import { ChatEvents, InsertionMethod, PromptDefinition, Preset } from "../../shared";
import { createPrompt } from "./command";
import { providers } from "./providers/common";
import { OpenAIProvider } from "./providers/openai";
Expand Down Expand Up @@ -145,7 +145,7 @@ export type PreparedCommand = {
system: string;
insertionMethod: InsertionMethod;
url: string;
completionParams: Record<string, string | number | boolean | any[]>;
completionParams: Preset["completionParams"];
};

const prepareCommand = async (prompt: PromptDefinition & { promptId: string }): Promise<PreparedCommand> => {
Expand All @@ -161,6 +161,5 @@ const prepareCommand = async (prompt: PromptDefinition & { promptId: string }):
...substituted,
insertionMethod,
url: getActiveModeActivePresetKeyValue("url") as string,
completionParams: getActiveModeActivePresetKeyValue("completionParams") as Record<string, string | number | boolean>,
};
};

0 comments on commit 9bca37a

Please sign in to comment.