Prepare structured D&D reference context
This commit is contained in:
@@ -37,13 +37,21 @@ var _ contracts.Extractor[dnd.ItemRegistry] = (*Extractor)(nil)
|
||||
|
||||
type Options struct{}
|
||||
|
||||
type Extractor struct{}
|
||||
type Extractor struct{ context shared.PreparedContext }
|
||||
|
||||
func New(_ Options, references ...contracts.ReferenceSet) (*Extractor, error) {
|
||||
if len(references) > 1 {
|
||||
return nil, extractorErrorf("at most one reference set may be supplied")
|
||||
}
|
||||
return &Extractor{}, nil
|
||||
var set contracts.ReferenceSet
|
||||
if len(references) == 1 {
|
||||
set = references[0]
|
||||
}
|
||||
context, err := shared.PrepareContext(set)
|
||||
if err != nil {
|
||||
return nil, extractorErrorf("prepare references: %w", err)
|
||||
}
|
||||
return &Extractor{context: context}, nil
|
||||
}
|
||||
|
||||
func (e *Extractor) Key() string { return Key }
|
||||
@@ -61,7 +69,7 @@ func (e *Extractor) PrepareExtraction(ctx context.Context, req contracts.Extract
|
||||
order := shared.NewSourceRefOrderForSource(req.Source, req.SourceIndex)
|
||||
|
||||
sourceID := req.Source.ID
|
||||
materials := shared.PromptInputs(sourceInput, req.References)
|
||||
materials := e.context.Inputs(sourceInput)
|
||||
inputs := make(map[string]promptkit.ArtifactRef, len(materials))
|
||||
for name, material := range materials {
|
||||
inputs[name] = promptkit.InlineWithURI(material.OriginURI, string(material.Content))
|
||||
|
||||
@@ -70,12 +70,12 @@ func TestExtractPassesReferencesWithoutTreatingThemAsEvidence(t *testing.T) {
|
||||
client := &fakeItemsLLMClient{response: extractionResponse{Items: []itemResponse{}}}
|
||||
req := extractionRequest()
|
||||
req.References = contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{
|
||||
"glossary": {Slot: contracts.ReferenceSlot{Name: "glossary"}, Items: []contracts.ReferenceItem{{SlotName: "glossary", Content: []byte("Star Compass: heirloom")}}},
|
||||
"glossary": {Slot: contracts.ReferenceSlot{Name: "glossary"}, Items: []contracts.ReferenceItem{{SlotName: "glossary", MediaType: "application/json", Content: []byte(`{"schema_version":"maximumdirect.glossary.v1","collections":{"campaign":{"entries":[{"id":"s","name":"Star Compass","category":"item","description":"heirloom"}]}}}`)}}},
|
||||
}}
|
||||
if _, err := runExtraction(context.Background(), newExtractor(t, client), req); err != nil {
|
||||
if _, err := runExtraction(context.Background(), newExtractor(t, client, req.References), req); err != nil {
|
||||
t.Fatalf("Extract() error = %v", err)
|
||||
}
|
||||
messageContaining(t, client.requests[0], "Star Compass: heirloom")
|
||||
messageContaining(t, client.requests[0], "Star Compass")
|
||||
if strings.Contains(messageContaining(t, client.requests[0], string(req.Chunk.Content)).Content, "heirloom") {
|
||||
t.Fatal("references became source evidence")
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func assessRegistry(ctx context.Context, request extractionTestInput, value dnd.
|
||||
func TestNativeExtractionCorrectsGroundingWithFixedInputs(t *testing.T) {
|
||||
client := &fakeItemsLLMClient{responses: []string{ungroundedRegistry, groundedRegistry}}
|
||||
request := extractionRequest()
|
||||
request.References = contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{"glossary": {Items: []contracts.ReferenceItem{{Content: []byte("fixed-reference")}}}}}
|
||||
request.References = contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{"players": {Items: []contracts.ReferenceItem{{Content: []byte("fixed-reference")}}}}}
|
||||
request.Execution.Controls.MaxAdditionalTurns = 1
|
||||
request.Execution.Execution.Execution = &promptkit.ExecutionTargetOverride{Model: "registry-override"}
|
||||
var prepared []promptkit.PreparedRun
|
||||
@@ -56,11 +56,11 @@ func TestNativeExtractionCorrectsGroundingWithFixedInputs(t *testing.T) {
|
||||
}
|
||||
// Changes after capture must not cause source/reference preparation again.
|
||||
request.SourceInput.Content[0] = '!'
|
||||
request.References.Slots["glossary"].Items[0].Content[0] = '!'
|
||||
request.References.Slots["players"].Items[0].Content[0] = '!'
|
||||
}
|
||||
return assessment, err
|
||||
}
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, client), request)
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, client, request.References), request)
|
||||
if err != nil || result.Outcome.Disposition != contracts.ProducerAccepted || !result.Outcome.ReuseEligible ||
|
||||
assessments != 2 || len(client.requests) != 2 || len(prepared) != 2 || len(result.Value.Items) != 1 {
|
||||
t.Fatalf("corrected registry=%#v %v, assessments/provider/prepared=%d/%d/%d", result, err, assessments, len(client.requests), len(prepared))
|
||||
|
||||
@@ -10,6 +10,15 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
)
|
||||
|
||||
func TestConstructionRejectsInvalidPartyReference(t *testing.T) {
|
||||
refs := contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{
|
||||
"party": {Items: []contracts.ReferenceItem{{MediaType: "application/json", Content: []byte("{}")}}},
|
||||
}}
|
||||
if _, err := New(Options{}, refs); err == nil {
|
||||
t.Fatal("invalid party accepted during construction")
|
||||
}
|
||||
}
|
||||
|
||||
func TestModuleRegistrationAndNativeDependencies(t *testing.T) {
|
||||
if _, err := New(Options{}, contracts.ReferenceSet{}, contracts.ReferenceSet{}); err == nil || !strings.Contains(err.Error(), "at most one") {
|
||||
t.Fatalf("New() error = %v, want reference-set rejection", err)
|
||||
|
||||
@@ -37,13 +37,21 @@ var _ contracts.Extractor[dnd.LocationRegistry] = (*Extractor)(nil)
|
||||
|
||||
type Options struct{}
|
||||
|
||||
type Extractor struct{}
|
||||
type Extractor struct{ context shared.PreparedContext }
|
||||
|
||||
func New(_ Options, references ...contracts.ReferenceSet) (*Extractor, error) {
|
||||
if len(references) > 1 {
|
||||
return nil, extractorErrorf("at most one reference set may be supplied")
|
||||
}
|
||||
return &Extractor{}, nil
|
||||
var set contracts.ReferenceSet
|
||||
if len(references) == 1 {
|
||||
set = references[0]
|
||||
}
|
||||
context, err := shared.PrepareContext(set)
|
||||
if err != nil {
|
||||
return nil, extractorErrorf("prepare references: %w", err)
|
||||
}
|
||||
return &Extractor{context: context}, nil
|
||||
}
|
||||
|
||||
func (e *Extractor) Key() string { return Key }
|
||||
@@ -61,7 +69,7 @@ func (e *Extractor) PrepareExtraction(ctx context.Context, req contracts.Extract
|
||||
order := shared.NewSourceRefOrderForSource(req.Source, req.SourceIndex)
|
||||
|
||||
sourceID := req.Source.ID
|
||||
materials := shared.PromptInputs(sourceInput, req.References)
|
||||
materials := e.context.Inputs(sourceInput)
|
||||
inputs := make(map[string]promptkit.ArtifactRef, len(materials))
|
||||
for name, material := range materials {
|
||||
inputs[name] = promptkit.InlineWithURI(material.OriginURI, string(material.Content))
|
||||
|
||||
@@ -73,12 +73,12 @@ func TestExtractPassesReferencesWithoutTreatingThemAsEvidence(t *testing.T) {
|
||||
client := &fakeLocationsLLMClient{response: extractionResponse{Locations: []locationResponse{}}}
|
||||
req := extractionRequest()
|
||||
req.References = contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{
|
||||
"glossary": {Slot: contracts.ReferenceSlot{Name: "glossary"}, Items: []contracts.ReferenceItem{{SlotName: "glossary", Content: []byte("Old Mill: abandoned granary")}}},
|
||||
"glossary": {Slot: contracts.ReferenceSlot{Name: "glossary"}, Items: []contracts.ReferenceItem{{SlotName: "glossary", MediaType: "application/json", Content: []byte(`{"schema_version":"maximumdirect.glossary.v1","collections":{"campaign":{"entries":[{"id":"m","name":"Old Mill","category":"place","description":"abandoned granary"}]}}}`)}}},
|
||||
}}
|
||||
if _, err := runExtraction(context.Background(), newExtractor(t, client), req); err != nil {
|
||||
if _, err := runExtraction(context.Background(), newExtractor(t, client, req.References), req); err != nil {
|
||||
t.Fatalf("Extract() error = %v", err)
|
||||
}
|
||||
messageContaining(t, client.requests[0], "Old Mill: abandoned granary")
|
||||
messageContaining(t, client.requests[0], "abandoned granary")
|
||||
if strings.Contains(messageContaining(t, client.requests[0], string(req.Chunk.Content)).Content, "abandoned granary") {
|
||||
t.Fatal("references became source evidence")
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func assessRegistry(ctx context.Context, request extractionTestInput, value dnd.
|
||||
func TestNativeExtractionCorrectsGroundingWithFixedInputs(t *testing.T) {
|
||||
client := &fakeLocationsLLMClient{responses: []string{ungroundedRegistry, groundedRegistry}}
|
||||
request := extractionRequest()
|
||||
request.References = contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{"glossary": {Items: []contracts.ReferenceItem{{Content: []byte("fixed-reference")}}}}}
|
||||
request.References = contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{"players": {Items: []contracts.ReferenceItem{{Content: []byte("fixed-reference")}}}}}
|
||||
request.Execution.Controls.MaxAdditionalTurns = 1
|
||||
request.Execution.Execution.Execution = &promptkit.ExecutionTargetOverride{Model: "registry-override"}
|
||||
var prepared []promptkit.PreparedRun
|
||||
@@ -56,11 +56,11 @@ func TestNativeExtractionCorrectsGroundingWithFixedInputs(t *testing.T) {
|
||||
}
|
||||
// Changes after capture must not cause source/reference preparation again.
|
||||
request.SourceInput.Content[0] = '!'
|
||||
request.References.Slots["glossary"].Items[0].Content[0] = '!'
|
||||
request.References.Slots["players"].Items[0].Content[0] = '!'
|
||||
}
|
||||
return assessment, err
|
||||
}
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, client), request)
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, client, request.References), request)
|
||||
if err != nil || result.Outcome.Disposition != contracts.ProducerAccepted || !result.Outcome.ReuseEligible ||
|
||||
assessments != 2 || len(client.requests) != 2 || len(prepared) != 2 || len(result.Value.Locations) != 1 {
|
||||
t.Fatalf("corrected registry=%#v %v, assessments/provider/prepared=%d/%d/%d", result, err, assessments, len(client.requests), len(prepared))
|
||||
|
||||
@@ -10,6 +10,15 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
)
|
||||
|
||||
func TestConstructionRejectsInvalidPartyReference(t *testing.T) {
|
||||
refs := contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{
|
||||
"party": {Items: []contracts.ReferenceItem{{MediaType: "application/json", Content: []byte("{}")}}},
|
||||
}}
|
||||
if _, err := New(Options{}, refs); err == nil {
|
||||
t.Fatal("invalid party accepted during construction")
|
||||
}
|
||||
}
|
||||
|
||||
func TestModuleRegistrationAndNativeDependencies(t *testing.T) {
|
||||
if _, err := New(Options{}, contracts.ReferenceSet{}, contracts.ReferenceSet{}); err == nil || !strings.Contains(err.Error(), "at most one") {
|
||||
t.Fatalf("New() error = %v, want reference-set rejection", err)
|
||||
|
||||
@@ -43,13 +43,21 @@ var _ contracts.Extractor[dnd.NPCRegistry] = (*Extractor)(nil)
|
||||
|
||||
type Options struct{}
|
||||
|
||||
type Extractor struct{}
|
||||
type Extractor struct{ context shared.PreparedContext }
|
||||
|
||||
func New(_ Options, references ...contracts.ReferenceSet) (*Extractor, error) {
|
||||
if len(references) > 1 {
|
||||
return nil, extractorErrorf("at most one reference set may be supplied")
|
||||
}
|
||||
return &Extractor{}, nil
|
||||
var set contracts.ReferenceSet
|
||||
if len(references) == 1 {
|
||||
set = references[0]
|
||||
}
|
||||
context, err := shared.PrepareContext(set)
|
||||
if err != nil {
|
||||
return nil, extractorErrorf("prepare references: %w", err)
|
||||
}
|
||||
return &Extractor{context: context}, nil
|
||||
}
|
||||
|
||||
func (e *Extractor) Key() string { return Key }
|
||||
@@ -67,7 +75,7 @@ func (e *Extractor) PrepareExtraction(ctx context.Context, req contracts.Extract
|
||||
order := shared.NewSourceRefOrderForSource(req.Source, req.SourceIndex)
|
||||
|
||||
sourceID := req.Source.ID
|
||||
materials := shared.PromptInputs(sourceInput, req.References)
|
||||
materials := e.context.Inputs(sourceInput)
|
||||
inputs := make(map[string]promptkit.ArtifactRef, len(materials))
|
||||
for name, material := range materials {
|
||||
inputs[name] = promptkit.InlineWithURI(material.OriginURI, string(material.Content))
|
||||
|
||||
@@ -131,15 +131,15 @@ func TestExtractPassesCampaignReferencesAsPromptInputs(t *testing.T) {
|
||||
req := extractionRequest()
|
||||
req.References = contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{
|
||||
"players": {Slot: contracts.ReferenceSlot{Name: "players"}, Items: []contracts.ReferenceItem{{SlotName: "players", Content: []byte("Dana: Mira")}}},
|
||||
"party": {Slot: contracts.ReferenceSlot{Name: "party"}, Items: []contracts.ReferenceItem{{SlotName: "party", Content: []byte("Mira: ranger")}}},
|
||||
"glossary": {Slot: contracts.ReferenceSlot{Name: "glossary"}, Items: []contracts.ReferenceItem{{SlotName: "glossary", Content: []byte("Greencloak: local title")}}},
|
||||
"party": {Slot: contracts.ReferenceSlot{Name: "party"}, Items: []contracts.ReferenceItem{{SlotName: "party", MediaType: "application/json", Content: []byte(`{"schema_version":"maximumdirect.rpg.party.v1","characters":{"m":{"character":{"name":"Mira","classes":[{"name":"ranger"}]}}}}`)}}},
|
||||
"glossary": {Slot: contracts.ReferenceSlot{Name: "glossary"}, Items: []contracts.ReferenceItem{{SlotName: "glossary", MediaType: "application/json", Content: []byte(`{"schema_version":"maximumdirect.glossary.v1","collections":{"campaign":{"entries":[{"id":"g","name":"Greencloak","category":"title","description":"local title"}]}}}`)}}},
|
||||
}}
|
||||
if _, err := runExtraction(context.Background(), newExtractor(t, client), req); err != nil {
|
||||
if _, err := runExtraction(context.Background(), newExtractor(t, client, req.References), req); err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil", err)
|
||||
}
|
||||
request := client.requests[0]
|
||||
references := messageContaining(t, request, "Dana: Mira").Content
|
||||
if !strings.Contains(references, "Mira: ranger") || !strings.Contains(references, "Greencloak: local title") {
|
||||
if !strings.Contains(references, "Mira") || !strings.Contains(references, "ranger") || !strings.Contains(references, "Greencloak") || !strings.Contains(references, "local title") {
|
||||
t.Fatal("campaign references missing")
|
||||
}
|
||||
if strings.Contains(messageContaining(t, request, string(req.Chunk.Content)).Content, "local title") {
|
||||
|
||||
@@ -41,7 +41,7 @@ func assessRegistry(ctx context.Context, request extractionTestInput, value dnd.
|
||||
func TestNativeExtractionCorrectsGroundingWithFixedInputs(t *testing.T) {
|
||||
client := &fakeNPCsLLMClient{responses: []string{ungroundedRegistry, groundedRegistry}}
|
||||
request := extractionRequest()
|
||||
request.References = contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{"glossary": {Items: []contracts.ReferenceItem{{Content: []byte("fixed-reference")}}}}}
|
||||
request.References = contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{"players": {Items: []contracts.ReferenceItem{{Content: []byte("fixed-reference")}}}}}
|
||||
request.Execution.Controls.MaxAdditionalTurns = 1
|
||||
request.Execution.Execution.Execution = &promptkit.ExecutionTargetOverride{Model: "registry-override"}
|
||||
var prepared []promptkit.PreparedRun
|
||||
@@ -56,11 +56,11 @@ func TestNativeExtractionCorrectsGroundingWithFixedInputs(t *testing.T) {
|
||||
}
|
||||
// Changes after capture must not cause source/reference preparation again.
|
||||
request.SourceInput.Content[0] = '!'
|
||||
request.References.Slots["glossary"].Items[0].Content[0] = '!'
|
||||
request.References.Slots["players"].Items[0].Content[0] = '!'
|
||||
}
|
||||
return assessment, err
|
||||
}
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, client), request)
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, client, request.References), request)
|
||||
if err != nil || result.Outcome.Disposition != contracts.ProducerAccepted || !result.Outcome.ReuseEligible ||
|
||||
assessments != 2 || len(client.requests) != 2 || len(prepared) != 2 || len(result.Value.NPCs) != 1 {
|
||||
t.Fatalf("corrected registry=%#v %v, assessments/provider/prepared=%d/%d/%d", result, err, assessments, len(client.requests), len(prepared))
|
||||
|
||||
@@ -10,6 +10,15 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
)
|
||||
|
||||
func TestConstructionRejectsInvalidPartyReference(t *testing.T) {
|
||||
refs := contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{
|
||||
"party": {Items: []contracts.ReferenceItem{{MediaType: "application/json", Content: []byte("{}")}}},
|
||||
}}
|
||||
if _, err := New(Options{}, refs); err == nil {
|
||||
t.Fatal("invalid party accepted during construction")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRejectsAmbiguousReferences(t *testing.T) {
|
||||
if _, err := New(Options{}, contracts.ReferenceSet{}, contracts.ReferenceSet{}); err == nil || !strings.Contains(err.Error(), "at most one reference set") {
|
||||
t.Fatalf("New() error = %v, want reference-set error", err)
|
||||
@@ -30,10 +39,10 @@ func TestModuleSpecAndReferenceSlots(t *testing.T) {
|
||||
Provides: []string{"dnd.npc_registry"},
|
||||
ArtifactKind: dnd.NPCRegistryKind,
|
||||
ReferenceSlots: []contracts.ReferenceSlot{
|
||||
{Name: "glossary", Description: "Optional campaign glossary reference material used only for NPC disambiguation.", AcceptedMediaTypes: []string{"application/json", "application/x-yaml", "application/yaml", "text/markdown", "text/plain"}},
|
||||
{Name: "party", Description: "Optional party roster reference material used only for NPC disambiguation.", AcceptedMediaTypes: []string{"application/json", "application/x-yaml", "application/yaml", "text/markdown", "text/plain"}},
|
||||
{Name: "glossary", Description: "Optional campaign glossary reference material used only for NPC disambiguation.", AcceptedMediaTypes: []string{"application/json", "application/x-yaml", "application/yaml"}},
|
||||
{Name: "party", Description: "Optional party roster reference material used only for NPC disambiguation.", AcceptedMediaTypes: []string{"application/json", "application/x-yaml", "application/yaml"}},
|
||||
{Name: "players", Description: "Optional player list reference material used only for NPC disambiguation.", AcceptedMediaTypes: []string{"application/json", "application/x-yaml", "application/yaml", "text/markdown", "text/plain"}},
|
||||
{Name: "roster", Description: "Deprecated alias for party roster reference material used only for NPC disambiguation.", AcceptedMediaTypes: []string{"application/json", "application/x-yaml", "application/yaml", "text/markdown", "text/plain"}},
|
||||
{Name: "roster", Description: "Deprecated alias for party roster reference material used only for NPC disambiguation.", AcceptedMediaTypes: []string{"application/json", "application/x-yaml", "application/yaml"}},
|
||||
},
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
|
||||
@@ -49,13 +49,21 @@ var _ contracts.Extractor[dnd.SceneDescriptionList] = (*Extractor)(nil)
|
||||
|
||||
type Options struct{}
|
||||
|
||||
type Extractor struct{}
|
||||
type Extractor struct{ context shared.PreparedContext }
|
||||
|
||||
func New(_ Options, references ...contracts.ReferenceSet) (*Extractor, error) {
|
||||
if len(references) > 1 {
|
||||
return nil, extractorErrorf("at most one reference set may be supplied")
|
||||
}
|
||||
return &Extractor{}, nil
|
||||
var set contracts.ReferenceSet
|
||||
if len(references) == 1 {
|
||||
set = references[0]
|
||||
}
|
||||
context, err := shared.PrepareContext(set)
|
||||
if err != nil {
|
||||
return nil, extractorErrorf("prepare references: %w", err)
|
||||
}
|
||||
return &Extractor{context: context}, nil
|
||||
}
|
||||
|
||||
func (e *Extractor) Key() string { return Key }
|
||||
@@ -86,7 +94,7 @@ func (e *Extractor) PrepareExtraction(ctx context.Context, req contracts.Extract
|
||||
value.Scenes[0].ID = chunk.ID
|
||||
return sceneFallback(&value, chunk, *index)
|
||||
}
|
||||
materials := shared.PromptInputs(sourceInput, req.References)
|
||||
materials := e.context.Inputs(sourceInput)
|
||||
inputs := make(map[string]promptkit.ArtifactRef, len(materials))
|
||||
for name, material := range materials {
|
||||
inputs[name] = promptkit.InlineWithURI(material.OriginURI, string(material.Content))
|
||||
|
||||
@@ -50,17 +50,17 @@ func TestExtractPassesOptionalReferencesAndUsesEmptyPlaceholders(t *testing.T) {
|
||||
}
|
||||
req.References = contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{
|
||||
"players": {Slot: contracts.ReferenceSlot{Name: "players"}, Items: []contracts.ReferenceItem{{SlotName: "players", Content: []byte("Dana: Mira")}}},
|
||||
"party": {Slot: contracts.ReferenceSlot{Name: "party"}, Items: []contracts.ReferenceItem{{SlotName: "party", Content: []byte("Mira: ranger")}}},
|
||||
"glossary": {Slot: contracts.ReferenceSlot{Name: "glossary"}, Items: []contracts.ReferenceItem{{SlotName: "glossary", Content: []byte("Greencloak: local title")}}},
|
||||
"party": {Slot: contracts.ReferenceSlot{Name: "party"}, Items: []contracts.ReferenceItem{{SlotName: "party", MediaType: "application/json", Content: []byte(`{"schema_version":"maximumdirect.rpg.party.v1","characters":{"m":{"character":{"name":"Mira","classes":[{"name":"ranger"}]}}}}`)}}},
|
||||
"glossary": {Slot: contracts.ReferenceSlot{Name: "glossary"}, Items: []contracts.ReferenceItem{{SlotName: "glossary", MediaType: "application/json", Content: []byte(`{"schema_version":"maximumdirect.glossary.v1","collections":{"campaign":{"entries":[{"id":"g","name":"Greencloak","category":"title","description":"local title"}]}}}`)}}},
|
||||
}}
|
||||
if _, err := runExtraction(newExtractor(t, client), context.Background(), req); err != nil {
|
||||
if _, err := runExtraction(newExtractor(t, client, req.References), context.Background(), req); err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil", err)
|
||||
}
|
||||
var text string
|
||||
for _, message := range client.requests[1].Prompt.Messages {
|
||||
text += message.Content
|
||||
}
|
||||
for _, reference := range []string{"Dana: Mira", "Mira: ranger", "Greencloak: local title"} {
|
||||
for _, reference := range []string{"Dana: Mira", "ranger", "Greencloak", "local title"} {
|
||||
if strings.Count(text, reference) != 1 {
|
||||
t.Fatalf("optional input not rendered once: %q", reference)
|
||||
}
|
||||
|
||||
@@ -10,6 +10,15 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
)
|
||||
|
||||
func TestConstructionRejectsInvalidPartyReference(t *testing.T) {
|
||||
refs := contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{
|
||||
"party": {Items: []contracts.ReferenceItem{{MediaType: "application/json", Content: []byte("{}")}}},
|
||||
}}
|
||||
if _, err := New(Options{}, refs); err == nil {
|
||||
t.Fatal("invalid party accepted during construction")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRejectsAmbiguousReferences(t *testing.T) {
|
||||
if _, err := New(Options{}, contracts.ReferenceSet{}, contracts.ReferenceSet{}); err == nil || !strings.Contains(err.Error(), "at most one reference set") {
|
||||
t.Fatalf("New() error = %v, want reference-set error", err)
|
||||
@@ -23,8 +32,8 @@ func TestModuleSpecAndReferenceSlots(t *testing.T) {
|
||||
want := pipeline.ModuleSpec{
|
||||
Key: Key, Stage: pipeline.StageExtract, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID}, Requires: []string{"chunks", "source.transcript"}, Provides: []string{"dnd.scene_descriptions"}, ArtifactKind: dnd.SceneDescriptionListKind,
|
||||
ReferenceSlots: []contracts.ReferenceSlot{
|
||||
{Name: "glossary", Description: "Optional campaign glossary reference material used only to disambiguate scene descriptions.", AcceptedMediaTypes: []string{"application/json", "application/x-yaml", "application/yaml", "text/markdown", "text/plain"}},
|
||||
{Name: "party", Description: "Optional party roster reference material used only to disambiguate scene descriptions.", AcceptedMediaTypes: []string{"application/json", "application/x-yaml", "application/yaml", "text/markdown", "text/plain"}},
|
||||
{Name: "glossary", Description: "Optional campaign glossary reference material used only to disambiguate scene descriptions.", AcceptedMediaTypes: []string{"application/json", "application/x-yaml", "application/yaml"}},
|
||||
{Name: "party", Description: "Optional party roster reference material used only to disambiguate scene descriptions.", AcceptedMediaTypes: []string{"application/json", "application/x-yaml", "application/yaml"}},
|
||||
{Name: "players", Description: "Optional player list reference material used only to disambiguate scene descriptions.", AcceptedMediaTypes: []string{"application/json", "application/x-yaml", "application/yaml", "text/markdown", "text/plain"}},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user