29 lines
736 B
Go
29 lines
736 B
Go
// Package prompts provides the embedded system prompt template.
|
|
package prompts
|
|
|
|
import (
|
|
_ "embed"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
//go:embed system_prompt.md
|
|
var DefaultSystemPrompt string
|
|
|
|
// ResolveSystemPrompt expands env vars in overridePath, then tries to read the
|
|
// file from the filesystem. If the file doesn't exist, the embedded default is
|
|
// returned.
|
|
func ResolveSystemPrompt(overridePath string) string {
|
|
if overridePath == "" {
|
|
return DefaultSystemPrompt
|
|
}
|
|
expanded := os.Expand(overridePath, os.Getenv)
|
|
data, err := os.ReadFile(expanded)
|
|
if err == nil {
|
|
return strings.TrimRight(string(data), "\n")
|
|
}
|
|
fmt.Fprintf(os.Stderr, "system_prompt %q: %v (using default)\n", expanded, err)
|
|
return DefaultSystemPrompt
|
|
}
|