Skip to content

webui: save model name with conversation history (#13570) #14192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions tools/server/webui/src/components/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function ChatMessage({
onChangeSibling(sibling: Message['id']): void;
isPending?: boolean;
}) {
const { viewingChat, config } = useAppContext();
const { viewingChat, config, serverProps } = useAppContext();
const [editingContent, setEditingContent] = useState<string | null>(null);
const timings = useMemo(
() =>
Expand Down Expand Up @@ -189,11 +189,18 @@ export default function ChatMessage({
</div>
</div>
)}

{/* Show model name only after AI messages */}
{msg.role === 'assistant' && serverProps?.model_path && (
<div className="text-xs opacity-50 mt-2">
{serverProps.model_path.split(/(\\|\/)/).pop()}
</div>
)}
</>
)}
</div>
</div>

{/* actions for each message */}
{msg.content !== null && (
<div
Expand Down
4 changes: 3 additions & 1 deletion tools/server/webui/src/utils/app.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,10 @@ export const AppContextProvider = ({
if (isGenerating(convId ?? '') || content.trim().length === 0) return false;

if (convId === null || convId.length === 0 || leafNodeId === null) {
const modelName = serverProps?.model_path?.split(/(\\|\/)/).pop();
const conv = await StorageUtils.createConversation(
content.substring(0, 256)
content.substring(0, 256),
modelName
);
convId = conv.id;
leafNodeId = conv.currNode;
Expand Down
14 changes: 12 additions & 2 deletions tools/server/webui/src/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ const db = new Dexie('LlamacppWebui') as Dexie & {

// https://dexie.org/docs/Version/Version.stores()
db.version(1).stores({
// Unlike SQL, you dont need to specify all properties but only the one you wish to index.
// Unlike SQL, you don't need to specify all properties but only the one you wish to index.
conversations: '&id, lastModified',
messages: '&id, convId, [convId+id], timestamp',
});

db.version(2).stores({
// Version 2: Added modelName field to conversations
conversations: '&id, lastModified, modelName',
messages: '&id, convId, [convId+id], timestamp',
});

// convId is a string prefixed with 'conv-'
const StorageUtils = {
/**
Expand Down Expand Up @@ -93,14 +99,18 @@ const StorageUtils = {
/**
* create a new conversation with a default root node
*/
async createConversation(name: string): Promise<Conversation> {
async createConversation(
name: string,
modelName?: string
): Promise<Conversation> {
const now = Date.now();
const msgId = now;
const conv: Conversation = {
id: `conv-${now}`,
lastModified: now,
currNode: msgId,
name,
modelName,
};
await db.conversations.add(conv);
// create a root node
Expand Down
1 change: 1 addition & 0 deletions tools/server/webui/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export interface Conversation {
lastModified: number; // timestamp from Date.now()
currNode: Message['id']; // the current message node being viewed
name: string;
modelName?: string; // optional model name extracted from serverProps
}

export interface ViewingChat {
Expand Down