-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Commentor #723
Commentor #723
Changes from all commits
0386d1e
d72a2b3
735d2f0
a8d5a4f
6bdd6c9
d54bdc9
5791433
621c5a8
253d297
06362e6
8f0ee3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
"demux", | ||
"devcontainers", | ||
"dockerode", | ||
"docstrings", | ||
"doptions", | ||
"Entra", | ||
"Evals", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ See [configuration](/genaiscript/getting-started/configuration). | |
|
||
## Files | ||
|
||
`run` takes one or more [glob](https://en.wikipedia.org/wiki/Glob_(programming)) patterns to match files in the workspace. | ||
`run` takes one or more [glob](<https://en.wikipedia.org/wiki/Glob_(programming)>) patterns to match files in the workspace. | ||
|
||
```bash sh | ||
npx genaiscript run <script> "**/*.md" "**/*.ts" | ||
|
@@ -150,7 +150,7 @@ permissions: | |
pull-requests: write | ||
``` | ||
|
||
- set the `GITHUB_TOKEN` secret in the `env` when running the cli | ||
- set the `GITHUB_TOKEN` secret in the `env` when running the cli | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect indentation, there should be no leading spaces before the bullet point.
|
||
|
||
```yaml | ||
- run: npx --yes genaiscript run ... -prc --out-trace $GITHUB_STEP_SUMMARY | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,7 +160,7 @@ index N in the above snippets, and then be prefixed with exactly the same whites | |
the original snippets above. See also the following examples of the expected response format. | ||
|
||
CHANGELOG: | ||
\`\`\` | ||
\`\`\`changelog | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect code fence; 'changelog' language specifier should be removed.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changelog format has been changed from a generic code block to a specific 'changelog' code block, which may not be recognized by the rendering engine or may alter the intended presentation.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing language specifier for the code fence, it should specify the language for syntax highlighting.
|
||
ChangeLog:1@<file> | ||
Description: <summary>. | ||
OriginalCode@4-6: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
title: Commenter | ||
description: Adds comments to your code | ||
sidebar: | ||
order: 20 | ||
--- | ||
|
||
import { Code } from "@astrojs/starlight/components" | ||
import source from "../../../../../packages/vscode/genaisrc/cmt.genai.mts?raw" | ||
|
||
Inspired by [a tweet](https://x.com/mckaywrigley/status/1838321570969981308), this script automates adding comments to source code. | ||
|
||
```ts title="cmt.genai.mts" | ||
script({ | ||
title: "Source Code Comment Generator", | ||
description: `Add comments to source code to make it more understandable for AI systems or human developers. | ||
Modified from https://x.com/mckaywrigley/status/1838321570969981308. | ||
`, | ||
}) | ||
``` | ||
|
||
### Getting Files to Process | ||
|
||
The user can select which files to comment or, if nothing is selected, we'll use Git to find all modified files. | ||
|
||
```ts | ||
let files = env.files | ||
if (files.length === 0) { | ||
files = await Promise.all( | ||
(await host.exec("git status --porcelain")).stdout | ||
.split("\n") | ||
.filter((filename) => /^ [M|U]/.test(filename)) | ||
.map( | ||
async (filename) => | ||
await workspace.readText(filename.replace(/^ [M|U] /, "")) | ||
) | ||
) | ||
} | ||
``` | ||
|
||
### Processing Each File | ||
|
||
We process each file separately, to avoid exploding the token context and keep the AI focused. | ||
We can use [inline prompts](/genaiscript/reference/scripts/inline-prompts) to make inner queries. | ||
|
||
```ts | ||
for (const file of files) { | ||
console.log(`processing ${file.filename}`) | ||
... add comments | ||
... save changes | ||
} | ||
``` | ||
|
||
### The Prompt for Adding Comments | ||
|
||
Within the `addComments` function, we prompt GenAI to add comments. We do this twice to increase the likelihood of generating useful comments. | ||
|
||
```ts | ||
const res = await runPrompt( | ||
(ctx) => { | ||
ctx.$`You can add comments to this code...` | ||
}, | ||
{ system: ["system", "system.files"] } | ||
) | ||
``` | ||
|
||
We provide a detailed set of instructions to the AI for how to analyze and comment on the code. | ||
|
||
## How to Run the Script | ||
|
||
To run this script, you'll first need to install the GenAIScript CLI. [Follow the installation guide here](https://microsoft.github.io/genaiscript/getting-started/installation). | ||
|
||
```shell | ||
genaiscript run cmt | ||
``` | ||
|
||
## Full source ([GitHub](https://github.com/microsoft/genaiscript/blob/main/packages/vscode/genaisrc/cmt.genai.mts)) | ||
|
||
<Code code={source} wrap={true} lang="ts" title="cmt.genai.mts" /> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect link format, angle brackets should not be used in markdown links.