Include glossary guidance in proposal conversations
This commit is contained in:
@@ -31,10 +31,7 @@ type TranscriptModule interface {
|
||||
type StructuredCompletionRequest = structuredoutput.Request
|
||||
type StructuredCompletionResponse = structuredoutput.Response
|
||||
|
||||
type GlossaryInstruction struct {
|
||||
Collection string
|
||||
Text string
|
||||
}
|
||||
type GlossaryInstruction = promptcontext.GlossaryInstruction
|
||||
|
||||
// ModuleRunSpec identifies one resolved module instance in a pipeline.
|
||||
type ModuleRunSpec struct {
|
||||
@@ -62,6 +59,7 @@ func (s *ModuleRunSpec) PrepareGlossary() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
variables.InstructionsBlock = promptcontext.GlossaryInstructionsBlock(s.GlossaryInstructions)
|
||||
s.GlossaryVariables = &variables
|
||||
}
|
||||
if s.GlossaryView == nil {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/core/chunking"
|
||||
@@ -95,24 +96,31 @@ func TestResolveModuleRunSpecs(t *testing.T) {
|
||||
func TestResolveGlossaryInstructions(t *testing.T) {
|
||||
cfg := &config.Config{
|
||||
GlossaryCollections: map[string]config.GlossaryCollection{
|
||||
"one": {Instruction: "First"}, "two": {Instruction: "Second"}, "protected": {Instruction: "Protection only"},
|
||||
"one": {Instruction: "First {{literal}}"}, "two": {Instruction: "Second"}, "protected": {Instruction: "Protection only"}, "empty": {},
|
||||
},
|
||||
Pipeline: config.Pipeline{Stages: []config.Stage{
|
||||
{Module: "grammar", Glossaries: []string{"two", "one"}, ProtectedTerms: []string{"protected"}},
|
||||
{Module: "grammar", Glossaries: []string{"two", "one"}, ProtectedTerms: []string{"protected"}},
|
||||
{Module: "grammar", Glossaries: []string{"two", "empty", "one"}, ProtectedTerms: []string{"protected"}},
|
||||
{Module: "grammar", Glossaries: []string{"two", "empty", "one"}, ProtectedTerms: []string{"protected"}},
|
||||
{Module: "grammar", Glossaries: []string{"one"}, ProtectedTerms: []string{"protected"}},
|
||||
}},
|
||||
}
|
||||
specs := ResolveModuleRunSpecs(cfg)
|
||||
want := []GlossaryInstruction{{Collection: "two", Text: "Second"}, {Collection: "one", Text: "First"}}
|
||||
want := []GlossaryInstruction{{Collection: "two", Text: "Second"}, {Collection: "empty"}, {Collection: "one", Text: "First {{literal}}"}}
|
||||
for _, spec := range specs[:2] {
|
||||
if !reflect.DeepEqual(spec.GlossaryInstructions, want) {
|
||||
t.Fatalf("instructions = %+v, want %+v", spec.GlossaryInstructions, want)
|
||||
}
|
||||
}
|
||||
if !reflect.DeepEqual(specs[2].GlossaryInstructions, want[1:]) {
|
||||
if !reflect.DeepEqual(specs[2].GlossaryInstructions, want[2:]) {
|
||||
t.Fatalf("specific selection = %+v", specs[2].GlossaryInstructions)
|
||||
}
|
||||
if err := specs[0].PrepareGlossary(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
block := specs[0].GlossaryVariables.InstructionsBlock
|
||||
if !strings.Contains(block, "two") || !strings.Contains(block, "one") || !strings.Contains(block, "First {{literal}}") || strings.Index(block, "Second") > strings.Index(block, "First") || strings.Contains(block, "empty") || strings.Contains(block, "Protection only") {
|
||||
t.Fatalf("instruction block = %q", block)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSectionMetadataFromSection(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user