@@ -39,13 +39,17 @@ and look for any AI coding instructions you add using your favorite IDE or text
39
39
40
40
Specifically, aider looks for one-liner comments (# ... or // ...) that either start or end with ` AI ` or ` AI! ` , like these:
41
41
42
- ```
42
+ ``` python
43
43
# Implement a snake game. AI!
44
+ ```
44
45
46
+ Or in ` // ` comment languages...
47
+
48
+ ``` js
45
49
// Write a self-learning protein folding prediction engine. AI!
46
50
```
47
51
48
- Aider will take note of all the comments you add that start or end with ` AI ` , but
52
+ Aider will take note of all the comments that start or end with ` AI ` , but
49
53
a comment that includes ` AI! ` with an exclamation point is special.
50
54
That triggers aider to take action to collect * all* the AI comments and use them as instructions to make code changes.
51
55
@@ -142,3 +146,68 @@ simply put an `#AI` comment in it and save the file.
142
146
You can undo/remove the comment immediately if you like, the file
143
147
will still be added to the aider chat.
144
148
149
+
150
+ ### You can be lazy
151
+
152
+ The comments in the examples above all show AI
153
+ comments with full sentences, proper capitalization, punctuation, etc.
154
+ This was done for clarity, but is not needed in practice.
155
+
156
+ Most LLMs are perfectly capable of dealing with ambiguity and
157
+ inferring implied intent.
158
+ This often allows you to be quite lazy with your AI comments.
159
+ In particular, you can start and end comments with lowercase ` ai ` and ` ai! ` ,
160
+ but you can also be much more terse with the request itself.
161
+ Below are simpler versions of some of the examples given above.
162
+
163
+ When the context clearly implies the needed action, ` ai! ` might be all you
164
+ need. For example, to implement a factorial function
165
+ in a program full of other math functions either of these
166
+ approaches would probably work:
167
+
168
+ ``` js
169
+ function factorial (n ) // ai!
170
+ ```
171
+
172
+ Or...
173
+
174
+ ```js
175
+ // add factorial() ai!
176
+ ```
177
+
178
+ Rather than a long, explicit comment like "Add error handling for NaN and less than zero,"
179
+ you can let aider infer more about the request.
180
+ This simpler comment may be sufficient:
181
+
182
+ ```javascript
183
+ app.get('/sqrt/:n', (req, res) => {
184
+ const n = parseFloat (req .params .n );
185
+
186
+ // add error handling ai!
187
+
188
+ const result = math .sqrt (n);
189
+ res .json ({ result: result });
190
+ });
191
+ ```
192
+
193
+ Similarly, this refactor probably could have been requested with fewer words, like this:
194
+
195
+ ``` python
196
+ @app.route (' /factorial/<int:n>' )
197
+ def factorial (n ):
198
+ if n < 0 :
199
+ return jsonify(error = " Factorial is not defined for negative numbers" ), 400
200
+
201
+ # ai refactor...
202
+
203
+ result = 1
204
+ for i in range (1 , n + 1 ):
205
+ result *= i
206
+
207
+ # ... to compute_factorial() ai!
208
+
209
+ return jsonify(result = result)
210
+ ```
211
+
212
+ As you use aider with your chosen LLM, you can develop a sense for how
213
+ explicit you need to make your AI comments.
0 commit comments