4 ms·
Try asking code-davinci-002 instead of text-davinci-003. curl https://api.openai.com/v1/completions \ -H "Content-Type: application/json" \ -H
by shagie 4y ago
Try asking code-davinci-002 instead of text-davinci-003.
curl https://api.openai.com/v1/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "code-davinci-002",
"prompt": "##### Create a regular expression to match words starting with 'dog' or ending with 'cat'.\n \n### Java Code",
"temperature": 0,
"max_tokens": 182,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0,
"stop": ["###"]
}'
This returned:
```java
String regex = "\\b(dog|cat)\\b";
```
- deleted 4y ago[deleted]
- zaroth 4y agoPretty sure that regexp is wrong though? Wouldn’t having ‘\b’ on both sides match beginning AND end? It’s got the parenthesis for the ‘|’ in the wrong place.
- shagie 4y agoYep. But it gave straight up code rather than trying to persuade a natural language LLM to write code. The regex I was expecting would be "\\b(dog.*)|(.*cat)\\b" The key point is to ask the code model. Part of what ChatGPT does is it appears to categorize the question and then may dispatch it to the code model. If you know you have a code question, asking the code model first would likely be more productive and less expensive.
- codetrotter 4y agoIt’s definitely not doing what the prompt asked for. https://regex101.com/r/ZNQa9X/1 https://regex101.com/r/ZNQa9X/1 The generated regex is the same as (\bdog\b)|(\bcat\b) https://regex101.com/r/vTtEU4/1 https://regex101.com/r/vTtEU4/1 I’m currently trying to figure out how to match a word starting with dog without using \bdog.* because .* would proceed to eat the rest of the line. So I was thinking I could say \bdog[^\b]* But that doesn’t work, it also ends up eating the rest of the line as well.
- shagie 4y agoUse \S which is the opposite set of \s which avoids eating word boundaries too. \b(dog\S*)|(\S*cat)\b You could also use a \B instead of a \S though there are different meanings there.
- codetrotter 4y agoIt almost does the trick https://regex101.com/r/sbpy8s/1 https://regex101.com/r/sbpy8s/1 But this matches for example dog.cat as one single word. But I would like that it matches separately dog and cat in this case. Likewise, I’d want for example dogapple-bananacat to be matched as two separate words dogapple and bananacat After a bit more reading online I thought that maybe the following regex would do what I want: \b(dog\p{L}*)|(\p{L}*cat)\b https://regex101.com/r/1NT5Ie/1 https://regex101.com/r/1NT5Ie/1 But that does not match dog42 as a word. What I want is a way to include everything after dog that is not \b And likewise everything preceding cat that is not \b Edit: I think I’ve found it after reading https://stackoverflow.com/questions/4541573/what-are-non-word-boundary-in-regex-b-compared-to-word-boundary https://stackoverflow.com/questions/4541573/what-are-non-wor... (\bdog\w*)|(\w*cat\b) Seems to behave exactly like I want. https://regex101.com/r/f3uJUE/1 https://regex101.com/r/f3uJUE/1
- btown 4y agoAfter all, who needs wget when you have \wcat!
- deleted 4y ago
- ketzo 4y agoMan, this thread is a great example for why I don't use regexes, lol