Skip to content

Commit 42eb6c4

Browse files
author
igardev
committed
Move the extraContext from storage to app.context.
1 parent 3645e1b commit 42eb6c4

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

examples/server/public/index.html.gz

222 Bytes
Binary file not shown.

examples/server/webui/src/components/ChatScreen.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export default function ChatScreen() {
7979
pendingMessages,
8080
canvasData,
8181
replaceMessageAndGenerate,
82+
setExtraContext
8283
} = useAppContext();
8384
const [inputMsg, setInputMsg] = useState('');
8485
const inputRef = useRef<HTMLTextAreaElement>(null);
@@ -88,7 +89,7 @@ export default function ChatScreen() {
8889
const handleMessage = (event: MessageEvent) => {
8990
if (event.data?.command === 'setText') {
9091
setInputMsg(event.data?.text);
91-
StorageUtils.setExtraContext(event.data?.context)
92+
setExtraContext(event.data?.context)
9293
inputRef.current?.focus();
9394
}
9495
};

examples/server/webui/src/utils/app.context.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ interface AppContextValue {
4444
saveConfig: (config: typeof CONFIG_DEFAULT) => void;
4545
showSettings: boolean;
4646
setShowSettings: (show: boolean) => void;
47+
48+
// extra context
49+
extraContext: string;
50+
setExtraContext: (extraCtx: string) => void;
4751
}
4852

4953
// this callback is used for scrolling to the bottom of the chat and switching to the last node
@@ -82,6 +86,7 @@ export const AppContextProvider = ({
8286
const [config, setConfig] = useState(StorageUtils.getConfig());
8387
const [canvasData, setCanvasData] = useState<CanvasData | null>(null);
8488
const [showSettings, setShowSettings] = useState(false);
89+
const [extraContext, setExtraContext] = useState("");
8590

8691
// handle change when the convId from URL is changed
8792
useEffect(() => {
@@ -174,9 +179,8 @@ export const AppContextProvider = ({
174179
: [{ role: 'system', content: config.systemMessage } as APIMessage]),
175180
...normalizeMsgsForAPI(currMessages),
176181
];
177-
let extraContext:string = await StorageUtils.getExtraContext()
178182
if (extraContext && extraContext != ""){
179-
// insert extra context just after the systemMessage
183+
// insert extra context just before the user messages
180184
messages.splice(config.systemMessage.length === 0 ? 0 : 1, 0, { role: 'user', content:extraContext } as APIMessage)
181185
}
182186
if (config.excludeThoughtOnReq) {
@@ -376,6 +380,8 @@ export const AppContextProvider = ({
376380
saveConfig,
377381
showSettings,
378382
setShowSettings,
383+
extraContext,
384+
setExtraContext,
379385
}}
380386
>
381387
{children}

examples/server/webui/src/utils/storage.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const dispatchConversationChange = (convId: string) => {
2121
const db = new Dexie('LlamacppWebui') as Dexie & {
2222
conversations: Table<Conversation>;
2323
messages: Table<Message>;
24-
extraContext: string;
2524
};
2625

2726
// https://dexie.org/docs/Version/Version.stores()
@@ -117,12 +116,6 @@ const StorageUtils = {
117116
});
118117
return conv;
119118
},
120-
async setExtraContext(extraContext: string): Promise<void> {
121-
db.extraContext = extraContext
122-
},
123-
async getExtraContext(): Promise<string> {
124-
return db.extraContext;
125-
},
126119
/**
127120
* if convId does not exist, throw an error
128121
*/

0 commit comments

Comments
 (0)