-
Notifications
You must be signed in to change notification settings - Fork 18
generate command #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generate command #79
Changes from 1 commit
871788d
9e82844
d8fcb9d
35870b9
3ea7a6e
ef7d089
96f9183
37b761c
74d048b
61a43ca
ee90766
e7d4a17
1c936c0
292917a
e9c6668
5c5a167
b4b662f
393020f
6458590
cdc38f1
bbdd748
7dc3d7d
e812aec
341442f
da294e2
50b853f
5018380
9391f0d
f3f320b
7ab63bc
f726d7c
e5dd291
239eed7
1a9c9ab
e0f0311
26f6ee3
c6da6de
0a15cec
130bc53
06a9caa
e6f4173
59fad69
fca40f4
a46680e
3cdc67e
d19f533
7903afa
6dda3c5
26df5e4
f797a5a
9e8a469
cbf9d78
1ac704e
34d55a2
2d7ef3f
582c004
ba24a7a
3b99ef5
527b564
440914f
9e1c074
d3b430a
fce67b8
e2c28d3
f183206
f5bc450
97a945f
6f22c37
4e17f45
1d06bed
2192d9e
12e866e
7ca45de
d3d51c6
fa86243
4632732
b083161
28f5a44
0fe3ff6
4a55194
ded2220
3aadaa3
cbbccc2
9469f8c
df5d94b
3bb8a18
52eed37
39249c3
d79901a
b1b4f24
fc6800d
507ec74
e668ba8
8e5d8f8
23ab2d7
39f24ea
af399ab
98146ad
d719935
5127d94
f57bf34
eba1adc
2d031ec
8b12281
9eb7803
025e32e
7571825
0615664
178d921
59ca252
2831dd9
a0cda99
d4a8976
2018522
e9adb0f
7defd59
29074f6
c058406
5bc1b87
36fd696
4a3285e
9c13267
4b18ed0
45d8915
8f7da6c
376135e
1a6090e
d21cd6c
cb8a394
df2c83f
0e97868
7894290
95b6719
1c93996
dceeba4
350a15b
7cf92c1
e6281db
09b9b87
7bd2e6c
e2970ef
c127bf4
b2d1244
58bb353
72e7a15
e5f6483
648ee9b
2882f71
20149e4
c238387
2925428
4a6eee9
b662738
caa8aa5
e04761b
283a3c7
e8bb082
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…sUnassistedResponse, Unfence, and SplitLines functions
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package generate | ||
|
|
||
| import ( | ||
| "regexp" | ||
| "strings" | ||
| ) | ||
|
|
||
| // IsUnassistedResponse returns true if the text is an unassisted response, like "i'm sorry" or "i can't assist with that". | ||
| func IsUnassistedResponse(text string) bool { | ||
| re := regexp.MustCompile(`i can't assist with that|i'm sorry`) | ||
| return re.MatchString(strings.ToLower(text)) | ||
| } | ||
|
|
||
| // unfence removes code fences and splits text into lines. | ||
| func Unfence(text string) string { | ||
| text = strings.TrimSpace(text) | ||
| // Remove triple backtick code fences if present | ||
| if strings.HasPrefix(text, "```") { | ||
| parts := strings.SplitN(text, "\n", 2) | ||
| if len(parts) == 2 { | ||
| text = parts[1] | ||
| } | ||
| text = strings.TrimSuffix(text, "```") | ||
| } | ||
| return text | ||
| } | ||
|
|
||
| // splits text into lines. | ||
pelikhan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| func SplitLines(text string) []string { | ||
| lines := strings.Split(text, "\n") | ||
| return lines | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,225 @@ | ||
| package generate | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestIsUnassistedResponse(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| input string | ||
| expected bool | ||
| }{ | ||
| { | ||
| name: "detects 'i can't assist with that' lowercase", | ||
| input: "i can't assist with that request", | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "detects 'i can't assist with that' mixed case", | ||
| input: "I Can't Assist With That Request", | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "detects 'i'm sorry' lowercase", | ||
| input: "i'm sorry, but i cannot help", | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "detects 'i'm sorry' mixed case", | ||
| input: "I'm Sorry, But I Cannot Help", | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "detects phrase within larger text", | ||
| input: "Unfortunately, I can't assist with that particular request. Please try something else.", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if it ever responds with "I cannot assist", if we should catch that.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LLMs are flimsy and somethings the promptpex prompts referencing inlined prompts confuses the inference engine. |
||
| expected: true, | ||
| }, | ||
| { | ||
| name: "detects 'i'm sorry' within larger text", | ||
| input: "Well, I'm sorry to say this but I cannot proceed.", | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "returns false for regular response", | ||
| input: "Here is the code you requested", | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "returns false for empty string", | ||
| input: "", | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "returns false for similar but different phrases", | ||
| input: "i can assist with that", | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "returns false for partial matches", | ||
| input: "sorry for the delay", | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "handles apostrophe variations", | ||
| input: "i can't assist with that", | ||
| expected: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| result := IsUnassistedResponse(tt.input) | ||
| require.Equal(t, tt.expected, result) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestUnfence(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| input string | ||
| expected string | ||
| }{ | ||
| { | ||
| name: "removes code fences with language", | ||
| input: "```go\npackage main\nfunc main() {}\n```", | ||
| expected: "package main\nfunc main() {}\n", | ||
| }, | ||
| { | ||
| name: "removes code fences without language", | ||
| input: "```\nsome code\nmore code\n```", | ||
| expected: "some code\nmore code\n", | ||
| }, | ||
| { | ||
| name: "handles text without code fences", | ||
| input: "just plain text", | ||
| expected: "just plain text", | ||
| }, | ||
| { | ||
| name: "handles empty string", | ||
| input: "", | ||
| expected: "", | ||
| }, | ||
| { | ||
| name: "handles whitespace around text", | ||
| input: " \n some text \n ", | ||
| expected: "some text", | ||
| }, | ||
| { | ||
| name: "handles only opening fence", | ||
| input: "```go\ncode without closing", | ||
| expected: "code without closing", | ||
| }, | ||
| { | ||
| name: "handles fence with no content", | ||
| input: "```\n```", | ||
| expected: "", | ||
| }, | ||
| { | ||
| name: "handles fence with only language - no newline", | ||
| input: "```python", | ||
| expected: "```python", | ||
| }, | ||
| { | ||
| name: "preserves content that looks like fences but isn't at start", | ||
| input: "some text\n```\nmore text", | ||
| expected: "some text\n```\nmore text", | ||
| }, | ||
| { | ||
| name: "handles multiple lines after fence", | ||
| input: "```javascript\nfunction test() {\n return 'hello';\n}\nconsole.log('world');\n```", | ||
| expected: "function test() {\n return 'hello';\n}\nconsole.log('world');\n", | ||
| }, | ||
| { | ||
| name: "handles single line with fences - no newline", | ||
| input: "```const x = 5;```", | ||
| expected: "```const x = 5;", | ||
| }, | ||
| { | ||
| name: "handles content with leading/trailing whitespace inside fences", | ||
| input: "```\n \n code content \n \n```", | ||
| expected: " \n code content \n \n", | ||
| }, | ||
| { | ||
| name: "handles fence with language and content on same line", | ||
| input: "```go func main() {}```", | ||
| expected: "```go func main() {}", | ||
| }, | ||
| { | ||
| name: "removes only trailing fence markers", | ||
| input: "```\ncode with ``` in middle\n```", | ||
| expected: "code with ``` in middle\n", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| result := Unfence(tt.input) | ||
| require.Equal(t, tt.expected, result) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestSplitLines(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| input string | ||
| expected []string | ||
| }{ | ||
| { | ||
| name: "splits multi-line text", | ||
| input: "line 1\nline 2\nline 3", | ||
| expected: []string{"line 1", "line 2", "line 3"}, | ||
| }, | ||
| { | ||
| name: "handles single line", | ||
| input: "single line", | ||
| expected: []string{"single line"}, | ||
| }, | ||
| { | ||
| name: "handles empty string", | ||
| input: "", | ||
| expected: []string{""}, | ||
| }, | ||
| { | ||
| name: "handles string with only newlines", | ||
| input: "\n\n\n", | ||
| expected: []string{"", "", "", ""}, | ||
| }, | ||
| { | ||
| name: "handles text with trailing newline", | ||
| input: "line 1\nline 2\n", | ||
| expected: []string{"line 1", "line 2", ""}, | ||
| }, | ||
| { | ||
| name: "handles text with leading newline", | ||
| input: "\nline 1\nline 2", | ||
| expected: []string{"", "line 1", "line 2"}, | ||
| }, | ||
| { | ||
| name: "handles mixed line endings and content", | ||
| input: "start\n\nmiddle\n\nend", | ||
| expected: []string{"start", "", "middle", "", "end"}, | ||
| }, | ||
| { | ||
| name: "handles single newline", | ||
| input: "\n", | ||
| expected: []string{"", ""}, | ||
| }, | ||
| { | ||
| name: "preserves empty lines between content", | ||
| input: "first\n\n\nsecond", | ||
| expected: []string{"first", "", "", "second"}, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| result := SplitLines(tt.input) | ||
| require.Equal(t, tt.expected, result) | ||
| }) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.