Enha: improve colours and formatingg
This commit is contained in:
2
bot.go
2
bot.go
@@ -113,6 +113,7 @@ func chatRound(userMsg, role string, tv *tview.TextView, regen bool) {
|
|||||||
if userMsg != "" && !regen { // no need to write assistant icon since we continue old message
|
if userMsg != "" && !regen { // no need to write assistant icon since we continue old message
|
||||||
fmt.Fprintf(tv, "(%d) ", len(chatBody.Messages))
|
fmt.Fprintf(tv, "(%d) ", len(chatBody.Messages))
|
||||||
fmt.Fprint(tv, cfg.AssistantIcon)
|
fmt.Fprint(tv, cfg.AssistantIcon)
|
||||||
|
fmt.Fprint(tv, "\n")
|
||||||
}
|
}
|
||||||
respText := strings.Builder{}
|
respText := strings.Builder{}
|
||||||
out:
|
out:
|
||||||
@@ -131,6 +132,7 @@ out:
|
|||||||
chatBody.Messages = append(chatBody.Messages, models.RoleMsg{
|
chatBody.Messages = append(chatBody.Messages, models.RoleMsg{
|
||||||
Role: cfg.AssistantRole, Content: respText.String(),
|
Role: cfg.AssistantRole, Content: respText.String(),
|
||||||
})
|
})
|
||||||
|
colorText()
|
||||||
// bot msg is done;
|
// bot msg is done;
|
||||||
// now check it for func call
|
// now check it for func call
|
||||||
// logChat(activeChatName, chatBody.Messages)
|
// logChat(activeChatName, chatBody.Messages)
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ func (m RoleMsg) ToText(i int) string {
|
|||||||
default:
|
default:
|
||||||
icon = fmt.Sprintf("(%d) <%s>: ", i, m.Role)
|
icon = fmt.Sprintf("(%d) <%s>: ", i, m.Role)
|
||||||
}
|
}
|
||||||
textMsg := fmt.Sprintf("%s%s\n", icon, m.Content)
|
textMsg := fmt.Sprintf("%s\n%s\n", icon, m.Content)
|
||||||
return strings.ReplaceAll(textMsg, "\n\n", "\n")
|
return strings.ReplaceAll(textMsg, "\n\n", "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
6
tools.go
6
tools.go
@@ -9,9 +9,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
toolCallRE = regexp.MustCompile(`__tool_call__\s*([\s\S]*?)__tool_call__`)
|
toolCallRE = regexp.MustCompile(`__tool_call__\s*([\s\S]*?)__tool_call__`)
|
||||||
// quotesRE = regexp.MustCompile(`(".*")`)
|
quotesRE = regexp.MustCompile(`(".*?")`)
|
||||||
// starRE = regexp.MustCompile(`(\*.*\*)`)
|
starRE = regexp.MustCompile(`(\*.*?\*)`)
|
||||||
basicSysMsg = `Large Language Model that helps user with any of his requests.`
|
basicSysMsg = `Large Language Model that helps user with any of his requests.`
|
||||||
toolSysMsg = `You're a helpful assistant.
|
toolSysMsg = `You're a helpful assistant.
|
||||||
# Tools
|
# Tools
|
||||||
|
|||||||
21
tui.go
21
tui.go
@@ -41,6 +41,13 @@ Press Enter to go back
|
|||||||
`
|
`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func colorText() {
|
||||||
|
// INFO: looks way too inefficient; use it with care or make it optional
|
||||||
|
tv := textView.GetText(false)
|
||||||
|
cq := quotesRE.ReplaceAllString(tv, `[orange:-:-]$1[-:-:-]`)
|
||||||
|
textView.SetText(starRE.ReplaceAllString(cq, `[turquoise::i]$1[-:-:-]`))
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
theme := tview.Theme{
|
theme := tview.Theme{
|
||||||
PrimitiveBackgroundColor: tcell.ColorDefault,
|
PrimitiveBackgroundColor: tcell.ColorDefault,
|
||||||
@@ -49,7 +56,7 @@ func init() {
|
|||||||
BorderColor: tcell.ColorGray,
|
BorderColor: tcell.ColorGray,
|
||||||
TitleColor: tcell.ColorRed,
|
TitleColor: tcell.ColorRed,
|
||||||
GraphicsColor: tcell.ColorBlue,
|
GraphicsColor: tcell.ColorBlue,
|
||||||
PrimaryTextColor: tcell.ColorOlive,
|
PrimaryTextColor: tcell.ColorLightGray,
|
||||||
SecondaryTextColor: tcell.ColorYellow,
|
SecondaryTextColor: tcell.ColorYellow,
|
||||||
TertiaryTextColor: tcell.ColorOrange,
|
TertiaryTextColor: tcell.ColorOrange,
|
||||||
InverseTextColor: tcell.ColorPurple,
|
InverseTextColor: tcell.ColorPurple,
|
||||||
@@ -79,10 +86,6 @@ func init() {
|
|||||||
AddItem(position, 0, 1, false)
|
AddItem(position, 0, 1, false)
|
||||||
updateStatusLine := func() {
|
updateStatusLine := func() {
|
||||||
position.SetText(fmt.Sprintf(indexLine, botRespMode, cfg.AssistantRole, activeChatName))
|
position.SetText(fmt.Sprintf(indexLine, botRespMode, cfg.AssistantRole, activeChatName))
|
||||||
// INFO: way too ineffective; it should be optional or removed
|
|
||||||
// tv := textView.GetText(false)
|
|
||||||
// cq := quotesRE.ReplaceAllString(tv, `[orange]$1[white]`)
|
|
||||||
// textView.SetText(starRE.ReplaceAllString(cq, `[yellow]$1[white]`))
|
|
||||||
}
|
}
|
||||||
chatOpts := []string{"cancel", "new", "rename current"}
|
chatOpts := []string{"cancel", "new", "rename current"}
|
||||||
chatList, err := loadHistoryChats()
|
chatList, err := loadHistoryChats()
|
||||||
@@ -113,6 +116,7 @@ func init() {
|
|||||||
activeChatName = newChat.Name
|
activeChatName = newChat.Name
|
||||||
chatMap[newChat.Name] = newChat
|
chatMap[newChat.Name] = newChat
|
||||||
pages.RemovePage("history")
|
pages.RemovePage("history")
|
||||||
|
colorText()
|
||||||
return
|
return
|
||||||
// set text
|
// set text
|
||||||
case "cancel":
|
case "cancel":
|
||||||
@@ -135,6 +139,7 @@ func init() {
|
|||||||
textView.SetText(chatToText(cfg.ShowSys))
|
textView.SetText(chatToText(cfg.ShowSys))
|
||||||
activeChatName = fn
|
activeChatName = fn
|
||||||
pages.RemovePage("history")
|
pages.RemovePage("history")
|
||||||
|
colorText()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -266,6 +271,7 @@ func init() {
|
|||||||
textArea.SetMovedFunc(updateStatusLine)
|
textArea.SetMovedFunc(updateStatusLine)
|
||||||
updateStatusLine()
|
updateStatusLine()
|
||||||
textView.SetText(chatToText(cfg.ShowSys))
|
textView.SetText(chatToText(cfg.ShowSys))
|
||||||
|
colorText()
|
||||||
textView.ScrollToEnd()
|
textView.ScrollToEnd()
|
||||||
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
||||||
if event.Key() == tcell.KeyF1 {
|
if event.Key() == tcell.KeyF1 {
|
||||||
@@ -335,11 +341,11 @@ func init() {
|
|||||||
}
|
}
|
||||||
if event.Key() == tcell.KeyCtrlE {
|
if event.Key() == tcell.KeyCtrlE {
|
||||||
textArea.SetText("pressed ctrl+e", true)
|
textArea.SetText("pressed ctrl+e", true)
|
||||||
|
colorText()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if event.Key() == tcell.KeyCtrlA {
|
if event.Key() == tcell.KeyCtrlA {
|
||||||
textArea.SetText("pressed ctrl+a", true)
|
textArea.SetText("pressed ctrl+a", true)
|
||||||
// list all agents
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if event.Key() == tcell.KeyCtrlS {
|
if event.Key() == tcell.KeyCtrlS {
|
||||||
@@ -369,9 +375,10 @@ func init() {
|
|||||||
// read all text into buffer
|
// read all text into buffer
|
||||||
msgText := textArea.GetText()
|
msgText := textArea.GetText()
|
||||||
if msgText != "" {
|
if msgText != "" {
|
||||||
fmt.Fprintf(textView, "\n(%d) <user>: %s\n", len(chatBody.Messages), msgText)
|
fmt.Fprintf(textView, "\n(%d) <user>: \n%s\n", len(chatBody.Messages), msgText)
|
||||||
textArea.SetText("", true)
|
textArea.SetText("", true)
|
||||||
textView.ScrollToEnd()
|
textView.ScrollToEnd()
|
||||||
|
colorText()
|
||||||
}
|
}
|
||||||
// update statue line
|
// update statue line
|
||||||
go chatRound(msgText, cfg.UserRole, textView, false)
|
go chatRound(msgText, cfg.UserRole, textView, false)
|
||||||
|
|||||||
Reference in New Issue
Block a user