Verify structured output for selected profiles
This commit is contained in:
93
internal/framework/llm/smoke.go
Normal file
93
internal/framework/llm/smoke.go
Normal file
@@ -0,0 +1,93 @@
|
||||
package llm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
pk "go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
type VerificationStatus string
|
||||
|
||||
const (
|
||||
VerificationSuccess VerificationStatus = "success"
|
||||
VerificationNegative VerificationStatus = "negative"
|
||||
VerificationUnsupported VerificationStatus = "unsupported"
|
||||
VerificationInconclusive VerificationStatus = "inconclusive"
|
||||
)
|
||||
|
||||
type ProfileVerification struct {
|
||||
ProfileID string
|
||||
Status VerificationStatus
|
||||
Report *pk.SmokeTestReport
|
||||
Err error
|
||||
}
|
||||
|
||||
type smokeTester interface {
|
||||
SmokeTest(context.Context, pk.SmokeTestRequest) (*pk.SmokeTestReport, error)
|
||||
}
|
||||
|
||||
func classifyStructuredOutput(report *pk.SmokeTestReport, err error) VerificationStatus {
|
||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||
return VerificationInconclusive
|
||||
}
|
||||
if err != nil {
|
||||
return VerificationNegative
|
||||
}
|
||||
if report == nil || report.Kind != pk.SmokeTestStructuredOutput {
|
||||
return VerificationInconclusive
|
||||
}
|
||||
if !report.Supported || (report.Applicable != nil && !*report.Applicable) {
|
||||
return VerificationUnsupported
|
||||
}
|
||||
if report.Failure != pk.ExecutionFailureNone {
|
||||
return VerificationNegative
|
||||
}
|
||||
if !report.Completed || report.Applicable == nil {
|
||||
return VerificationInconclusive
|
||||
}
|
||||
for _, fact := range []*bool{report.Facts.GenerationCompleted, report.Facts.ValidJSON, report.Facts.SchemaMatched} {
|
||||
if fact != nil && !*fact {
|
||||
return VerificationNegative
|
||||
}
|
||||
}
|
||||
for _, fact := range []*bool{report.Facts.GenerationCompleted, report.Facts.ValidJSON, report.Facts.SchemaMatched} {
|
||||
if fact == nil {
|
||||
return VerificationInconclusive
|
||||
}
|
||||
}
|
||||
return VerificationSuccess
|
||||
}
|
||||
|
||||
// VerifyStructuredOutput checks selected profiles sequentially and retains native evidence.
|
||||
func VerifyStructuredOutput(ctx context.Context, engine smokeTester, profiles []string) ([]ProfileVerification, error) {
|
||||
var results []ProfileVerification
|
||||
var failures []error
|
||||
for _, id := range profiles {
|
||||
if err := ctx.Err(); err != nil {
|
||||
failures = append(failures, err)
|
||||
break
|
||||
}
|
||||
report, err := engine.SmokeTest(ctx, pk.SmokeTestRequest{Kind: pk.SmokeTestStructuredOutput, ProfileID: id})
|
||||
status := classifyStructuredOutput(report, err)
|
||||
results = append(results, ProfileVerification{ProfileID: id, Status: status, Report: report, Err: err})
|
||||
if status != VerificationSuccess {
|
||||
if err != nil {
|
||||
failures = append(failures, fmt.Errorf("profile %q: %w", id, err))
|
||||
} else {
|
||||
failures = append(failures, fmt.Errorf("profile %q: structured-output verification %s", id, status))
|
||||
}
|
||||
}
|
||||
if canceled := ctx.Err(); canceled != nil {
|
||||
if !errors.Is(err, canceled) {
|
||||
failures = append(failures, canceled)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
if err := ctx.Err(); err != nil && !errors.Is(errors.Join(failures...), err) {
|
||||
failures = append(failures, err)
|
||||
}
|
||||
return results, errors.Join(failures...)
|
||||
}
|
||||
Reference in New Issue
Block a user