Fix dry run

This commit is contained in:
Azwar Tamim 2024-08-29 15:46:48 +07:00
parent 4006f3f417
commit 7d3bf8c3a2

View File

@ -143,10 +143,38 @@ func Cli() (message string, err error) {
}
if currentFlags.DryRun {
fmt.Println("Dry run: Would send the following request:")
fmt.Printf("Chat Request: %+v\n", currentFlags.BuildChatRequest())
fmt.Printf("Chat Options: %+v\n", currentFlags.BuildChatOptions())
return
var patternContent string
var contextContent string
if currentFlags.Pattern != "" {
pattern, patternErr := fabric.Db.Patterns.GetPattern(currentFlags.Pattern)
if patternErr != nil {
fmt.Printf("Error getting pattern content: %v\n", patternErr)
return "", patternErr
}
patternContent = pattern.Pattern // Assuming the content is stored in the 'Pattern' field
}
if currentFlags.Context != "" {
context, contextErr := fabric.Db.Contexts.GetContext(currentFlags.Context)
if contextErr != nil {
fmt.Printf("Error getting context content: %v\n", contextErr)
return "", contextErr
}
contextContent = context.Content
}
systemMessage := strings.TrimSpace(contextContent) + strings.TrimSpace(patternContent)
userMessage := strings.TrimSpace(currentFlags.Message)
fmt.Println("Dry run: Would send the following request:\n")
if systemMessage != "" {
fmt.Printf("System:\n%s\n\n", systemMessage)
}
if userMessage != "" {
fmt.Printf("User:\n%s\n", userMessage)
}
return "", nil
}
var chatter *core.Chatter