before result functions add

This commit is contained in:
2025-10-21 09:10:22 +06:00
parent 04d785db77
commit 47671eb566
8 changed files with 692 additions and 389 deletions

48
response.go Normal file
View File

@@ -0,0 +1,48 @@
package main
import (
"fmt"
"os"
"path"
"time"
"github.com/direct-dev-ru/linux-command-gpt/config"
)
func nowTimestamp() string {
return time.Now().Format("2006-01-02_15-04-05")
}
func pathJoin(base, name string) string {
return path.Join(base, name)
}
func writeFile(filePath, content string) {
if err := os.WriteFile(filePath, []byte(content), 0644); err != nil {
fmt.Println("Failed to save response:", err)
} else {
fmt.Printf("Saved to %s\n", filePath)
}
}
func saveResponse(response string, gpt3Model string, prompt string, cmd string) {
timestamp := nowTimestamp()
filename := fmt.Sprintf("gpt_request_%s_%s.md", gpt3Model, timestamp)
filePath := pathJoin(config.AppConfig.ResultFolder, filename)
title := truncateTitle(cmd)
content := fmt.Sprintf("# %s\n\n## Prompt\n\n%s\n\n## Response\n\n%s\n", title, cmd+". "+prompt, response)
writeFile(filePath, content)
}
func truncateTitle(s string) string {
const maxLen = 120
if runeCount := len([]rune(s)); runeCount <= maxLen {
return s
}
const head = 116
r := []rune(s)
if len(r) <= head {
return s
}
return string(r[:head]) + " ..."
}