-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* artificial error * Add GitHub Action guide, enhance filename filtering, and add spell checker script * Fix grammar and punctuation in documentation and refine AI analysis instructions * Add file chunk size option, replace unique with uniq from es-toolkit and update dependencies * revert file chunks * Update CLI docs, improve spell checker script, and modify type definitions * Update spell checker script and documentation for clarity and changelog integration * Update script to fetch staged Markdown files for spell-checking and refine documentation * Fix syntax error by adding closing backtick in poem.genai.mts
- Loading branch information
Showing
40 changed files
with
267 additions
and
105 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
title: GitHub Action Investigator | ||
description: Investigate GitHub Actions failures | ||
sidebar: | ||
order: 100 | ||
--- | ||
import { Code } from "@astrojs/starlight/components" | ||
import source from "../../../../../packages/sample/genaisrc/gai.genai.mts?raw" | ||
import gasource from "../../../../../.github/workflows/genai-investigator.yml?raw" | ||
|
||
This is an in-depth guide to build a script that interactively investigates GitHub Actions failures. | ||
|
||
## Full source ([GitHub](https://github.com/microsoft/genaiscript/blob/main/packages/sample/genaisrc/gai.genai.mts)) | ||
|
||
<Code code={source} wrap={true} lang="ts" title="gai.genai.mts" /> | ||
|
||
<Code code={gasource} wrap={true} lang="yaml" title="gai.yml" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
title: Spell Checker | ||
description: Spell check a document | ||
sidebar: | ||
order: 101 | ||
--- | ||
|
||
import { Code } from "@astrojs/starlight/components" | ||
import source from "../../../../../packages/sample/genaisrc/sc.genai.mts?raw" | ||
|
||
Automating and improving the efficiency of proofreading documents is a common need among developers and writers. This script addresses this need by checking and correcting spelling and grammar in Markdown files. | ||
|
||
## Code Explanation | ||
|
||
Starting at the top of the script, we see that it's a GenAI script, which is evident from the `.mts` extension and the `script` function call. | ||
|
||
```ts | ||
script({ | ||
title: "Spell checker", | ||
system: ["system", "system.files", "system.diff"], | ||
temperature: 0.1, | ||
}) | ||
``` | ||
|
||
This block sets the title of the script to "Spell checker" and specifies that it uses several system prompts, such as file operations and diff generation. The `temperature` is set to `0.1`, indicating that the script will generate output with low creativity, favoring precision. | ||
|
||
### Fetching Files for Checking | ||
|
||
Next, we check for files to process, first from the environment and then from Git if none are provided. | ||
|
||
```ts | ||
let files = env.files | ||
if (files.length === 0) { | ||
const gitStatus = await host.exec("git diff --name-only --cached") | ||
files = await Promise.all( | ||
gitStatus.stdout | ||
.split(/\r?\n/g) | ||
.filter((filename) => /\.(md|mdx)$/.test(filename)) | ||
.map(async (filename) => await workspace.readText(filename)) | ||
) | ||
} | ||
``` | ||
|
||
In this block, we're assigning files from the `env` variable, which would contain any files passed to the script. If no files are provided, we execute a Git command to get a list of all cached (staged) modified files and filter them to include only `.md` and `.mdx` files. We then read the content of these files for processing. | ||
|
||
### Defining the File Types to Work on | ||
|
||
Following this, there's a `def` call: | ||
|
||
```ts | ||
def("FILES", files, { endsWith: [".md", ".mdx"] }) | ||
``` | ||
|
||
This line defines `FILES` to be the array of files we gathered. The options object `{ endsWith: [".md", ".mdx"] }` tells GenAI that we're only interested in files ending with `.md` or `.mdx`. | ||
|
||
The `$`-prefixed backtick notation is used to write the prompt template: | ||
|
||
```ts | ||
$`Fix the spelling and grammar of the content of FILES. Use diff format for small changes. | ||
- do NOT fix the frontmatter | ||
- do NOT fix code regions | ||
- do NOT fix \`code\` and \`\`\`code\`\`\` | ||
- in .mdx files, do NOT fix inline typescript code | ||
` | ||
``` | ||
|
||
This prompt instructs GenAI to fix spelling and grammar in the content of the defined `FILES`, outputting small changes in diff format. It also specifies constraints, such as not fixing the frontmatter, code regions, inline code in markdown, and inline TypeScript code in MDX files. | ||
|
||
Finally, there is a `defFileOutput` call: | ||
|
||
```ts | ||
defFileOutput(files, "fixed markdown or mdx files") | ||
``` | ||
|
||
This call declares the intent that the script will generate "fixed markdown or mdx files" based on the input files. | ||
|
||
## How to Run the Script with GenAIScript CLI | ||
|
||
Running this spell checker script is straightforward with the GenAIScript CLI. First, ensure you have the CLI installed by following the instructions in the [GenAIScript documentation](https://microsoft.github.io/genaiscript/getting-started/installation). | ||
|
||
Once you have the CLI installed, navigate to your local copy of the script in your terminal or command line interface. Run the following command to execute the spell checker: | ||
|
||
```shell | ||
genaiscript run sc | ||
``` | ||
|
||
Remember, you do not need to specify the `.genai.mts` extension when using the `run` command. | ||
|
||
And there you have it—a detailed walkthrough of a GenAI spell checker script for markdown files. Happy coding and perfecting your documents! | ||
|
||
## Full source ([GitHub](https://github.com/microsoft/genaiscript/blob/main/packages/sample/genaisrc/sc.genai.mts)) | ||
|
||
<Code code={source} wrap={true} lang="ts" title="sc.genai.mts" /> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.