Armored the decision parsing.
This commit is contained in:
parent
80d60acf64
commit
36fdd5f00e
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Paper represents a single academic paper
|
// Paper represents a single academic paper
|
||||||
|
@ -185,13 +186,24 @@ Abstract: %s`, criteria, paper.Title, paper.Abstract)
|
||||||
return nil, fmt.Errorf("invalid response format")
|
return nil, fmt.Errorf("invalid response format")
|
||||||
}
|
}
|
||||||
|
|
||||||
decisionParts := bytes.SplitN(lines[0], []byte(":"), 2)
|
// Clean and normalize decision
|
||||||
if len(decisionParts) != 2 {
|
rawDecision := string(bytes.TrimSpace(lines[0]))
|
||||||
return nil, fmt.Errorf("invalid decision format, expected 'DECISION: [VALUE]'")
|
|
||||||
}
|
// Remove any non-alphabetic characters from start/end
|
||||||
decision := strings.ToUpper(string(bytes.TrimSpace(decisionParts[1])))
|
cleanDecision := strings.TrimFunc(rawDecision, func(r rune) bool {
|
||||||
if decision != "ACCEPT" && decision != "REJECT" {
|
return !unicode.IsLetter(r)
|
||||||
return nil, fmt.Errorf("invalid decision value: %s", decision)
|
})
|
||||||
|
|
||||||
|
// Normalize case and check for valid decision
|
||||||
|
upperDecision := strings.ToUpper(cleanDecision)
|
||||||
|
var decision string
|
||||||
|
switch {
|
||||||
|
case strings.HasPrefix(upperDecision, "ACCEPT"):
|
||||||
|
decision = "ACCEPT"
|
||||||
|
case strings.HasPrefix(upperDecision, "REJECT"):
|
||||||
|
decision = "REJECT"
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("invalid decision value: %q (cleaned: %q)", rawDecision, cleanDecision)
|
||||||
}
|
}
|
||||||
|
|
||||||
explanation := string(bytes.TrimSpace(bytes.Join(lines[1:], []byte("\n"))))
|
explanation := string(bytes.TrimSpace(bytes.Join(lines[1:], []byte("\n"))))
|
||||||
|
|
Loading…
Reference in New Issue