Chore: remove AutoCleanToolCallsFromCtx, atomic model color
This commit is contained in:
19
bot.go
19
bot.go
@@ -851,7 +851,7 @@ out:
|
|||||||
if thinkingCollapsed {
|
if thinkingCollapsed {
|
||||||
// Show placeholder immediately when thinking starts in collapsed mode
|
// Show placeholder immediately when thinking starts in collapsed mode
|
||||||
fmt.Fprint(textView, "[yellow::i][thinking... (press Alt+T to expand)][-:-:-]")
|
fmt.Fprint(textView, "[yellow::i][thinking... (press Alt+T to expand)][-:-:-]")
|
||||||
if scrollToEndEnabled {
|
if cfg.AutoScrollEnabled {
|
||||||
textView.ScrollToEnd()
|
textView.ScrollToEnd()
|
||||||
}
|
}
|
||||||
respText.WriteString(chunk)
|
respText.WriteString(chunk)
|
||||||
@@ -866,7 +866,7 @@ out:
|
|||||||
// Thinking already displayed as placeholder, just update respText
|
// Thinking already displayed as placeholder, just update respText
|
||||||
respText.WriteString(chunk)
|
respText.WriteString(chunk)
|
||||||
justExitedThinkingCollapsed = true
|
justExitedThinkingCollapsed = true
|
||||||
if scrollToEndEnabled {
|
if cfg.AutoScrollEnabled {
|
||||||
textView.ScrollToEnd()
|
textView.ScrollToEnd()
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
@@ -888,7 +888,7 @@ out:
|
|||||||
respText.WriteString(chunk)
|
respText.WriteString(chunk)
|
||||||
// Update the message in chatBody.Messages so it persists during Alt+T
|
// Update the message in chatBody.Messages so it persists during Alt+T
|
||||||
chatBody.Messages[msgIdx].Content = respText.String()
|
chatBody.Messages[msgIdx].Content = respText.String()
|
||||||
if scrollToEndEnabled {
|
if cfg.AutoScrollEnabled {
|
||||||
textView.ScrollToEnd()
|
textView.ScrollToEnd()
|
||||||
}
|
}
|
||||||
// Send chunk to audio stream handler
|
// Send chunk to audio stream handler
|
||||||
@@ -898,7 +898,7 @@ out:
|
|||||||
case toolChunk := <-openAIToolChan:
|
case toolChunk := <-openAIToolChan:
|
||||||
fmt.Fprint(textView, toolChunk)
|
fmt.Fprint(textView, toolChunk)
|
||||||
toolResp.WriteString(toolChunk)
|
toolResp.WriteString(toolChunk)
|
||||||
if scrollToEndEnabled {
|
if cfg.AutoScrollEnabled {
|
||||||
textView.ScrollToEnd()
|
textView.ScrollToEnd()
|
||||||
}
|
}
|
||||||
case <-streamDone:
|
case <-streamDone:
|
||||||
@@ -906,7 +906,7 @@ out:
|
|||||||
chunk := <-chunkChan
|
chunk := <-chunkChan
|
||||||
fmt.Fprint(textView, chunk)
|
fmt.Fprint(textView, chunk)
|
||||||
respText.WriteString(chunk)
|
respText.WriteString(chunk)
|
||||||
if scrollToEndEnabled {
|
if cfg.AutoScrollEnabled {
|
||||||
textView.ScrollToEnd()
|
textView.ScrollToEnd()
|
||||||
}
|
}
|
||||||
if cfg.TTS_ENABLED {
|
if cfg.TTS_ENABLED {
|
||||||
@@ -1394,9 +1394,6 @@ func updateModelLists() {
|
|||||||
localModelsMu.Lock()
|
localModelsMu.Lock()
|
||||||
LocalModels = ml
|
LocalModels = ml
|
||||||
localModelsMu.Unlock()
|
localModelsMu.Unlock()
|
||||||
for statusLineWidget == nil {
|
|
||||||
time.Sleep(time.Millisecond * 100)
|
|
||||||
}
|
|
||||||
// set already loaded model in llama.cpp
|
// set already loaded model in llama.cpp
|
||||||
if !isLocalLlamacpp() {
|
if !isLocalLlamacpp() {
|
||||||
return
|
return
|
||||||
@@ -1408,7 +1405,7 @@ func updateModelLists() {
|
|||||||
m := strings.TrimPrefix(LocalModels[i], models.LoadedMark)
|
m := strings.TrimPrefix(LocalModels[i], models.LoadedMark)
|
||||||
cfg.CurrentModel = m
|
cfg.CurrentModel = m
|
||||||
chatBody.Model = m
|
chatBody.Model = m
|
||||||
cachedModelColor = "green"
|
cachedModelColor.Store("green")
|
||||||
updateStatusLine()
|
updateStatusLine()
|
||||||
updateToolCapabilities()
|
updateToolCapabilities()
|
||||||
app.Draw()
|
app.Draw()
|
||||||
@@ -1546,8 +1543,8 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Initialize scrollToEndEnabled based on config
|
// atomic default values
|
||||||
scrollToEndEnabled = cfg.AutoScrollEnabled
|
cachedModelColor.Store("orange")
|
||||||
go chatWatcher(ctx)
|
go chatWatcher(ctx)
|
||||||
initTUI()
|
initTUI()
|
||||||
initTools()
|
initTools()
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ type Config struct {
|
|||||||
WriteNextMsgAs string
|
WriteNextMsgAs string
|
||||||
WriteNextMsgAsCompletionAgent string
|
WriteNextMsgAsCompletionAgent string
|
||||||
SkipLLMResp bool
|
SkipLLMResp bool
|
||||||
AutoCleanToolCallsFromCtx bool `toml:"AutoCleanToolCallsFromCtx"`
|
|
||||||
DBPATH string `toml:"DBPATH"`
|
DBPATH string `toml:"DBPATH"`
|
||||||
FilePickerDir string `toml:"FilePickerDir"`
|
FilePickerDir string `toml:"FilePickerDir"`
|
||||||
FilePickerExts string `toml:"FilePickerExts"`
|
FilePickerExts string `toml:"FilePickerExts"`
|
||||||
|
|||||||
@@ -63,9 +63,6 @@ This document explains how to set up and configure the application using the `co
|
|||||||
#### AutoScrollEnabled (`true`)
|
#### AutoScrollEnabled (`true`)
|
||||||
- Whether to automatically scroll chat window while llm streams its repsonse.
|
- Whether to automatically scroll chat window while llm streams its repsonse.
|
||||||
|
|
||||||
#### AutoCleanToolCallsFromCtx (`false`)
|
|
||||||
- Whether to automatically clean tool calls from the conversation context to manage token usage.
|
|
||||||
|
|
||||||
### RAG (Retrieval Augmented Generation) Settings
|
### RAG (Retrieval Augmented Generation) Settings
|
||||||
|
|
||||||
#### EmbedURL (`"http://localhost:8082/v1/embeddings"`)
|
#### EmbedURL (`"http://localhost:8082/v1/embeddings"`)
|
||||||
|
|||||||
24
helpfuncs.go
24
helpfuncs.go
@@ -12,6 +12,7 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
@@ -19,7 +20,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Cached model color - updated by background goroutine
|
// Cached model color - updated by background goroutine
|
||||||
var cachedModelColor string = "orange"
|
// var cachedModelColor string = "orange"
|
||||||
|
var cachedModelColor atomic.Value
|
||||||
|
|
||||||
// startModelColorUpdater starts a background goroutine that periodically updates
|
// startModelColorUpdater starts a background goroutine that periodically updates
|
||||||
// the cached model color. Only runs HTTP requests for local llama.cpp APIs.
|
// the cached model color. Only runs HTTP requests for local llama.cpp APIs.
|
||||||
@@ -38,20 +40,20 @@ func startModelColorUpdater() {
|
|||||||
// updateCachedModelColor updates the global cachedModelColor variable
|
// updateCachedModelColor updates the global cachedModelColor variable
|
||||||
func updateCachedModelColor() {
|
func updateCachedModelColor() {
|
||||||
if !isLocalLlamacpp() {
|
if !isLocalLlamacpp() {
|
||||||
cachedModelColor = "orange"
|
cachedModelColor.Store("orange")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Check if model is loaded
|
// Check if model is loaded
|
||||||
loaded, err := isModelLoaded(chatBody.Model)
|
loaded, err := isModelLoaded(chatBody.Model)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// On error, assume not loaded (red)
|
// On error, assume not loaded (red)
|
||||||
cachedModelColor = "red"
|
cachedModelColor.Store("red")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if loaded {
|
if loaded {
|
||||||
cachedModelColor = "green"
|
cachedModelColor.Store("green")
|
||||||
} else {
|
} else {
|
||||||
cachedModelColor = "red"
|
cachedModelColor.Store("red")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +109,7 @@ func refreshChatDisplay() {
|
|||||||
textView.SetText(displayText)
|
textView.SetText(displayText)
|
||||||
colorText()
|
colorText()
|
||||||
updateStatusLine()
|
updateStatusLine()
|
||||||
if scrollToEndEnabled {
|
if cfg.AutoScrollEnabled {
|
||||||
textView.ScrollToEnd()
|
textView.ScrollToEnd()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -332,7 +334,7 @@ func isLocalLlamacpp() bool {
|
|||||||
// The cached value is updated by a background goroutine every 5 seconds.
|
// The cached value is updated by a background goroutine every 5 seconds.
|
||||||
// For non-local models, returns orange. For local llama.cpp models, returns green if loaded, red if not.
|
// For non-local models, returns orange. For local llama.cpp models, returns green if loaded, red if not.
|
||||||
func getModelColor() string {
|
func getModelColor() string {
|
||||||
return cachedModelColor
|
return cachedModelColor.Load().(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeStatusLine() string {
|
func makeStatusLine() string {
|
||||||
@@ -539,7 +541,7 @@ func executeCommandAndDisplay(cmdText string) {
|
|||||||
cmdText = strings.TrimSpace(cmdText)
|
cmdText = strings.TrimSpace(cmdText)
|
||||||
if cmdText == "" {
|
if cmdText == "" {
|
||||||
fmt.Fprintf(textView, "\n[red]Error: No command provided[-:-:-]\n")
|
fmt.Fprintf(textView, "\n[red]Error: No command provided[-:-:-]\n")
|
||||||
if scrollToEndEnabled {
|
if cfg.AutoScrollEnabled {
|
||||||
textView.ScrollToEnd()
|
textView.ScrollToEnd()
|
||||||
}
|
}
|
||||||
colorText()
|
colorText()
|
||||||
@@ -571,7 +573,7 @@ func executeCommandAndDisplay(cmdText string) {
|
|||||||
Content: "$ " + cmdText + "\n\n" + outputContent,
|
Content: "$ " + cmdText + "\n\n" + outputContent,
|
||||||
}
|
}
|
||||||
chatBody.Messages = append(chatBody.Messages, combinedMsg)
|
chatBody.Messages = append(chatBody.Messages, combinedMsg)
|
||||||
if scrollToEndEnabled {
|
if cfg.AutoScrollEnabled {
|
||||||
textView.ScrollToEnd()
|
textView.ScrollToEnd()
|
||||||
}
|
}
|
||||||
colorText()
|
colorText()
|
||||||
@@ -586,7 +588,7 @@ func executeCommandAndDisplay(cmdText string) {
|
|||||||
Content: "$ " + cmdText + "\n\n" + outputContent,
|
Content: "$ " + cmdText + "\n\n" + outputContent,
|
||||||
}
|
}
|
||||||
chatBody.Messages = append(chatBody.Messages, combinedMsg)
|
chatBody.Messages = append(chatBody.Messages, combinedMsg)
|
||||||
if scrollToEndEnabled {
|
if cfg.AutoScrollEnabled {
|
||||||
textView.ScrollToEnd()
|
textView.ScrollToEnd()
|
||||||
}
|
}
|
||||||
colorText()
|
colorText()
|
||||||
@@ -634,7 +636,7 @@ func executeCommandAndDisplay(cmdText string) {
|
|||||||
}
|
}
|
||||||
chatBody.Messages = append(chatBody.Messages, combinedMsg)
|
chatBody.Messages = append(chatBody.Messages, combinedMsg)
|
||||||
// Scroll to end and update colors
|
// Scroll to end and update colors
|
||||||
if scrollToEndEnabled {
|
if cfg.AutoScrollEnabled {
|
||||||
textView.ScrollToEnd()
|
textView.ScrollToEnd()
|
||||||
}
|
}
|
||||||
colorText()
|
colorText()
|
||||||
|
|||||||
@@ -121,9 +121,6 @@ func makePropsTable(props map[string]float32) *tview.Table {
|
|||||||
addCheckboxRow("TTS Enabled", cfg.TTS_ENABLED, func(checked bool) {
|
addCheckboxRow("TTS Enabled", cfg.TTS_ENABLED, func(checked bool) {
|
||||||
cfg.TTS_ENABLED = checked
|
cfg.TTS_ENABLED = checked
|
||||||
})
|
})
|
||||||
addCheckboxRow("Auto clean tool calls from context", cfg.AutoCleanToolCallsFromCtx, func(checked bool) {
|
|
||||||
cfg.AutoCleanToolCallsFromCtx = checked
|
|
||||||
})
|
|
||||||
addCheckboxRow("Enable Mouse", cfg.EnableMouse, func(checked bool) {
|
addCheckboxRow("Enable Mouse", cfg.EnableMouse, func(checked bool) {
|
||||||
cfg.EnableMouse = checked
|
cfg.EnableMouse = checked
|
||||||
// Reconfigure the app's mouse setting
|
// Reconfigure the app's mouse setting
|
||||||
|
|||||||
9
tui.go
9
tui.go
@@ -42,7 +42,6 @@ var (
|
|||||||
confirmPageName = "confirm"
|
confirmPageName = "confirm"
|
||||||
fullscreenMode bool
|
fullscreenMode bool
|
||||||
positionVisible bool = true
|
positionVisible bool = true
|
||||||
scrollToEndEnabled bool = true
|
|
||||||
// pages
|
// pages
|
||||||
historyPage = "historyPage"
|
historyPage = "historyPage"
|
||||||
agentPage = "agentPage"
|
agentPage = "agentPage"
|
||||||
@@ -634,7 +633,7 @@ func initTUI() {
|
|||||||
updateStatusLine()
|
updateStatusLine()
|
||||||
textView.SetText(chatToText(chatBody.Messages, cfg.ShowSys))
|
textView.SetText(chatToText(chatBody.Messages, cfg.ShowSys))
|
||||||
colorText()
|
colorText()
|
||||||
if scrollToEndEnabled {
|
if cfg.AutoScrollEnabled {
|
||||||
textView.ScrollToEnd()
|
textView.ScrollToEnd()
|
||||||
}
|
}
|
||||||
// init sysmap
|
// init sysmap
|
||||||
@@ -663,9 +662,9 @@ func initTUI() {
|
|||||||
}
|
}
|
||||||
if event.Key() == tcell.KeyRune && event.Rune() == '2' && event.Modifiers()&tcell.ModAlt != 0 {
|
if event.Key() == tcell.KeyRune && event.Rune() == '2' && event.Modifiers()&tcell.ModAlt != 0 {
|
||||||
// toggle auto-scrolling
|
// toggle auto-scrolling
|
||||||
scrollToEndEnabled = !scrollToEndEnabled
|
cfg.AutoScrollEnabled = !cfg.AutoScrollEnabled
|
||||||
status := "disabled"
|
status := "disabled"
|
||||||
if scrollToEndEnabled {
|
if cfg.AutoScrollEnabled {
|
||||||
status = "enabled"
|
status = "enabled"
|
||||||
}
|
}
|
||||||
showToast("autoscroll", "Auto-scrolling "+status)
|
showToast("autoscroll", "Auto-scrolling "+status)
|
||||||
@@ -1139,7 +1138,7 @@ func initTUI() {
|
|||||||
fmt.Fprintf(textView, "%s[-:-:b](%d) <%s>: [-:-:-]\n%s\n",
|
fmt.Fprintf(textView, "%s[-:-:b](%d) <%s>: [-:-:-]\n%s\n",
|
||||||
nl, len(chatBody.Messages), persona, msgText)
|
nl, len(chatBody.Messages), persona, msgText)
|
||||||
textArea.SetText("", true)
|
textArea.SetText("", true)
|
||||||
if scrollToEndEnabled {
|
if cfg.AutoScrollEnabled {
|
||||||
textView.ScrollToEnd()
|
textView.ScrollToEnd()
|
||||||
}
|
}
|
||||||
colorText()
|
colorText()
|
||||||
|
|||||||
Reference in New Issue
Block a user