Skip to content

Commit 943699e

Browse files
committed
improve compacting support + add return to previous thread button
1 parent f422bdc commit 943699e

4 files changed

Lines changed: 46 additions & 5 deletions

File tree

llms/extensions/app/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import asyncio
22
import json
33
import os
4-
import re
54
import time
65
from datetime import datetime
76
from typing import Any
@@ -56,6 +55,7 @@ def get_db():
5655
"error",
5756
"ref",
5857
"contextTokens",
58+
"parentId",
5959
]
6060

6161
def thread_dto(row):

llms/llms.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
},
132132
{
133133
"role": "user",
134-
"content": "Compact the following conversation while preserving all context needed to continue it coherently. The conversation has {message_count} messages totaling approximately {token_count} tokens. Target approximately {target_tokens} tokens.\n\n<conversation>\n{messages_json}\n</conversation>\n\nReturn your response as a JSON object with a single \"messages\" key containing the compacted array. Do not include any text before or after the JSON. Do not wrap in markdown code fences.\n\nExample output structure:\n{\"messages\":[{\"role\":\"system\",\"content\":\"...\"},{\"role\":\"user\",\"content\":\"...\"}]}"
134+
"content": "Compact the following conversation while preserving all context needed to continue it coherently. The conversation has {message_count} messages totaling approximately {token_count} tokens. Target approximately {target_tokens} tokens.\n\n<conversation>\n{messages_json}\n</conversation>\n\nReturn your response as a JSON object with a single \"messages\" key containing the compacted array."
135135
}
136136
],
137137
"response_format": {

llms/ui/app.css

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@
419419
.top-4 {
420420
top: calc(var(--spacing) * 4);
421421
}
422+
.top-12 {
423+
top: calc(var(--spacing) * 12);
424+
}
422425
.top-full {
423426
top: 100%;
424427
}
@@ -455,6 +458,9 @@
455458
.left-1\/2 {
456459
left: calc(1/2 * 100%);
457460
}
461+
.left-2 {
462+
left: calc(var(--spacing) * 2);
463+
}
458464
.left-3 {
459465
left: calc(var(--spacing) * 3);
460466
}
@@ -500,6 +506,9 @@
500506
.col-span-12 {
501507
grid-column: span 12 / span 12;
502508
}
509+
.float-left {
510+
float: left;
511+
}
503512
.container {
504513
width: 100%;
505514
@media (width >= 40rem) {
@@ -557,6 +566,12 @@
557566
.my-4 {
558567
margin-block: calc(var(--spacing) * 4);
559568
}
569+
.-mt-0 {
570+
margin-top: calc(var(--spacing) * -0);
571+
}
572+
.-mt-0\.5 {
573+
margin-top: calc(var(--spacing) * -0.5);
574+
}
560575
.-mt-1 {
561576
margin-top: calc(var(--spacing) * -1);
562577
}
@@ -786,6 +801,9 @@
786801
.h-4 {
787802
height: calc(var(--spacing) * 4);
788803
}
804+
.h-4\.5 {
805+
height: calc(var(--spacing) * 4.5);
806+
}
789807
.h-5 {
790808
height: calc(var(--spacing) * 5);
791809
}
@@ -2164,6 +2182,12 @@
21642182
.pr-12 {
21652183
padding-right: calc(var(--spacing) * 12);
21662184
}
2185+
.pb-0 {
2186+
padding-bottom: calc(var(--spacing) * 0);
2187+
}
2188+
.pb-0\.5 {
2189+
padding-bottom: calc(var(--spacing) * 0.5);
2190+
}
21672191
.pb-1 {
21682192
padding-bottom: calc(var(--spacing) * 1);
21692193
}
@@ -2292,6 +2316,14 @@
22922316
.text-\[11px\] {
22932317
font-size: 11px;
22942318
}
2319+
.leading-2 {
2320+
--tw-leading: calc(var(--spacing) * 2);
2321+
line-height: calc(var(--spacing) * 2);
2322+
}
2323+
.leading-3 {
2324+
--tw-leading: calc(var(--spacing) * 3);
2325+
line-height: calc(var(--spacing) * 3);
2326+
}
22952327
.leading-4 {
22962328
--tw-leading: calc(var(--spacing) * 4);
22972329
line-height: calc(var(--spacing) * 4);

llms/ui/modules/chat/ChatBody.mjs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,19 +638,19 @@ export const ToolOutput = {
638638
export const CompactThreadButton = {
639639
template: `
640640
<button v-if="currentThread.messages.length > 10 || percentUsed > 40" type="button" @click.stop="compactThread()"
641-
class="ml-3 px-2 pt-0.5 rounded-lg text-xs font-semibold border transition-all select-none disabled:opacity-60 disabled:cursor-not-allowed"
641+
class="ml-3 px-2 pt-1 pb-0.5 rounded-lg text-xs font-semibold border transition-all select-none disabled:opacity-60 disabled:cursor-not-allowed"
642642
:class="buttonClass"
643643
:style="buttonStyle"
644644
:title="tooltipText"
645645
:disabled="compacting">
646-
<span v-if="compacting" class="inline-flex items-center gap-1">
646+
<span v-if="compacting" class="inline-flex items-center gap-1 font-mono tabular-nums">
647647
<svg class="animate-spin h-3 w-3" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
648648
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
649649
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
650650
</svg>
651651
<span>compacting...</span>
652652
</span>
653-
<span v-else class="inline-flex items-center gap-x-1 font-mono tabular-nums">
653+
<span v-else class="inline-flex items-center gap-1 font-mono tabular-nums">
654654
<span v-if="percentUsed !== null">{{ percentUsed }}% used</span>
655655
<span>·</span>
656656
<span>compact</span>
@@ -718,6 +718,7 @@ export const CompactThreadButton = {
718718
compacting.value = true
719719
const api = await ctx.postJson(`/ext/app/threads/${props.currentThread.id}/compact`)
720720
if (api.response?.id) {
721+
ctx.threads.loadThreads()
721722
ctx.router.push(`/c/${api.response.id}`)
722723
} else {
723724
ctx.setError(api.error)
@@ -757,6 +758,14 @@ export const ChatBody = {
757758
758759
<!-- Messages -->
759760
<div v-else-if="currentThread">
761+
<button v-if="currentThread.parentId" type="button" @click.stop="$ctx.to('/c/' + currentThread.parentId)"
762+
title="Return to previous thread"
763+
class="float-left mb-2 p-1.5 rounded-lg text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors">
764+
<svg class="size-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
765+
<path d="M9 14 4 9l5-5"/>
766+
<path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11"/>
767+
</svg>
768+
</button>
760769
<ThreadHeader v-if="currentThread" :thread="currentThread" class="mb-2" />
761770
<div class="space-y-2" v-if="currentThread?.messages?.length">
762771
<div

0 commit comments

Comments
 (0)