Feat (pull/18994): llama.cpp reasoning

This commit is contained in:
Grail Finder
2026-02-21 16:31:59 +03:00
parent 96ffbd5cf5
commit eedda0ec4b
4 changed files with 12 additions and 5 deletions

1
bot.go
View File

@@ -653,7 +653,6 @@ func sendMsgToLLM(body io.Reader) {
reasoningText := "<think>" + reasoningBuffer.String() + "</think>" reasoningText := "<think>" + reasoningBuffer.String() + "</think>"
answerText = strings.ReplaceAll(reasoningText, "\n\n", "\n") answerText = strings.ReplaceAll(reasoningText, "\n\n", "\n")
chunkChan <- answerText chunkChan <- answerText
reasoningSent = true
} }
if chunk.Chunk != "" { if chunk.Chunk != "" {
logger.Warn("text inside of finish llmchunk", "chunk", chunk, "counter", counter) logger.Warn("text inside of finish llmchunk", "chunk", chunk, "counter", counter)

6
llm.go
View File

@@ -237,8 +237,10 @@ func (op LCPChat) ParseChunk(data []byte) (*models.TextChunk, error) {
return &models.TextChunk{Finished: true}, nil return &models.TextChunk{Finished: true}, nil
} }
lastChoice := llmchunk.Choices[len(llmchunk.Choices)-1]
resp := &models.TextChunk{ resp := &models.TextChunk{
Chunk: llmchunk.Choices[len(llmchunk.Choices)-1].Delta.Content, Chunk: lastChoice.Delta.Content,
Reasoning: lastChoice.Delta.ReasoningContent,
} }
// Check for tool calls in all choices, not just the last one // Check for tool calls in all choices, not just the last one
@@ -256,7 +258,7 @@ func (op LCPChat) ParseChunk(data []byte) (*models.TextChunk, error) {
} }
} }
if llmchunk.Choices[len(llmchunk.Choices)-1].FinishReason == "stop" { if lastChoice.FinishReason == "stop" {
if resp.Chunk != "" { if resp.Chunk != "" {
logger.Error("text inside of finish llmchunk", "chunk", llmchunk) logger.Error("text inside of finish llmchunk", "chunk", llmchunk)
} }

View File

@@ -65,6 +65,7 @@ type LLMRespChunk struct {
Index int `json:"index"` Index int `json:"index"`
Delta struct { Delta struct {
Content string `json:"content"` Content string `json:"content"`
ReasoningContent string `json:"reasoning_content"`
ToolCalls []ToolDeltaResp `json:"tool_calls"` ToolCalls []ToolDeltaResp `json:"tool_calls"`
} `json:"delta"` } `json:"delta"`
} `json:"choices"` } `json:"choices"`

View File

@@ -149,6 +149,11 @@ func makePropsTable(props map[string]float32) *tview.Table {
addListPopupRow("Set log level", logLevels, GetLogLevel(), func(option string) { addListPopupRow("Set log level", logLevels, GetLogLevel(), func(option string) {
setLogLevel(option) setLogLevel(option)
}) })
// Add reasoning effort dropdown (for OpenRouter and supported APIs)
reasoningEfforts := []string{"", "none", "minimal", "low", "medium", "high", "xhigh"}
addListPopupRow("Reasoning effort (OR)", reasoningEfforts, cfg.ReasoningEffort, func(option string) {
cfg.ReasoningEffort = option
})
// Helper function to get model list for a given API // Helper function to get model list for a given API
getModelListForAPI := func(api string) []string { getModelListForAPI := func(api string) []string {
if strings.Contains(api, "api.deepseek.com/") { if strings.Contains(api, "api.deepseek.com/") {