Fix D&D extraction issues and retire the completed audit
This commit is contained in:
@@ -8,31 +8,46 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared"
|
||||
)
|
||||
|
||||
type orderedSpellResponse struct {
|
||||
value spellCastResponse
|
||||
earliest int
|
||||
hasEvidence bool
|
||||
}
|
||||
|
||||
func canonicalizeResponse(response *extractionResponse, order shared.SourceRefOrder, sourceID string) {
|
||||
if response == nil {
|
||||
return
|
||||
}
|
||||
ordered := make([]orderedSpellResponse, len(response.SpellCasts))
|
||||
for index := range response.SpellCasts {
|
||||
canonicalizeSpellCast(&response.SpellCasts[index], order, sourceID)
|
||||
}
|
||||
sort.SliceStable(response.SpellCasts, func(i, j int) bool {
|
||||
left, leftOK := order.EarliestValid(spellSourceRefs(response.SpellCasts[i].SourceRefs, sourceID))
|
||||
right, rightOK := order.EarliestValid(spellSourceRefs(response.SpellCasts[j].SourceRefs, sourceID))
|
||||
if leftOK != rightOK {
|
||||
return leftOK
|
||||
earliest, hasEvidence := canonicalizeSpellCast(&response.SpellCasts[index], order, sourceID)
|
||||
ordered[index] = orderedSpellResponse{
|
||||
value: response.SpellCasts[index],
|
||||
earliest: earliest,
|
||||
hasEvidence: hasEvidence,
|
||||
}
|
||||
if !leftOK {
|
||||
}
|
||||
sort.SliceStable(ordered, func(i, j int) bool {
|
||||
if ordered[i].hasEvidence != ordered[j].hasEvidence {
|
||||
return ordered[i].hasEvidence
|
||||
}
|
||||
if !ordered[i].hasEvidence {
|
||||
return false
|
||||
}
|
||||
return left < right
|
||||
return ordered[i].earliest < ordered[j].earliest
|
||||
})
|
||||
for index := range ordered {
|
||||
response.SpellCasts[index] = ordered[index].value
|
||||
}
|
||||
}
|
||||
|
||||
func canonicalizeSpellCast(spell *spellCastResponse, order shared.SourceRefOrder, sourceID string) {
|
||||
func canonicalizeSpellCast(spell *spellCastResponse, order shared.SourceRefOrder, sourceID string) (int, bool) {
|
||||
if spell == nil {
|
||||
return
|
||||
return 0, false
|
||||
}
|
||||
spell.SourceRefs = spellResponseRefs(order.Canonicalize(spellSourceRefs(spell.SourceRefs, sourceID)))
|
||||
refs := order.Canonicalize(spellSourceRefs(spell.SourceRefs, sourceID))
|
||||
spell.SourceRefs = spellResponseRefs(refs)
|
||||
return order.EarliestValid(refs)
|
||||
}
|
||||
|
||||
func spellSourceRefs(refs []spellSourceRefResponse, sourceID string) []source.SourceRef {
|
||||
|
||||
@@ -24,15 +24,16 @@ func TestScriptoriumPromptPreparesTranscriptReferencesAndTaskMessages(t *testing
|
||||
for index, want := range []struct {
|
||||
role string
|
||||
cached bool
|
||||
marker string
|
||||
}{
|
||||
{role: "system"},
|
||||
{role: "user"},
|
||||
{role: "user", cached: true},
|
||||
{role: "system", marker: "Dungeons & Dragons gameplay transcripts"},
|
||||
{role: "user", marker: "Transcript units are the only evidence"},
|
||||
{role: "user", cached: true, marker: "most specific supported in-world"},
|
||||
{role: "user", cached: true},
|
||||
{role: "user", cached: true},
|
||||
{role: "user"},
|
||||
{role: "user"},
|
||||
{role: "user", cached: true},
|
||||
{role: "user", marker: "spell-cast artifacts"},
|
||||
{role: "user", cached: true, marker: "source references must collectively support"},
|
||||
{role: "user"},
|
||||
} {
|
||||
if index >= len(prepared.Messages) {
|
||||
@@ -49,6 +50,9 @@ func TestScriptoriumPromptPreparesTranscriptReferencesAndTaskMessages(t *testing
|
||||
} else if message.CacheControl != nil {
|
||||
t.Errorf("message %d cache control = %#v, want nil", index, message.CacheControl)
|
||||
}
|
||||
if want.marker != "" && !strings.Contains(message.Content, want.marker) {
|
||||
t.Errorf("message %d content does not contain purpose marker %q", index, want.marker)
|
||||
}
|
||||
}
|
||||
if len(prepared.Messages) != 9 {
|
||||
t.Fatalf("prepared prompt has %d messages, want 9", len(prepared.Messages))
|
||||
|
||||
Reference in New Issue
Block a user