Enha: log level to props
This commit is contained in:
13
bot.go
13
bot.go
@@ -25,6 +25,7 @@ var httpClient = http.Client{}
|
|||||||
var (
|
var (
|
||||||
cfg *config.Config
|
cfg *config.Config
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
|
logLevel = new(slog.LevelVar)
|
||||||
activeChatName string
|
activeChatName string
|
||||||
chunkChan = make(chan string, 10)
|
chunkChan = make(chan string, 10)
|
||||||
streamDone = make(chan bool, 1)
|
streamDone = make(chan bool, 1)
|
||||||
@@ -67,7 +68,6 @@ func fetchModelName() *models.LLMModels {
|
|||||||
return &llmModel
|
return &llmModel
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: should be a part of server?
|
|
||||||
func sendMsgToLLM(body io.Reader) {
|
func sendMsgToLLM(body io.Reader) {
|
||||||
// nolint
|
// nolint
|
||||||
resp, err := httpClient.Post(cfg.CurrentAPI, "application/json", body)
|
resp, err := httpClient.Post(cfg.CurrentAPI, "application/json", body)
|
||||||
@@ -86,9 +86,10 @@ func sendMsgToLLM(body io.Reader) {
|
|||||||
counter++
|
counter++
|
||||||
if interruptResp {
|
if interruptResp {
|
||||||
interruptResp = false
|
interruptResp = false
|
||||||
logger.Info("interrupted bot response")
|
logger.Info("interrupted bot response", "chunk_counter", counter)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
// to stop from spiriling in infinity read of bad bytes that happens with poor connection
|
||||||
if cfg.ChunkLimit > 0 && counter > cfg.ChunkLimit {
|
if cfg.ChunkLimit > 0 && counter > cfg.ChunkLimit {
|
||||||
logger.Warn("response hit chunk limit", "limit", cfg.ChunkLimit)
|
logger.Warn("response hit chunk limit", "limit", cfg.ChunkLimit)
|
||||||
streamDone <- true
|
streamDone <- true
|
||||||
@@ -108,7 +109,7 @@ func sendMsgToLLM(body io.Reader) {
|
|||||||
}
|
}
|
||||||
// starts with -> data:
|
// starts with -> data:
|
||||||
line = line[6:]
|
line = line[6:]
|
||||||
logger.Info("debugging resp", "line", string(line))
|
logger.Debug("debugging resp", "line", string(line))
|
||||||
content, stop, err := chunkParser.ParseChunk(line)
|
content, stop, err := chunkParser.ParseChunk(line)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("error parsing response body", "error", err, "line", string(line), "url", cfg.CurrentAPI)
|
logger.Error("error parsing response body", "error", err, "line", string(line), "url", cfg.CurrentAPI)
|
||||||
@@ -158,7 +159,7 @@ func chatRagUse(qText string) (string, error) {
|
|||||||
}
|
}
|
||||||
// get raw text
|
// get raw text
|
||||||
resps := []string{}
|
resps := []string{}
|
||||||
logger.Info("sqlvec resp", "vecs len", len(respVecs))
|
logger.Debug("sqlvec resp", "vecs len", len(respVecs))
|
||||||
for _, rv := range respVecs {
|
for _, rv := range respVecs {
|
||||||
resps = append(resps, rv.RawText)
|
resps = append(resps, rv.RawText)
|
||||||
}
|
}
|
||||||
@@ -335,7 +336,8 @@ func init() {
|
|||||||
basicCard.Role = cfg.AssistantRole
|
basicCard.Role = cfg.AssistantRole
|
||||||
toolCard.Role = cfg.AssistantRole
|
toolCard.Role = cfg.AssistantRole
|
||||||
//
|
//
|
||||||
logger = slog.New(slog.NewTextHandler(logfile, nil))
|
logLevel.Set(slog.LevelInfo)
|
||||||
|
logger = slog.New(slog.NewTextHandler(logfile, &slog.HandlerOptions{Level: logLevel}))
|
||||||
store = storage.NewProviderSQL("test.db", logger)
|
store = storage.NewProviderSQL("test.db", logger)
|
||||||
if store == nil {
|
if store == nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -348,7 +350,6 @@ func init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
lastChat := loadOldChatOrGetNew()
|
lastChat := loadOldChatOrGetNew()
|
||||||
logger.Info("loaded history")
|
|
||||||
chatBody = &models.ChatBody{
|
chatBody = &models.ChatBody{
|
||||||
Model: "modl_name",
|
Model: "modl_name",
|
||||||
Stream: true,
|
Stream: true,
|
||||||
|
|||||||
4
llm.go
4
llm.go
@@ -16,11 +16,11 @@ type ChunkParser interface {
|
|||||||
func initChunkParser() {
|
func initChunkParser() {
|
||||||
chunkParser = LlamaCPPeer{}
|
chunkParser = LlamaCPPeer{}
|
||||||
if strings.Contains(cfg.CurrentAPI, "v1") {
|
if strings.Contains(cfg.CurrentAPI, "v1") {
|
||||||
logger.Info("chosen openai parser")
|
logger.Debug("chosen /v1/chat parser")
|
||||||
chunkParser = OpenAIer{}
|
chunkParser = OpenAIer{}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger.Info("chosen llamacpp parser")
|
logger.Debug("chosen llamacpp /completion parser")
|
||||||
}
|
}
|
||||||
|
|
||||||
type LlamaCPPeer struct {
|
type LlamaCPPeer struct {
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -12,7 +12,7 @@ var (
|
|||||||
botRespMode = false
|
botRespMode = false
|
||||||
editMode = false
|
editMode = false
|
||||||
selectedIndex = int(-1)
|
selectedIndex = int(-1)
|
||||||
indexLine = "F12 to show keys help | bot resp mode: %v (F6) | char: %s (ctrl+s) | chat: %s (F1) | RAGEnabled: %v (F11) | toolUseAdviced: %v (ctrl+k) | model: %s (ctrl+l)\nAPI_URL: %s (ctrl+v) | ThinkUse: %v (ctrl+p)"
|
indexLine = "F12 to show keys help | bot resp mode: %v (F6) | char: %s (ctrl+s) | chat: %s (F1) | RAGEnabled: %v (F11) | toolUseAdviced: %v (ctrl+k) | model: %s (ctrl+l)\nAPI_URL: %s (ctrl+v) | ThinkUse: %v (ctrl+p) | Log Level: %v (ctrl+p)"
|
||||||
focusSwitcher = map[tview.Primitive]tview.Primitive{}
|
focusSwitcher = map[tview.Primitive]tview.Primitive{}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
10
rag/main.go
10
rag/main.go
@@ -49,7 +49,7 @@ func (r *RAG) LoadRAG(fpath string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
r.logger.Info("rag: loaded file", "fp", fpath)
|
r.logger.Debug("rag: loaded file", "fp", fpath)
|
||||||
LongJobStatusCh <- LoadedFileRAGStatus
|
LongJobStatusCh <- LoadedFileRAGStatus
|
||||||
fileText := string(data)
|
fileText := string(data)
|
||||||
tokenizer, err := english.NewSentenceTokenizer(nil)
|
tokenizer, err := english.NewSentenceTokenizer(nil)
|
||||||
@@ -105,7 +105,7 @@ func (r *RAG) LoadRAG(fpath string) error {
|
|||||||
ctn++
|
ctn++
|
||||||
}
|
}
|
||||||
finishedBatchesMsg := fmt.Sprintf("finished batching batches#: %d; paragraphs: %d; sentences: %d\n", len(batchCh), len(paragraphs), len(sents))
|
finishedBatchesMsg := fmt.Sprintf("finished batching batches#: %d; paragraphs: %d; sentences: %d\n", len(batchCh), len(paragraphs), len(sents))
|
||||||
r.logger.Info(finishedBatchesMsg)
|
r.logger.Debug(finishedBatchesMsg)
|
||||||
LongJobStatusCh <- finishedBatchesMsg
|
LongJobStatusCh <- finishedBatchesMsg
|
||||||
for w := 0; w < workers; w++ {
|
for w := 0; w < workers; w++ {
|
||||||
go r.batchToVectorHFAsync(lock, w, batchCh, vectorCh, errCh, doneCh, path.Base(fpath))
|
go r.batchToVectorHFAsync(lock, w, batchCh, vectorCh, errCh, doneCh, path.Base(fpath))
|
||||||
@@ -127,9 +127,9 @@ func (r *RAG) writeVectors(vectorCh chan []models.VectorRow) error {
|
|||||||
// return err
|
// return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r.logger.Info("wrote batch to db", "size", len(batch), "vector_chan_len", len(vectorCh))
|
r.logger.Debug("wrote batch to db", "size", len(batch), "vector_chan_len", len(vectorCh))
|
||||||
if len(vectorCh) == 0 {
|
if len(vectorCh) == 0 {
|
||||||
r.logger.Info("finished writing vectors")
|
r.logger.Debug("finished writing vectors")
|
||||||
LongJobStatusCh <- FinishedRAGStatus
|
LongJobStatusCh <- FinishedRAGStatus
|
||||||
defer close(vectorCh)
|
defer close(vectorCh)
|
||||||
return nil
|
return nil
|
||||||
@@ -160,7 +160,7 @@ func (r *RAG) batchToVectorHFAsync(lock *sync.Mutex, id int, inputCh <-chan map[
|
|||||||
lock.Unlock()
|
lock.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r.logger.Info("to vector batches", "batches#", len(inputCh), "worker#", id)
|
r.logger.Debug("to vector batches", "batches#", len(inputCh), "worker#", id)
|
||||||
LongJobStatusCh <- fmt.Sprintf("converted to vector; batches: %d, worker#: %d", len(inputCh), id)
|
LongJobStatusCh <- fmt.Sprintf("converted to vector; batches: %d, worker#: %d", len(inputCh), id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func (p *ProviderSQL) Migrate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.logger.Info("All migrations executed successfully!")
|
p.logger.Debug("All migrations executed successfully!")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProviderSQL) executeMigration(migrationsDir fs.FS, fileName string) error {
|
func (p *ProviderSQL) executeMigration(migrationsDir fs.FS, fileName string) error {
|
||||||
|
|||||||
@@ -173,7 +173,6 @@ func makeRAGTable(fileList []string) *tview.Flex {
|
|||||||
close(errCh)
|
close(errCh)
|
||||||
return
|
return
|
||||||
case status := <-rag.LongJobStatusCh:
|
case status := <-rag.LongJobStatusCh:
|
||||||
logger.Info("reading status channel", "status", status)
|
|
||||||
longStatusView.SetText(status)
|
longStatusView.SetText(status)
|
||||||
// fmt.Fprintln(longStatusView, status)
|
// fmt.Fprintln(longStatusView, status)
|
||||||
// app.Sync()
|
// app.Sync()
|
||||||
@@ -366,7 +365,6 @@ func makeCodeBlockTable(codeBlocks []string) *tview.Table {
|
|||||||
rows, cols := len(codeBlocks), len(actions)+1
|
rows, cols := len(codeBlocks), len(actions)+1
|
||||||
table := tview.NewTable().
|
table := tview.NewTable().
|
||||||
SetBorders(true)
|
SetBorders(true)
|
||||||
logger.Info("creating codeblock table", "len#", len(codeBlocks), "data", codeBlocks)
|
|
||||||
for r := 0; r < rows; r++ {
|
for r := 0; r < rows; r++ {
|
||||||
for c := 0; c < cols; c++ {
|
for c := 0; c < cols; c++ {
|
||||||
color := tcell.ColorWhite
|
color := tcell.ColorWhite
|
||||||
@@ -387,7 +385,6 @@ func makeCodeBlockTable(codeBlocks []string) *tview.Table {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.Info("filled table", "len#", len(codeBlocks), "data", codeBlocks)
|
|
||||||
table.Select(0, 0).SetFixed(1, 1).SetDoneFunc(func(key tcell.Key) {
|
table.Select(0, 0).SetFixed(1, 1).SetDoneFunc(func(key tcell.Key) {
|
||||||
if key == tcell.KeyEsc || key == tcell.KeyF1 {
|
if key == tcell.KeyEsc || key == tcell.KeyF1 {
|
||||||
pages.RemovePage(agentPage)
|
pages.RemovePage(agentPage)
|
||||||
|
|||||||
21
tui.go
21
tui.go
@@ -135,7 +135,7 @@ func colorText() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateStatusLine() {
|
func updateStatusLine() {
|
||||||
position.SetText(fmt.Sprintf(indexLine, botRespMode, cfg.AssistantRole, activeChatName, cfg.RAGEnabled, cfg.ToolUse, currentModel, cfg.CurrentAPI, cfg.ThinkUse))
|
position.SetText(fmt.Sprintf(indexLine, botRespMode, cfg.AssistantRole, activeChatName, cfg.RAGEnabled, cfg.ToolUse, currentModel, cfg.CurrentAPI, cfg.ThinkUse, logLevel.Level()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func initSysCards() ([]string, error) {
|
func initSysCards() ([]string, error) {
|
||||||
@@ -180,16 +180,33 @@ func startNewChat() {
|
|||||||
colorText()
|
colorText()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setLogLevel(sl string) {
|
||||||
|
switch sl {
|
||||||
|
case "Debug":
|
||||||
|
logLevel.Set(-4)
|
||||||
|
case "Info":
|
||||||
|
logLevel.Set(0)
|
||||||
|
case "Warn":
|
||||||
|
logLevel.Set(4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func makePropsForm(props map[string]float32) *tview.Form {
|
func makePropsForm(props map[string]float32) *tview.Form {
|
||||||
|
// https://github.com/rivo/tview/commit/0a18dea458148770d212d348f656988df75ff341
|
||||||
|
// no way to close a form by a key press; a shame.
|
||||||
form := tview.NewForm().
|
form := tview.NewForm().
|
||||||
AddTextView("Notes", "Props for llamacpp completion call", 40, 2, true, false).
|
AddTextView("Notes", "Props for llamacpp completion call", 40, 2, true, false).
|
||||||
AddCheckbox("Insert <think> (/completion only)", cfg.ThinkUse, func(checked bool) {
|
AddCheckbox("Insert <think> (/completion only)", cfg.ThinkUse, func(checked bool) {
|
||||||
cfg.ThinkUse = checked
|
cfg.ThinkUse = checked
|
||||||
|
}).AddDropDown("Set log level (Enter): ", []string{"Debug", "Info", "Warn"}, 1,
|
||||||
|
func(option string, optionIndex int) {
|
||||||
|
setLogLevel(option)
|
||||||
}).
|
}).
|
||||||
AddButton("Quit", func() {
|
AddButton("Quit", func() {
|
||||||
pages.RemovePage(propsPage)
|
pages.RemovePage(propsPage)
|
||||||
})
|
})
|
||||||
form.AddButton("Save", func() {
|
form.AddButton("Save", func() {
|
||||||
|
defer updateStatusLine()
|
||||||
defer pages.RemovePage(propsPage)
|
defer pages.RemovePage(propsPage)
|
||||||
for pn := range props {
|
for pn := range props {
|
||||||
propField, ok := form.GetFormItemByLabel(pn).(*tview.InputField)
|
propField, ok := form.GetFormItemByLabel(pn).(*tview.InputField)
|
||||||
@@ -442,7 +459,7 @@ func init() {
|
|||||||
text := textView.GetText(true)
|
text := textView.GetText(true)
|
||||||
assistantIcon := roleToIcon(cfg.AssistantRole)
|
assistantIcon := roleToIcon(cfg.AssistantRole)
|
||||||
if strings.HasSuffix(text, assistantIcon) {
|
if strings.HasSuffix(text, assistantIcon) {
|
||||||
logger.Info("deleting assistant icon", "icon", assistantIcon)
|
logger.Debug("deleting assistant icon", "icon", assistantIcon)
|
||||||
textView.SetText(strings.TrimSuffix(text, assistantIcon))
|
textView.SetText(strings.TrimSuffix(text, assistantIcon))
|
||||||
colorText()
|
colorText()
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user