14,953
edits
Tags: Mobile edit Mobile web edit |
(→相關網頁) |
||
| (10 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
AI Assistants in Coding | AI Assistants in Coding | ||
{{Template:Generative AI Tool}} | |||
== Usages == | == Usages == | ||
* Write documentation (or Generate Docs) | * Write documentation (or Generate Docs) | ||
* Convert file to another language | * Convert file to another language | ||
* Refactor the following code (or simplify this) | * Refactor the following code (or simplify this, or make code easier to read) | ||
* Explain the following code | * Explain the following code (or add comments to my code) | ||
* Generate Unit Tests (or generate tests) | * Generate Unit Tests (or generate tests) | ||
* Generate Code | * Generate Code | ||
| Line 12: | Line 13: | ||
== Prompts cases == | == Prompts cases == | ||
=== Improve the quality of Meta-prompt === | |||
Prompt | |||
<pre> | |||
Now we need to review and improve the development discussion of a file management tool. Please analyze from the following three aspects: | |||
1. Original Problem Analysis | |||
Please analyze in this discussion: | |||
- Initial technical issues and error situations | |||
- Original solution attempts | |||
- Key technical barriers discovered during discussion | |||
2. Extended Requirements and Improvement Opportunities | |||
Based on the discussion process: | |||
- List functionality points that were not considered but are actually important | |||
- Identify potential technical risks and limitations | |||
- Propose possible optimization directions | |||
3. Professional Specification Writing Guidelines | |||
Please provide: | |||
- Specification structure suitable for this type of tool | |||
- Key items and content suggestions | |||
- Technical documentation points that need special attention | |||
Based on these three aspects, please provide a complete prompt template for guiding similar tool development discussions. | |||
</pre> | |||
<pre> | |||
現在需要回顧並改進一個檔案管理工具的開發討論。請從以下三個面向分析: | |||
1. 原始問題分析 | |||
請分析這段討論中: | |||
- 最初提出的技術問題和錯誤情況 | |||
- 原始的解決方案嘗試 | |||
- 討論過程中發現的關鍵技術障礙 | |||
2. 延伸需求和改進機會 | |||
基於討論過程: | |||
- 列出原本未考慮到但實際重要的功能點 | |||
- 識別潛在的技術風險和限制 | |||
- 提出可能的改善方向 | |||
3. 專業規格書撰寫指引 | |||
請提供: | |||
- 適合此類工具的規格書架構 | |||
- 關鍵項目和內容建議 | |||
- 特別需要注意的技術文件要點 | |||
以上述三個面向為基礎,請提供一個完整的 prompt 模板,用於指導類似工具的開發討論。 | |||
</pre> | |||
=== Prompt for refactor source code === | === Prompt for refactor source code === | ||
Prompt | Prompt | ||
| Line 58: | Line 109: | ||
JetBrain 推出 [https://plugins.jetbrains.com/plugin/22282-ai-assistant AI Assistant 外掛]功能,目前付費客戶可以免費試用 7 天。它下的 prompt,供大家參考 | JetBrain 推出 [https://plugins.jetbrains.com/plugin/22282-ai-assistant AI Assistant 外掛]功能,目前付費客戶可以免費試用 7 天。它下的 prompt,供大家參考 | ||
==== | ==== Prompt from JetBrain ==== | ||
<pre> | <pre> | ||
Write "XXXClassTest' tests for the | Write "XXXClassTest' tests for the | ||
| Line 86: | Line 121: | ||
'''php ?php class | '''php ?php class | ||
XXXClass { ... | XXXClass { ... | ||
''' | |||
</pre> | |||
==== Prompt with Complete Testing Strategy ==== | |||
<pre> | |||
Write complete unit tests for the "$METHOD_NAME" method in the "$CLASS_NAME" class. | |||
## Test Target | |||
- Class: $CLASS_NAME | |||
- Method: $METHOD_NAME | |||
- Test Class Name: ${CLASS_NAME}Test | |||
- Namespace: $NAMESPACE | |||
- Source File: $FILE_NAME | |||
## Source Code | |||
\```php | |||
$CODE | |||
\``` | |||
## Writing Conventions | |||
**File Structure** | |||
- Test file must begin with `<?php` | |||
- Namespace should be `Tests\$NAMESPACE` | |||
- Place test file at `__tests__/${CLASS_NAME}Test.php` | |||
**Test Conventions** | |||
- Extend `PHPUnit\Framework\TestCase` | |||
- Each test method should cover only a single behavior | |||
- Method naming format: `test_[method_name]_[scenario_description]` | |||
- Use `setUp()` to initialize shared objects | |||
**Coverage** | |||
- Happy Path: expected results under normal input | |||
- Edge Cases: boundary values, null values, extreme inputs | |||
- Error States: thrown exceptions, error returns | |||
## Output Requirements | |||
- Test file must be complete and executable without any modifications | |||
- Add a comment above each test method describing its purpose | |||
- Include the CLI command to run the test file | |||
</pre> | |||
Instruction of Complete Testing Strategy | |||
1. '''Happy Path''' — Verifies the program behaves correctly under expected, valid inputs. | |||
<pre lang="php"> | |||
// e.g. formatDate should return the correct format when given a valid date | |||
$this->assertSame('2024/01/15', $this->formatter->format('2024-01-15')); | |||
</pre> | |||
2. '''Edge Cases''' — Covers extreme or atypical but still valid inputs. | |||
<pre lang="php"> | |||
// e.g. empty string, zero value, maximum integer, boundary date | |||
$this->assertSame('', $this->formatter->format('')); | |||
</pre> | |||
3. '''Error States''' — Validates how the program handles illegal inputs or system failures. | |||
<pre lang="php"> | |||
// e.g. should throw an exception or degrade gracefully when an invalid date is passed | |||
$this->expectException(\InvalidArgumentException::class); | |||
$this->formatter->format(null); | |||
</pre> | |||
==== Simple version ==== | |||
<pre> | |||
Write PHPUnit test case including edge cases | |||
'''php | |||
function xxx(){ ... | |||
''' | ''' | ||
</pre> | </pre> | ||
| Line 115: | Line 224: | ||
``` | ``` | ||
SQL syntax ... | SQL syntax ... | ||
``` | |||
</pre> | |||
=== Prompt for Direct Code Analysis === | |||
Use Case: When AI debugging tools aren't working (agents, IDEs, etc.), try a clean approach: Use web-based AI with just the code—no context, no error messages. Simply ask "What's wrong with this code?" or "Find any issues?" | |||
This fresh perspective often solves stubborn problems by avoiding bias from error messages and predetermined fix patterns, uncovering root causes that were previously missed. | |||
Example 1 | |||
<pre> | |||
Find any issues in this code: | |||
``` | |||
source code ... | |||
``` | |||
</pre> | |||
Example 2 | |||
<pre> | |||
What problems do you see in this code? | |||
``` | |||
source code ... | |||
``` | |||
</pre> | |||
Example 3 | |||
<pre> | |||
Review this code and identify potential issues: | |||
``` | |||
source code ... | |||
``` | ``` | ||
</pre> | </pre> | ||
| Line 129: | Line 268: | ||
* [https://plugins.jetbrains.com/plugin/22282-ai-assistant AI Assistant - IntelliJ IDEs Plugin | Marketplace] | * [https://plugins.jetbrains.com/plugin/22282-ai-assistant AI Assistant - IntelliJ IDEs Plugin | Marketplace] | ||
* [https://docs.github.com/en/copilot/overview-of-github-copilot/about-github-copilot-individual About GitHub Copilot Individual - GitHub Docs] | * [https://docs.github.com/en/copilot/overview-of-github-copilot/about-github-copilot-individual About GitHub Copilot Individual - GitHub Docs] | ||
* [https://edge.aif.tw/anitahu-interview-talent-education/ 生成式 AI 增加學生溝通能力?胡敏君:因有強烈動機與好奇心] | |||
[[Category: Programming]] | |||
[[Category:Programming]] | [[Category: Generative AI]] | ||
[[Category: | [[Category: Revised with LLMs]] | ||
[[Category: | |||