Skip to content

Commit 4bbd48d

Browse files
committed
MessageExtraContext
1 parent e7ec817 commit 4bbd48d

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

examples/server/webui/src/utils/llama-vscode.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useState } from 'react';
2-
import { MessageExtraTextFile } from './types';
2+
import { MessageExtraContext } from './types';
33

44
// Extra context when using llama.cpp WebUI from llama-vscode, inside an iframe
55
// Ref: https://github.com/ggml-org/llama.cpp/pull/11940
@@ -18,7 +18,7 @@ export const useVSCodeContext = (
1818
inputRef: React.RefObject<HTMLTextAreaElement>,
1919
setInputMsg: (text: string) => void
2020
) => {
21-
const [extraContext, setExtraContext] = useState<MessageExtraTextFile | null>(
21+
const [extraContext, setExtraContext] = useState<MessageExtraContext | null>(
2222
null
2323
);
2424
console.log({ extraContext });
@@ -29,11 +29,12 @@ export const useVSCodeContext = (
2929
if (event.data?.command === 'setText') {
3030
const data: SetTextEvData = event.data;
3131
setInputMsg(data?.text);
32-
setExtraContext({
33-
type: 'textFile',
34-
name: '(context)', // TODO: set filename
35-
content: data?.context ?? '(no context)',
36-
});
32+
if (data?.context && data.context.length > 0) {
33+
setExtraContext({
34+
type: 'context',
35+
content: data.context,
36+
});
37+
}
3738
inputRef.current?.focus();
3839
}
3940
};

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ export function normalizeMsgsForAPI(messages: Readonly<Message[]>) {
6060
let newContent = '';
6161

6262
for (const extra of msg.extra ?? []) {
63-
if (extra.type === 'textFile') {
64-
// TODO: allow user to customize this via Settings
65-
newContent += `\n===\nExtra file: ${extra.name}\n${extra.content}\n\n===\n`;
63+
if (extra.type === 'context') {
64+
newContent += `${extra.content}\n\n`;
6665
}
6766
}
6867

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,19 @@ export interface Message {
4848
children: Message['id'][];
4949
}
5050

51-
type MessageExtra = MessageExtraTextFile; // TODO: will add more in the future
51+
type MessageExtra = MessageExtraTextFile | MessageExtraContext; // TODO: will add more in the future
5252

5353
export interface MessageExtraTextFile {
5454
type: 'textFile';
5555
name: string;
5656
content: string;
5757
}
5858

59+
export interface MessageExtraContext {
60+
type: 'context';
61+
content: string;
62+
}
63+
5964
export type APIMessage = Pick<Message, 'role' | 'content'>;
6065

6166
export interface Conversation {

0 commit comments

Comments
 (0)