Consolidate spell and combat turn instructions
This commit is contained in:
@@ -17,7 +17,6 @@ var promptAssetManifest = shared.PromptAssetManifest{
|
||||
ModuleDir: "dnd.combat_turns",
|
||||
ModuleFiles: []promptfs.ModulePromptFile{
|
||||
{Name: "prompt.yaml", Path: "prompts/prompt.yaml"},
|
||||
{Name: "task.md", Path: "prompts/task.md"},
|
||||
{Name: "instructions.md", Path: "prompts/instructions.md"},
|
||||
},
|
||||
SharedFiles: []string{
|
||||
|
||||
@@ -45,15 +45,15 @@ func TestPromptAssetsPrepareRequiredInputs(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("NewEngine() error = %v, want nil", err)
|
||||
}
|
||||
transcript := `{"units":[1]}`
|
||||
transcript := `{"units":[{"sentinel":"combat-transcript"}]}`
|
||||
prepared, err := engine.Prepare(context.Background(), promptkit.RunRequest{
|
||||
PromptID: PromptID, PromptVersion: SchemaVersion, ProfileID: "combat-test-profile",
|
||||
Inputs: map[string]promptkit.ArtifactRef{
|
||||
"transcript": promptkit.InlineWithURI("file:///session.json", transcript),
|
||||
"players": promptkit.Inline(" "),
|
||||
"players": promptkit.Inline("combat-player"),
|
||||
"party": promptkit.Inline(" "),
|
||||
"glossary": promptkit.Inline(" "),
|
||||
"npcs": promptkit.Inline(" "),
|
||||
"npcs": promptkit.Inline(`{"npcs":[{"name":"combat-npc"}]}`),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -62,4 +62,41 @@ func TestPromptAssetsPrepareRequiredInputs(t *testing.T) {
|
||||
if prepared.PromptID != PromptID || prepared.OutputContract.SchemaPath != "dnd_combat_turns_llm.v1.json" {
|
||||
t.Fatalf("prepared prompt = %#v, want combat prompt identity and schema", prepared)
|
||||
}
|
||||
if len(prepared.Messages) < 6 {
|
||||
t.Fatalf("prepared messages = %#v, want shared context, NPC grounding, and instructions", prepared.Messages)
|
||||
}
|
||||
referenceIndex := -1
|
||||
transcriptIndex := -1
|
||||
npcIndex := -1
|
||||
for index, message := range prepared.Messages {
|
||||
if strings.Contains(message.Content, "combat-player") {
|
||||
referenceIndex = index
|
||||
}
|
||||
if strings.Contains(message.Content, "combat-transcript") {
|
||||
transcriptIndex = index
|
||||
}
|
||||
if strings.Contains(message.Content, "combat-npc") {
|
||||
npcIndex = index
|
||||
}
|
||||
}
|
||||
instructionsIndex := len(prepared.Messages) - 1
|
||||
if referenceIndex < 0 || transcriptIndex <= referenceIndex || npcIndex <= transcriptIndex || instructionsIndex <= npcIndex {
|
||||
t.Fatalf("message order = references %d, transcript %d, NPCs %d, instructions %d; want that order", referenceIndex, transcriptIndex, npcIndex, 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, "combat-player") {
|
||||
t.Errorf("message %d unexpectedly rendered campaign-reference input", index)
|
||||
}
|
||||
if index != transcriptIndex && strings.Contains(message.Content, "combat-transcript") {
|
||||
t.Errorf("message %d unexpectedly rendered transcript input", index)
|
||||
}
|
||||
if index != npcIndex && strings.Contains(message.Content, "combat-npc") {
|
||||
t.Errorf("message %d unexpectedly rendered NPC grounding input", index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ var promptAssetManifest = shared.PromptAssetManifest{
|
||||
ModuleFiles: []promptfs.ModulePromptFile{
|
||||
{Name: "prompt.yaml", Path: "prompts/prompt.yaml"},
|
||||
{Name: "spell-catalog.md", Path: "prompts/spell-catalog.md"},
|
||||
{Name: "task.md", Path: "prompts/task.md"},
|
||||
{Name: "instructions.md", Path: "prompts/instructions.md"},
|
||||
},
|
||||
SharedFiles: []string{
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
)
|
||||
|
||||
func TestPromptAssetsPrepareSpellPrompt(t *testing.T) {
|
||||
transcript := []byte(`{"id":"session-1","segments":[{"id":"u1","text":"Mira casts shield."}]}`)
|
||||
prepared := prepareSpellsPrompt(t, transcript, "Dana: Mira", "Mira: wizard", "Shield: abjuration")
|
||||
transcript := []byte(`{"id":"session-1","segments":[{"id":"u1","text":"spell-transcript"}]}`)
|
||||
prepared := prepareSpellsPrompt(t, transcript, "spell-player", "Mira: wizard", "Shield: abjuration")
|
||||
|
||||
if prepared.PromptID != PromptID {
|
||||
t.Fatalf("prompt id = %q, want %q", prepared.PromptID, PromptID)
|
||||
@@ -21,6 +21,38 @@ func TestPromptAssetsPrepareSpellPrompt(t *testing.T) {
|
||||
if prepared.OutputContract.SchemaPath != "dnd_spells_llm.v1.json" {
|
||||
t.Fatalf("schema path = %q, want LLM-only schema", prepared.OutputContract.SchemaPath)
|
||||
}
|
||||
if len(prepared.Messages) < 7 {
|
||||
t.Fatalf("prepared messages = %#v, want shared context, grounded inputs, and instructions", prepared.Messages)
|
||||
}
|
||||
indices := map[string]int{
|
||||
"spell-player": -1,
|
||||
"spell-transcript": -1,
|
||||
"spell-npc-sentinel": -1,
|
||||
"spell-catalog-sentinel": -1,
|
||||
}
|
||||
for index, message := range prepared.Messages {
|
||||
for sentinel := range indices {
|
||||
if strings.Contains(message.Content, sentinel) {
|
||||
indices[sentinel] = index
|
||||
}
|
||||
}
|
||||
}
|
||||
instructionsIndex := len(prepared.Messages) - 1
|
||||
if indices["spell-player"] < 0 || indices["spell-transcript"] <= indices["spell-player"] || indices["spell-npc-sentinel"] <= indices["spell-transcript"] || indices["spell-catalog-sentinel"] <= indices["spell-npc-sentinel"] || instructionsIndex <= indices["spell-catalog-sentinel"] {
|
||||
t.Fatalf("message order = %#v with instructions at %d, want references, transcript, NPCs, catalog, instructions", indices, instructionsIndex)
|
||||
}
|
||||
for _, index := range []int{indices["spell-player"], indices["spell-transcript"], 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 sentinel, index := range indices {
|
||||
for messageIndex, message := range prepared.Messages {
|
||||
if messageIndex != index && strings.Contains(message.Content, sentinel) {
|
||||
t.Errorf("message %d unexpectedly rendered %q", messageIndex, sentinel)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPromptAssetsPrepareWithMissingOptionalReferences(t *testing.T) {
|
||||
@@ -107,8 +139,8 @@ func prepareSpellsPrompt(t *testing.T, transcript []byte, players string, party
|
||||
ProfileID: "spell-test-profile",
|
||||
Inputs: map[string]promptkit.ArtifactRef{
|
||||
"transcript": promptkit.InlineWithURI("file:///session.json", string(transcript)),
|
||||
"spell_catalog": promptkit.Inline(`{"spell_names":["Cure Wounds"]}`),
|
||||
"npcs": promptkit.Inline(`{"npcs":[]}`),
|
||||
"spell_catalog": promptkit.Inline(`{"spell_names":["spell-catalog-sentinel"]}`),
|
||||
"npcs": promptkit.Inline(`{"npcs":[{"name":"spell-npc-sentinel"}]}`),
|
||||
"players": promptkit.Inline(players),
|
||||
"party": promptkit.Inline(party),
|
||||
"glossary": promptkit.Inline(glossary),
|
||||
|
||||
Reference in New Issue
Block a user