Skip to content

Commit

Permalink
feat(templates): Allow user to set the temperature for each prompt (#111
Browse files Browse the repository at this point in the history
)
  • Loading branch information
juanjonavarro authored Jun 1, 2023
1 parent 9b7e252 commit 8c05660
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/lib/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export async function loadUserCommands() {
customCommands.push({
type: type,
name: type,
temperature: Number(result[0].properties["prompt-temperature"]),
prompt: prompt,
});
}
Expand All @@ -62,6 +63,7 @@ export async function loadUserCommands() {

interface Prompt {
name: string;
temperature: number;
description: string;
prompt: string;
}
Expand All @@ -74,6 +76,7 @@ function promptsToCommands(prompts: Prompts): Command[] {
name: prompt.name,
description: prompt.description,
prompt: prompt.prompt,
temperature: prompt.temperature,
};
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export const settingsSchema: SettingSchemaDesc[] = [
default: 1.0,
title: "OpenAI Temperature",
description:
"The temperature controls how much randomness is in the output.",
"The temperature controls how much randomness is in the output.<br/>"+
"You can set a different temperature in your own prompt templates by adding a 'prompt-template' property to the block.",
},
{
key: "openAIMaxTokens",
Expand Down
4 changes: 4 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ const LogseqApp = () => {
}

const openAISettings = getOpenaiSettings();
// Set temperature of command instead of global temperature
if (command.temperature!=null && !Number.isNaN(command.temperature)) {
openAISettings.temperature = command.temperature;
}
const response = await openAI(command.prompt + inputText, openAISettings);
if (response) {
return response;
Expand Down
1 change: 1 addition & 0 deletions src/ui/LogseqAI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface Command {
type: string;
name: string;
prompt: string;
temperature?: number;
shortcut?: string;
}

Expand Down

0 comments on commit 8c05660

Please sign in to comment.