Move embedded prompts to PromptKit definitions
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
@@ -16,6 +17,7 @@ type Key string
|
||||
const (
|
||||
CorrectionSetKey Key = "correction_set"
|
||||
ValidatorDecisionSetKey Key = "validator_decision_set"
|
||||
AssetRoot = "assets"
|
||||
correctionSetSchemaID = "audita.correction_set"
|
||||
validatorDecisionSchemaID = "audita.validator_decision_set"
|
||||
schemaVersionV1 = "v1"
|
||||
@@ -24,6 +26,20 @@ const (
|
||||
//go:embed assets/*.json
|
||||
var schemaAssets embed.FS
|
||||
|
||||
// Filesystem exposes the canonical embedded schemas to PromptKit.
|
||||
func Filesystem() fs.FS { return schemaAssets }
|
||||
|
||||
func AssetPath(key Key) (string, bool) {
|
||||
switch key {
|
||||
case CorrectionSetKey:
|
||||
return "correction_set.v1.json", true
|
||||
case ValidatorDecisionSetKey:
|
||||
return "validator_decision_set.v1.json", true
|
||||
default:
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
|
||||
// Schema describes one registered structured response schema.
|
||||
type Schema struct {
|
||||
ID string `json:"id"`
|
||||
|
||||
@@ -5,9 +5,31 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPromptKitSchemaPathsUseCanonicalAssets(t *testing.T) {
|
||||
for _, key := range []Key{CorrectionSetKey, ValidatorDecisionSetKey} {
|
||||
path, ok := AssetPath(key)
|
||||
if !ok {
|
||||
t.Fatalf("missing path for %q", key)
|
||||
}
|
||||
file, err := Filesystem().Open(AssetRoot + "/" + path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err := io.ReadAll(file)
|
||||
file.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Equal(data, MustLookup(key).JSONSchema) {
|
||||
t.Fatalf("PromptKit schema differs for %q", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
expectedCorrectionSetSHA256 = "b86a2dde38d7f440d26470fa8830167512bb0aa1b35e5fee5547057be583c388"
|
||||
expectedValidatorDecisionSetSHA256 = "2fe90d450e2595b57885aba91c8cc5cedf783dd36758ab430309e3eace401f54"
|
||||
|
||||
Reference in New Issue
Block a user