Use prompt-defined structured output contracts
This commit is contained in:
@@ -56,7 +56,7 @@ func TestRepairedProposalStillFacesDomainChecks(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
settings := loaded.Config.Application.LLM
|
||||
settings.TransientRetries, settings.RepairAttempts = 0, 1
|
||||
settings.TransientRetries = 0
|
||||
client, err := runtime.NewRoleClient("proposal", "base", settings, llm.CallHooks{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/outcomes"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/proposals"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/responseschema"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/stagename"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/structuredoutput"
|
||||
)
|
||||
@@ -86,8 +85,8 @@ func GenerateCandidates(ctx context.Context, req Request) (Result, error) {
|
||||
CaptureExchange: req.CaptureExchange,
|
||||
CaptureDiagnostics: req.Interactions != nil,
|
||||
PromptID: req.PromptID,
|
||||
Variables: req.Variables, Schema: responseschema.CorrectionSetKey,
|
||||
Context: coordinates,
|
||||
Variables: req.Variables,
|
||||
Context: coordinates,
|
||||
}, &response)
|
||||
sectionIndex := 0
|
||||
if req.Section != nil {
|
||||
@@ -113,7 +112,6 @@ func GenerateCandidates(ctx context.Context, req Request) (Result, error) {
|
||||
"segment_ids": segmentIDs(req.WorkingTranscript),
|
||||
"prompt": completion.Prompt,
|
||||
}
|
||||
requestMetadata["response_schema"] = responseschema.MustLookup(responseschema.CorrectionSetKey).DiagnosticsMap()
|
||||
artifacts, _ = req.Interactions.WriteInteraction(structuredoutput.Interaction{
|
||||
Name: stage, Context: coordinates, RequestMetadata: requestMetadata, RequestPayload: completion.Prepared,
|
||||
ResponsePayload: map[string]any{"decoded": response, "final_content": completion.FinalContent, "model": completion.Model},
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/llm"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/outcomes"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/proposals"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/responseschema"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/structuredoutput"
|
||||
)
|
||||
|
||||
@@ -122,12 +121,12 @@ func TestGenerateCandidatesUsesCorrectionSetSchema(t *testing.T) {
|
||||
t.Fatalf("expected 1 LLM call, got %d", len(client.calls))
|
||||
}
|
||||
call := client.calls[0]
|
||||
if call.Schema != responseschema.CorrectionSetKey || call.PromptID != req.PromptID || call.Context.Role != "proposal" {
|
||||
if call.PromptID != req.PromptID || call.Context.Role != "proposal" {
|
||||
t.Fatalf("unexpected call contract: %+v", call)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateCandidatesDiagnosticsIncludeSchemaMetadata(t *testing.T) {
|
||||
func TestGenerateCandidatesDiagnosticsOmitRegistrySchemaMetadata(t *testing.T) {
|
||||
client := &fakeStructuredClient{
|
||||
responses: []StructuredCorrectionSet{
|
||||
{Corrections: []StructuredCorrectionProposal{{SegmentReference: 1, OriginalText: "teh", CorrectedText: "the"}}},
|
||||
@@ -146,13 +145,8 @@ func TestGenerateCandidatesDiagnosticsIncludeSchemaMetadata(t *testing.T) {
|
||||
if !ok {
|
||||
t.Fatalf("expected request metadata map, got %T", diag.lastRequestMetadata)
|
||||
}
|
||||
schemaMap, ok := metadata["response_schema"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("expected response_schema metadata map, got %T", metadata["response_schema"])
|
||||
}
|
||||
want := responseschema.MustLookup(responseschema.CorrectionSetKey)
|
||||
if schemaMap["id"] != want.ID || schemaMap["version"] != want.Version || schemaMap["name"] != want.Name || schemaMap["sha256"] != want.SHA256 {
|
||||
t.Fatalf("unexpected diagnostics schema metadata: got=%v want=%+v", schemaMap, want)
|
||||
if _, exists := metadata["response_schema"]; exists {
|
||||
t.Fatal("unexpected registry schema metadata")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -293,13 +287,8 @@ func TestGenerateCandidatesDiagnosticsWritten(t *testing.T) {
|
||||
if start, ok := metadata["start_index"].(float64); !ok || start != 0 {
|
||||
t.Fatalf("missing response-local origin: %s", raw)
|
||||
}
|
||||
schemaMap, ok := metadata["response_schema"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("expected response_schema metadata in diagnostics, got %T", metadata["response_schema"])
|
||||
}
|
||||
want := responseschema.MustLookup(responseschema.CorrectionSetKey)
|
||||
if schemaMap["id"] != want.ID || schemaMap["version"] != want.Version || schemaMap["name"] != want.Name || schemaMap["sha256"] != want.SHA256 {
|
||||
t.Fatalf("unexpected schema metadata in diagnostics: got=%v want=%+v", schemaMap, want)
|
||||
if _, exists := metadata["response_schema"]; exists {
|
||||
t.Fatal("unexpected registry schema metadata")
|
||||
}
|
||||
var coordinates struct {
|
||||
Context structuredoutput.DiagnosticContext `json:"context"`
|
||||
|
||||
Reference in New Issue
Block a user