|
| 1 | +--- |
| 2 | +# try also 'default' to start simple |
| 3 | +theme: default |
| 4 | +title: GenAIScript |
| 5 | +titleTemplate: "%s" |
| 6 | +#colorSchema: dark |
| 7 | +favicon: "https://microsoft.github.io/genaiscript/images/favicon.svg" |
| 8 | +info: | |
| 9 | + ## AST-based LLM Edits |
| 10 | + with GenAIScript.<br/> |
| 11 | + [Docs](https://microsoft.github.io/genaiscript/) | [GitHub](https://github.com/microsoft/genaiscript/) |
| 12 | +class: text-center |
| 13 | +# https://sli.dev/custom/highlighters.html |
| 14 | +highlighter: shiki |
| 15 | +# https://sli.dev/guide/drawing |
| 16 | +drawings: |
| 17 | + persist: false |
| 18 | +# slide transition: https://sli.dev/guide/animations#slide-transitions |
| 19 | +#transition: slide-left |
| 20 | +# enable MDC Syntax: https://sli.dev/guide/syntax#mdc-syntax |
| 21 | +mdc: true |
| 22 | +layout: center |
| 23 | +--- |
| 24 | + |
| 25 | +{ style="width: 16rem; margin:auto; margin-right: 1rem; display:inline;" } |
| 26 | +{ style="width: 12rem; margin:auto; display:inline;" } |
| 27 | + |
| 28 | +# AST-based LLM Edits |
| 29 | + |
| 30 | +## with ast-grep and GenAIScript |
| 31 | + |
| 32 | +<br/> |
| 33 | +<br/> |
| 34 | + |
| 35 | +https://microsoft.github.io/genaiscript/blog/ast-grep-and-transform/ |
| 36 | + |
| 37 | +--- |
| 38 | +layout: center |
| 39 | +--- |
| 40 | + |
| 41 | +# AST-based search and replace |
| 42 | + |
| 43 | +# powered LLM transforms |
| 44 | + |
| 45 | +- compiler precision/scale for search/insert |
| 46 | +- LLM reasoning for text generation |
| 47 | + |
| 48 | +_best of both worlds!_ |
| 49 | + |
| 50 | +--- |
| 51 | +layout: center |
| 52 | +--- |
| 53 | + |
| 54 | +# Examples |
| 55 | + |
| 56 | +## Upsert comments `/docs` |
| 57 | + |
| 58 | +- Insert new comments |
| 59 | +- Update existing comments |
| 60 | +- DO NOT MODIFY MY CODE! |
| 61 | + |
| 62 | +## Upsert tests `/tests` |
| 63 | + |
| 64 | +- Find existing tests, and updates |
| 65 | +- Generate new tests |
| 66 | +- DO NOT MODIFY MY CODE! |
| 67 | + |
| 68 | +## Upsert logging instrumentation (AOP) |
| 69 | + |
| 70 | +- Find every branch and insert logging statement |
| 71 | +- DO NOT MODIFY MY CODE ANYWHERE ELSE! |
| 72 | + |
| 73 | +--- |
| 74 | + |
| 75 | +# AST-GREP |
| 76 | + |
| 77 | +## ast-grep(sg) is a fast and polyglot tool for code structural search, lint, rewriting at large scale. |
| 78 | + |
| 79 | +- pattern matching over tree-sitter ASTs |
| 80 | + |
| 81 | +{ |
| 82 | + |
| 83 | +- https://ast-grep.github.io/ |
| 84 | + |
| 85 | +--- |
| 86 | +layout: two-cols-header |
| 87 | +--- |
| 88 | + |
| 89 | +# AST-GREP x GenAIScript |
| 90 | + |
| 91 | +::left:: |
| 92 | + |
| 93 | +- Match and replace AST nodes with native node.js library |
| 94 | +- Fast and efficient |
| 95 | +- Polyglot (C, C++, Java, Python, Go, Ruby, Rust, TypeScript, JavaScript, any tree-sitter grammar...) |
| 96 | + |
| 97 | +::right:: |
| 98 | + |
| 99 | +```js |
| 100 | +// search |
| 101 | +const { matches } = await sg.search( |
| 102 | + "ts", |
| 103 | + "src/fib.ts", |
| 104 | + YAML` |
| 105 | +rule: |
| 106 | + kind: function_declaration |
| 107 | + not: |
| 108 | + precedes: |
| 109 | + kind: comment |
| 110 | + stopBy: neighbor |
| 111 | +` |
| 112 | +) |
| 113 | +// update |
| 114 | +const edits = sg.changeset() |
| 115 | +for (const match of matches) { |
| 116 | + const edit = match.replace(/* LLM generates */) |
| 117 | + edits.insert(edit) |
| 118 | +} |
| 119 | +// commit |
| 120 | +const newFiles = edits.commit() |
| 121 | +await workspace.writeFiles(newFiles) |
| 122 | +``` |
| 123 | + |
| 124 | +--- |
| 125 | +layout: center |
| 126 | +--- |
| 127 | + |
| 128 | +# AST-based search and replace |
| 129 | + |
| 130 | +# powered LLM transforms |
| 131 | + |
| 132 | +- compiler precision/scale for search/insert |
| 133 | +- LLM reasoning for text generation |
| 134 | + |
| 135 | +_best of both worlds!_ |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +# Docs generator for TypeScript `/docs` |
| 140 | + |
| 141 | +``` |
| 142 | +find functions without docs |
| 143 | + generate docs |
| 144 | + update file |
| 145 | +find functions with docs |
| 146 | + update docs |
| 147 | + use LLM-as-judge to weed out nits |
| 148 | + update file |
| 149 | +``` |
| 150 | + |
| 151 | +- [source](https://github.com/microsoft/genaiscript/blob/main/genaisrc/docs.genai.mts) |
| 152 | +- [applied to TypeScript ](https://github.com/pelikhan/TypeScript/commit/0c90af56cd533a545257f332b883597e2c07f1b8) |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | +--- |
| 157 | +layout: two-cols-header |
| 158 | +--- |
| 159 | + |
| 160 | +# Debug statement instrumentation |
| 161 | + |
| 162 | +::left:: |
| 163 | + |
| 164 | +``` |
| 165 | +branches = find all branches without debug statements |
| 166 | + insert unique identifier in each branch |
| 167 | +ask LLM to generate debug statement all at once |
| 168 | +parse out the debug statements |
| 169 | + insert debug statements in each branch |
| 170 | +save file |
| 171 | +``` |
| 172 | + |
| 173 | +- 2 LLM requests per file, LLM only regenerates debug statements |
| 174 | +- [source](https://github.com/microsoft/genaiscript/blob/main/genaisrc/debugify.genai.mts) |
| 175 | + |
| 176 | +::right:: |
| 177 | + |
| 178 | +- original |
| 179 | + |
| 180 | +```js |
| 181 | +if (condition) { |
| 182 | + ... |
| 183 | +} |
| 184 | +``` |
| 185 | + |
| 186 | +- marked |
| 187 | + |
| 188 | +```js |
| 189 | +if (condition) { |
| 190 | + dbg(<DBG_ID_1>); |
| 191 | + ... |
| 192 | +} |
| 193 | +``` |
| 194 | + |
| 195 | +- LLM response |
| 196 | + |
| 197 | +```txt |
| 198 | +DBG_ID_1: reason |
| 199 | +``` |
| 200 | + |
| 201 | +- updated |
| 202 | + |
| 203 | +```js |
| 204 | +if (condition) { |
| 205 | + dbg("...describe why we took the branch..."); |
| 206 | + ... |
| 207 | +} |
| 208 | +``` |
0 commit comments