Define correction repair response and conversation replay
This commit is contained in:
31
internal/framework/proposal_generation/repair.go
Normal file
31
internal/framework/proposal_generation/repair.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package proposal_generation
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/outcomes"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/structuredoutput"
|
||||
)
|
||||
|
||||
// RepairResponse is one model response for an original proposal reference.
|
||||
type RepairResponse struct {
|
||||
ProposalRef int `json:"proposal_ref"`
|
||||
Action string `json:"action"`
|
||||
Correction *StructuredCorrectionProposal `json:"correction"`
|
||||
}
|
||||
|
||||
// DecodeRepairResponse checks correspondence after structural schema validation.
|
||||
func DecodeRepairResponse(content []byte, expectedRef int) (RepairResponse, error) {
|
||||
var response RepairResponse
|
||||
if err := json.Unmarshal(content, &response); err != nil {
|
||||
return RepairResponse{}, invalidRepairResponse(err)
|
||||
}
|
||||
if response.ProposalRef != expectedRef || (response.Action != "revise" || response.Correction == nil) && (response.Action != "withdraw" || response.Correction != nil) {
|
||||
return RepairResponse{}, invalidRepairResponse(nil)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func invalidRepairResponse(cause error) error {
|
||||
return &structuredoutput.Failure{Class: structuredoutput.FailureRecoverable, Reason: outcomes.ReasonInvalidOutput, Message: "correction repair response is unusable", Cause: cause}
|
||||
}
|
||||
Reference in New Issue
Block a user