differsOnlyInWhitespace reports whether oldString matches content at exactly one spot once every whitespace run is collapsed: i.e. the sole mismatch is indentation/tabs/newlines. Bounded with spaces so a match can't straddle a token boundary and mislabel an unrelated near-miss.
(content, oldString string)
| 66 | // indentation/tabs/newlines. Bounded with spaces so a match can't straddle a |
| 67 | // token boundary and mislabel an unrelated near-miss. |
| 68 | func differsOnlyInWhitespace(content, oldString string) bool { |
| 69 | norm := func(s string) string { return " " + strings.Join(strings.Fields(s), " ") + " " } |
| 70 | return strings.Count(norm(content), norm(oldString)) == 1 |
| 71 | } |
| 72 | |
| 73 | // EditFileSchema is the OpenAI tool definition for edit_file. The description |
| 74 | // steers the model toward edit_file over write_file for small changes so it |