Skip to content

Commit

Permalink
Append user system prompt instead of override (#880)
Browse files Browse the repository at this point in the history
  • Loading branch information
logancyang authored Dec 1, 2024
1 parent 744d7bf commit 1d8b4ed
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const DEFAULT_SYSTEM_PROMPT = `You are Obsidian Copilot, a helpful assist
2. If you are unsure about something, ask the user to provide more context.
3. If the user mentions "note", it most likely means an Obsidian note in the vault, not the generic meaning of a note.
4. If the user mentions "@vault", it means the user wants you to search the Obsidian vault for information relevant to the query. The search results will be provided to you in the context. If there's no relevant information in the vault, just say so.
5. If the user mentions any other tool with the @ symbol, check the context for their results. If nothing is found, just ignore the @ symbol in the query.`;
5. If the user mentions any other tool with the @ symbol, check the context for their results. If nothing is found, just ignore the @ symbol in the query.
6. Always respond in the language of the user's query.`;
export const CHUNK_SIZE = 4000;
export const CONTEXT_SCORE_THRESHOLD = 0.4;
export const TEXT_WEIGHT = 0.4;
Expand Down
7 changes: 3 additions & 4 deletions src/settings/components/AdvancedSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DEFAULT_SYSTEM_PROMPT } from "@/constants";
import { updateSetting, useSettingsValue } from "@/settings/model";
import React from "react";
import { TextAreaComponent } from "./SettingBlocks";
import { updateSetting, useSettingsValue } from "@/settings/model";

const AdvancedSettings: React.FC = () => {
const settings = useSettingsValue();
Expand All @@ -10,10 +9,10 @@ const AdvancedSettings: React.FC = () => {
<h1>Advanced Settings</h1>
<TextAreaComponent
name="User System Prompt"
description="Warning: It will override the default system prompt for all messages!"
description="Customize the system prompt for all messages, may result in unexpected behavior!"
value={settings.userSystemPrompt}
onChange={(value) => updateSetting("userSystemPrompt", value)}
placeholder={settings.userSystemPrompt || "Default: " + DEFAULT_SYSTEM_PROMPT}
placeholder={""}
rows={10}
/>
</div>
Expand Down
5 changes: 3 additions & 2 deletions src/settings/model.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { CustomModel } from "@/aiParams";
import { atom, getDefaultStore, useAtomValue } from "jotai";

import { type ChainType } from "@/chainFactory";
import {
BUILTIN_CHAT_MODELS,
BUILTIN_EMBEDDING_MODELS,
DEFAULT_OPEN_AREA,
DEFAULT_SETTINGS,
DEFAULT_SYSTEM_PROMPT,
} from "@/constants";
import { type ChainType } from "@/chainFactory";

export interface CopilotSettings {
plusLicenseKey: string;
Expand Down Expand Up @@ -133,7 +133,8 @@ export function sanitizeSettings(settings: CopilotSettings): CopilotSettings {
}

export function getSystemPrompt(): string {
return getSettings().userSystemPrompt || DEFAULT_SYSTEM_PROMPT;
const userPrompt = getSettings().userSystemPrompt;
return userPrompt ? `${DEFAULT_SYSTEM_PROMPT}\n\n${userPrompt}` : DEFAULT_SYSTEM_PROMPT;
}

function mergeAllActiveModelsWithCoreModels(settings: CopilotSettings): CopilotSettings {
Expand Down

0 comments on commit 1d8b4ed

Please sign in to comment.