86 lines
3.7 KiB
Go
86 lines
3.7 KiB
Go
package locationoccurrences
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/llm"
|
|
"gitea.maximumdirect.net/eric/promptkit"
|
|
)
|
|
|
|
func TestRegisterPromptAssetsPreparesLocationOccurrencePrompt(t *testing.T) {
|
|
registry := llm.NewAssetRegistry()
|
|
if err := RegisterPromptAssets(registry); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
options, err := registry.PromptKitOptions()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
options = append(options, promptkit.WithProfiles(promptkit.OpenAICompatibleProfile(promptkit.OpenAICompatibleProfileConfig{
|
|
ID: "location-occurrences-test", Endpoint: "http://127.0.0.1:1/v1", Model: "test",
|
|
})))
|
|
engine, err := promptkit.NewEngine(promptkit.Config{Timeout: time.Second}, options...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
prepared, err := engine.Prepare(context.Background(), promptkit.RunRequest{
|
|
PromptID: PromptID, PromptVersion: SchemaVersion, ProfileID: "location-occurrences-test",
|
|
Inputs: map[string]promptkit.ArtifactRef{
|
|
"transcript": promptkit.Inline(`{"units":[{"sentinel":"location-occurrence-transcript"}]}`), "players": promptkit.Inline("location-occurrence-player"), "party": promptkit.Inline(" "), "glossary": promptkit.Inline(" "),
|
|
"locations": promptkit.Inline(`{"locations":[{"id":"location:sha256:test","name":"location-occurrence-registry"}]}`),
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if prepared.PromptID != PromptID || prepared.OutputContract.SchemaPath != "dnd_location_occurrences_llm.v1.json" {
|
|
t.Fatalf("prepared prompt = %#v", prepared)
|
|
}
|
|
var registryMessage string
|
|
referenceIndex := -1
|
|
transcriptIndex := -1
|
|
registryIndex := -1
|
|
evidenceIndex := -1
|
|
for index, message := range prepared.Messages {
|
|
if strings.Contains(message.Content, "location-occurrence-player") {
|
|
referenceIndex = index
|
|
}
|
|
if strings.Contains(message.Content, "location-occurrence-transcript") {
|
|
transcriptIndex = index
|
|
}
|
|
if strings.Contains(message.Content, "normalized location registry") {
|
|
registryMessage = message.Content
|
|
registryIndex = index
|
|
}
|
|
if strings.Contains(message.Content, "Transcript units are the only evidence") {
|
|
evidenceIndex = index
|
|
}
|
|
}
|
|
if !strings.Contains(registryMessage, "location:sha256:test") || !strings.Contains(registryMessage, "location-occurrence-registry") || strings.Contains(registryMessage, "source_refs") {
|
|
t.Fatalf("rendered prompt did not preserve source-free registry grounding: %s", registryMessage)
|
|
}
|
|
instructionsIndex := len(prepared.Messages) - 1
|
|
if referenceIndex < 0 || transcriptIndex <= referenceIndex || evidenceIndex <= transcriptIndex || registryIndex <= evidenceIndex || instructionsIndex <= registryIndex {
|
|
t.Fatalf("message order = references %d, transcript %d, evidence %d, registry %d, instructions %d; want that order", referenceIndex, transcriptIndex, evidenceIndex, registryIndex, instructionsIndex)
|
|
}
|
|
for _, index := range []int{referenceIndex, transcriptIndex, instructionsIndex} {
|
|
if cache := prepared.Messages[index].CacheControl; cache == nil || cache.Type != promptkit.CacheControlEphemeral {
|
|
t.Fatalf("message %d cache control = %#v, want ephemeral", index, cache)
|
|
}
|
|
}
|
|
for index, message := range prepared.Messages {
|
|
if index != referenceIndex && strings.Contains(message.Content, "location-occurrence-player") {
|
|
t.Errorf("message %d unexpectedly rendered campaign-reference input", index)
|
|
}
|
|
if index != transcriptIndex && strings.Contains(message.Content, "location-occurrence-transcript") {
|
|
t.Errorf("message %d unexpectedly rendered transcript input", index)
|
|
}
|
|
if index != registryIndex && strings.Contains(message.Content, "location-occurrence-registry") {
|
|
t.Errorf("message %d unexpectedly rendered registry grounding input", index)
|
|
}
|
|
}
|
|
}
|