問同一個問題 DeepSeek-r1 / Grok-3 / Gemini 2.0 / ChatGPT 的結(jié)果出乎意料...
最近在寫 TS ,希望實現(xiàn)一個類似 .gitignore 的功能,已有代碼如下:
/**
* Check if a file should be ignored based on patterns
*/
export function shouldIgnore(filePath: string, ignorePatterns: string[]): boolean {
// Simple implementation of glob pattern matching
return ignorePatterns.some(pattern => {
if (pattern.endsWith('/**')) {
const dirPattern = pattern.slice(0, -3);
return filePath.startsWith(dirPattern);
} else if (pattern.startsWith('**/*.')) {
const ext = pattern.slice(3);
return filePath.endsWith(ext);
} else if (pattern.includes('*')) {
const regex = new RegExp('^' + pattern.replace(/\*/g, '.*') + '$');
return regex.test(path.basename(filePath));
}
return filePath.includes(pattern);
});
}
在 JS 層面使用正則匹配,顯然不是什么好方案。單元測試也過不了。
于是整理代碼和報錯信息,找了四個免費的模型,問問思路。
先說結(jié)論:DeepSeek-r1 思考了 298 秒,我一度以為其陷入了死循環(huán),但最后其在第一輪給出的方案,被 Grok-3 、 Gemini 2.0 、 ChatGPT 統(tǒng)統(tǒng)認可是最優(yōu)方案之一。且后三者都沒有在第一輪對話給出這個方案。
下面來看具體過程。
第一輪
第一輪提問
請幫我排查錯誤原因并修正代碼。我希望實現(xiàn)和 .gitignore 一樣的效果。如有必要可以引入第三方匹配 lib (比如可以獲取更高的性能、更全的功能)
先看最快的三個回答:
Grok-3
Grok-3 推薦了 minimatch 工具。
Gemini 2.0 Flash Thinking
Gemini 2.0 推薦了 micromatch 。
ChatGPT
ChatGPT-推理 最原生,推薦了 glob 。
在等了很久后, DeepSeek-r1 終于給出答案。我本來已經(jīng)對其不抱希望。
DeepSeek-r1
其推薦了 ignore 工具。這大大引起我的興趣,因為從名字而言,這是和我的 .gitignore 需求最接近的。
到底哪個工具好
于是我又問:minimatch 和 glob 和 ignore 這三個 lib 有什么區(qū)別?更推薦哪個?
ChatGPT
Gemini
Gemini
Grok
Grok
顯然,最終 Grok 和 Gemini 明顯更加推薦 DeepSeek-r1 一開始就推薦的 ignore 工具。
這里很疑惑:
- 明明 ignore 最合適,為什么這三家沒有想到?(我的首輪提問中明明已經(jīng)有了
.gitignore
這樣的關鍵詞?) - 為什么 DeepSeek-r1 思考了這么久,想到了 ignore ?思考時間與答案質(zhì)量成正比嗎?
但是看起來, DeepSeek-r1 的大部分時間在思考如何寫算法。而最后,其才臨門一腳想到了 ignore 。感覺本次實驗取樣不足,沒有置信度。
對了,關于第二輪的問題“minimatch 和 glob 和 ignore 這三個 lib 有什么區(qū)別?更推薦哪個?”
,DeepSeek-r1 是怎么回答的呢?