mirror of
https://github.com/coalaura/whiskr.git
synced 2025-09-09 09:19:54 +00:00
cleanup styling, show reasoning, fixes & improvements
This commit is contained in:
51
prompts.go
Normal file
51
prompts.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"text/template"
|
||||
"time"
|
||||
)
|
||||
|
||||
type PromptData struct {
|
||||
Name string
|
||||
Slug string
|
||||
Date string
|
||||
}
|
||||
|
||||
var (
|
||||
//go:embed prompts/normal.txt
|
||||
PromptNormal string
|
||||
|
||||
PromptNormalTmpl = template.Must(template.New("normal").Parse(PromptNormal))
|
||||
)
|
||||
|
||||
func BuildPrompt(name string, model *Model) (string, error) {
|
||||
if name == "" {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
var tmpl *template.Template
|
||||
|
||||
switch name {
|
||||
case "normal":
|
||||
tmpl = PromptNormalTmpl
|
||||
default:
|
||||
return "", fmt.Errorf("unknown prompt: %q", name)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
||||
err := tmpl.Execute(&buf, PromptData{
|
||||
Name: model.Name,
|
||||
Slug: model.ID,
|
||||
Date: time.Now().Format(time.RFC1123),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return buf.String(), nil
|
||||
}
|
Reference in New Issue
Block a user