diff --git a/paperprocessor.go b/paperprocessor.go index 31527b8..f942354 100644 --- a/paperprocessor.go +++ b/paperprocessor.go @@ -8,6 +8,7 @@ import ( "net/http" "strings" "time" + "unicode" ) // Paper represents a single academic paper @@ -185,13 +186,24 @@ Abstract: %s`, criteria, paper.Title, paper.Abstract) return nil, fmt.Errorf("invalid response format") } - decisionParts := bytes.SplitN(lines[0], []byte(":"), 2) - if len(decisionParts) != 2 { - return nil, fmt.Errorf("invalid decision format, expected 'DECISION: [VALUE]'") - } - decision := strings.ToUpper(string(bytes.TrimSpace(decisionParts[1]))) - if decision != "ACCEPT" && decision != "REJECT" { - return nil, fmt.Errorf("invalid decision value: %s", decision) + // Clean and normalize decision + rawDecision := string(bytes.TrimSpace(lines[0])) + + // Remove any non-alphabetic characters from start/end + cleanDecision := strings.TrimFunc(rawDecision, func(r rune) bool { + return !unicode.IsLetter(r) + }) + + // 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"))))