Accept equivalent integer references in model responses

This commit is contained in:
2026-11-17 04:22:20 +00:00
parent 2d93e8ae7c
commit 44c767f285
10 changed files with 52 additions and 27 deletions

View File

@@ -40,6 +40,7 @@ type correctionProvider struct {
entered chan struct{}
wait bool
invalidFirstRevision bool
decimalReferences bool
}
func (p *correctionProvider) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@@ -52,6 +53,7 @@ func (p *correctionProvider) ServeHTTP(w http.ResponseWriter, r *http.Request) {
_, validation := req.ResponseFormat.JSONSchema.Schema.Properties["validations"]
p.mu.Lock()
p.requests = append(p.requests, req)
decimalReferences := p.decimalReferences
p.mu.Unlock()
content := `{"corrections":[{"id":1,"original_text":"hello","corrected_text":"Hello"},{"id":2,"original_text":"second","corrected_text":"Second"},{"id":3,"original_text":"third","corrected_text":"Third"}]}`
if validation {
@@ -103,6 +105,14 @@ func (p *correctionProvider) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
content = fmt.Sprintf(`{"proposal_ref":2,"decision":{"action":"revise","correction":{"id":%d,"original_text":"second","corrected_text":"Second"}}}`, id)
}
if decimalReferences {
switch {
case repair:
content = strings.NewReplacer(`"proposal_ref":2`, `"proposal_ref":2e0`, `"id":2`, `"id":2.0`).Replace(content)
case !validation:
content = strings.Replace(content, `"id":2`, `"id":2.0`, 1)
}
}
raw, _ := json.Marshal(content)
w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, `{"model":"fixture","choices":[{"message":{"content":%s}}]}`, raw)
@@ -172,11 +182,14 @@ func setupCorrectionFixture(t *testing.T, attempts int, replacement, wait bool)
func TestSubprocessCorrectionRepairConversation(t *testing.T) {
for _, tc := range []struct {
name string
debug, replacement bool
}{{"default prompt without debug", false, false}, {"replacement with debug", true, true}} {
name string
debug, replacement, decimalReferences bool
}{{"default prompt without debug", false, false, false}, {"replacement with debug and equivalent reference spellings", true, true, true}} {
t.Run(tc.name, func(t *testing.T) {
f, provider := setupCorrectionFixture(t, 2, tc.replacement, false)
provider.mu.Lock()
provider.decimalReferences = tc.decimalReferences
provider.mu.Unlock()
args := []string{"--verbose"}
if tc.debug {
args = append(args, "--debug")