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]) + " ..." }