mirror of
https://github.com/kardolus/chatgpt-cli.git
synced 2024-09-08 23:15:00 +03:00
30 lines
689 B
Go
30 lines
689 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func FormatPrompt(str string, counter, usage int, now time.Time) string {
|
|
variables := map[string]string{
|
|
"%datetime": now.Format("2006-01-02 15:04:05"),
|
|
"%date": now.Format("2006-01-02"),
|
|
"%time": now.Format("15:04:05"),
|
|
"%counter": fmt.Sprintf("%d", counter),
|
|
"%usage": fmt.Sprintf("%d", usage),
|
|
}
|
|
|
|
// Replace placeholders in the order of longest to shortest
|
|
for _, key := range []string{"%datetime", "%date", "%time", "%counter", "%usage"} {
|
|
str = strings.ReplaceAll(str, key, variables[key])
|
|
}
|
|
|
|
// Ensure the last character is a space
|
|
if !strings.HasSuffix(str, " ") {
|
|
str += " "
|
|
}
|
|
|
|
return str
|
|
}
|