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 (
|
||||
cfg *config.Config
|
||||
logger *slog.Logger
|
||||
logLevel = new(slog.LevelVar)
|
||||
activeChatName string
|
||||
chunkChan = make(chan string, 10)
|
||||
streamDone = make(chan bool, 1)
|
||||
@@ -67,7 +68,6 @@ func fetchModelName() *models.LLMModels {
|
||||
return &llmModel
|
||||
}
|
||||
|
||||
// TODO: should be a part of server?
|
||||
func sendMsgToLLM(body io.Reader) {
|
||||
// nolint
|
||||
resp, err := httpClient.Post(cfg.CurrentAPI, "application/json", body)
|
||||
@@ -86,9 +86,10 @@ func sendMsgToLLM(body io.Reader) {
|
||||
counter++
|
||||
if interruptResp {
|
||||
interruptResp = false
|
||||
logger.Info("interrupted bot response")
|
||||
logger.Info("interrupted bot response", "chunk_counter", counter)
|
||||
break
|
||||
}
|
||||
// to stop from spiriling in infinity read of bad bytes that happens with poor connection
|
||||
if cfg.ChunkLimit > 0 && counter > cfg.ChunkLimit {
|
||||
logger.Warn("response hit chunk limit", "limit", cfg.ChunkLimit)
|
||||
streamDone <- true
|
||||
@@ -108,7 +109,7 @@ func sendMsgToLLM(body io.Reader) {
|
||||
}
|
||||
// starts with -> data:
|
||||
line = line[6:]
|
||||
logger.Info("debugging resp", "line", string(line))
|
||||
logger.Debug("debugging resp", "line", string(line))
|
||||
content, stop, err := chunkParser.ParseChunk(line)
|
||||
if err != nil {
|
||||
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
|
||||
resps := []string{}
|
||||
logger.Info("sqlvec resp", "vecs len", len(respVecs))
|
||||
logger.Debug("sqlvec resp", "vecs len", len(respVecs))
|
||||
for _, rv := range respVecs {
|
||||
resps = append(resps, rv.RawText)
|
||||
}
|
||||
@@ -335,7 +336,8 @@ func init() {
|
||||
basicCard.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)
|
||||
if store == nil {
|
||||
os.Exit(1)
|
||||
@@ -348,7 +350,6 @@ func init() {
|
||||
return
|
||||
}
|
||||
lastChat := loadOldChatOrGetNew()
|
||||
logger.Info("loaded history")
|
||||
chatBody = &models.ChatBody{
|
||||
Model: "modl_name",
|
||||
Stream: true,
|
||||
|
||||
4
llm.go
4
llm.go
@@ -16,11 +16,11 @@ type ChunkParser interface {
|
||||
func initChunkParser() {
|
||||
chunkParser = LlamaCPPeer{}
|
||||
if strings.Contains(cfg.CurrentAPI, "v1") {
|
||||
logger.Info("chosen openai parser")
|
||||
logger.Debug("chosen /v1/chat parser")
|
||||
chunkParser = OpenAIer{}
|
||||
return
|
||||
}
|
||||
logger.Info("chosen llamacpp parser")
|
||||
logger.Debug("chosen llamacpp /completion parser")
|
||||
}
|
||||
|
||||
type LlamaCPPeer struct {
|
||||
|
||||
2
main.go
2
main.go
@@ -12,7 +12,7 @@ var (
|
||||
botRespMode = false
|
||||
editMode = false
|
||||
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{}
|
||||
)
|
||||
|
||||
|
||||
10
rag/main.go
10
rag/main.go
@@ -49,7 +49,7 @@ func (r *RAG) LoadRAG(fpath string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r.logger.Info("rag: loaded file", "fp", fpath)
|
||||
r.logger.Debug("rag: loaded file", "fp", fpath)
|
||||
LongJobStatusCh <- LoadedFileRAGStatus
|
||||
fileText := string(data)
|
||||
tokenizer, err := english.NewSentenceTokenizer(nil)
|
||||
@@ -105,7 +105,7 @@ func (r *RAG) LoadRAG(fpath string) error {
|
||||
ctn++
|
||||
}
|
||||
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
|
||||
for w := 0; w < workers; w++ {
|
||||
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
|
||||
}
|
||||
}
|
||||
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 {
|
||||
r.logger.Info("finished writing vectors")
|
||||
r.logger.Debug("finished writing vectors")
|
||||
LongJobStatusCh <- FinishedRAGStatus
|
||||
defer close(vectorCh)
|
||||
return nil
|
||||
@@ -160,7 +160,7 @@ func (r *RAG) batchToVectorHFAsync(lock *sync.Mutex, id int, inputCh <-chan map[
|
||||
lock.Unlock()
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -173,7 +173,6 @@ func makeRAGTable(fileList []string) *tview.Flex {
|
||||
close(errCh)
|
||||
return
|
||||
case status := <-rag.LongJobStatusCh:
|
||||
logger.Info("reading status channel", "status", status)
|
||||
longStatusView.SetText(status)
|
||||
// fmt.Fprintln(longStatusView, status)
|
||||
// app.Sync()
|
||||
@@ -366,7 +365,6 @@ func makeCodeBlockTable(codeBlocks []string) *tview.Table {
|
||||
rows, cols := len(codeBlocks), len(actions)+1
|
||||
table := tview.NewTable().
|
||||
SetBorders(true)
|
||||
logger.Info("creating codeblock table", "len#", len(codeBlocks), "data", codeBlocks)
|
||||
for r := 0; r < rows; r++ {
|
||||
for c := 0; c < cols; c++ {
|
||||
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) {
|
||||
if key == tcell.KeyEsc || key == tcell.KeyF1 {
|
||||
pages.RemovePage(agentPage)
|
||||
|
||||
21
tui.go
21
tui.go
@@ -135,7 +135,7 @@ func colorText() {
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -180,16 +180,33 @@ func startNewChat() {
|
||||
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 {
|
||||
// https://github.com/rivo/tview/commit/0a18dea458148770d212d348f656988df75ff341
|
||||
// no way to close a form by a key press; a shame.
|
||||
form := tview.NewForm().
|
||||
AddTextView("Notes", "Props for llamacpp completion call", 40, 2, true, false).
|
||||
AddCheckbox("Insert <think> (/completion only)", cfg.ThinkUse, func(checked bool) {
|
||||
cfg.ThinkUse = checked
|
||||
}).AddDropDown("Set log level (Enter): ", []string{"Debug", "Info", "Warn"}, 1,
|
||||
func(option string, optionIndex int) {
|
||||
setLogLevel(option)
|
||||
}).
|
||||
AddButton("Quit", func() {
|
||||
pages.RemovePage(propsPage)
|
||||
})
|
||||
form.AddButton("Save", func() {
|
||||
defer updateStatusLine()
|
||||
defer pages.RemovePage(propsPage)
|
||||
for pn := range props {
|
||||
propField, ok := form.GetFormItemByLabel(pn).(*tview.InputField)
|
||||
@@ -442,7 +459,7 @@ func init() {
|
||||
text := textView.GetText(true)
|
||||
assistantIcon := roleToIcon(cfg.AssistantRole)
|
||||
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))
|
||||
colorText()
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user