Files

36 lines
1.0 KiB
Go

package judgegate
import (
"encoding/json"
"fmt"
"io/fs"
"github.com/samcharles93/archipelago/sdk/systemone"
)
// ChoicePrompt is a choice question kept as a file: the instructions and what
// each label means.
type ChoicePrompt struct {
Instructions string `json:"instructions"`
Criteria map[string]string `json:"criteria"`
}
// LoadChoice reads the choice question stored as prompts/<name>.json. Every
// instruction sent to a model is a file, never inline in code.
func LoadChoice(files fs.FS, name string) (ChoicePrompt, error) {
data, err := fs.ReadFile(files, "prompts/"+name+".json")
if err != nil {
return ChoicePrompt{}, fmt.Errorf("prompt %s: %w", name, err)
}
var p ChoicePrompt
if err := json.Unmarshal(data, &p); err != nil {
return ChoicePrompt{}, fmt.Errorf("prompt %s: %w", name, err)
}
return p, nil
}
// Question is the prompt as a System One choice question.
func (p ChoicePrompt) Question() systemone.Question {
return systemone.Choice(p.Instructions, p.Criteria)
}