mirror of
https://github.com/danielmiessler/Fabric.git
synced 2026-02-13 07:25:10 -05:00
## CHANGES - Add suppress-think flag to hide thinking blocks - Configure customizable start and end thinking tags - Strip thinking content from final response output - Update streaming logic to respect suppress-think setting - Add YAML configuration support for thinking options - Implement StripThinkBlocks utility function for content filtering - Add comprehensive tests for thinking suppression functionality
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/danielmiessler/fabric/internal/core"
|
|
"github.com/danielmiessler/fabric/internal/domain"
|
|
"github.com/danielmiessler/fabric/internal/plugins/db/fsdb"
|
|
)
|
|
|
|
// handleChatProcessing handles the main chat processing logic
|
|
func handleChatProcessing(currentFlags *Flags, registry *core.PluginRegistry, messageTools string) (err error) {
|
|
if messageTools != "" {
|
|
currentFlags.AppendMessage(messageTools)
|
|
}
|
|
|
|
var chatter *core.Chatter
|
|
if chatter, err = registry.GetChatter(currentFlags.Model, currentFlags.ModelContextLength,
|
|
currentFlags.Strategy, currentFlags.Stream, currentFlags.DryRun); err != nil {
|
|
return
|
|
}
|
|
|
|
var session *fsdb.Session
|
|
var chatReq *domain.ChatRequest
|
|
if chatReq, err = currentFlags.BuildChatRequest(strings.Join(os.Args[1:], " ")); err != nil {
|
|
return
|
|
}
|
|
|
|
if chatReq.Language == "" {
|
|
chatReq.Language = registry.Language.DefaultLanguage.Value
|
|
}
|
|
var chatOptions *domain.ChatOptions
|
|
if chatOptions, err = currentFlags.BuildChatOptions(); err != nil {
|
|
return
|
|
}
|
|
if session, err = chatter.Send(chatReq, chatOptions); err != nil {
|
|
return
|
|
}
|
|
|
|
result := session.GetLastMessage().Content
|
|
|
|
if !currentFlags.Stream || currentFlags.SuppressThink {
|
|
// print the result if it was not streamed already or suppress-think disabled streaming output
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// if the copy flag is set, copy the message to the clipboard
|
|
if currentFlags.Copy {
|
|
if err = CopyToClipboard(result); err != nil {
|
|
return
|
|
}
|
|
}
|
|
|
|
// if the output flag is set, create an output file
|
|
if currentFlags.Output != "" {
|
|
if currentFlags.OutputSession {
|
|
sessionAsString := session.String()
|
|
err = CreateOutputFile(sessionAsString, currentFlags.Output)
|
|
} else {
|
|
err = CreateOutputFile(result, currentFlags.Output)
|
|
}
|
|
}
|
|
return
|
|
}
|