Skip to content

Commit

Permalink
Update file extensions from .genai.js to .genai.mjs in documentation …
Browse files Browse the repository at this point in the history
…and script references
  • Loading branch information
pelikhan committed Sep 6, 2024
1 parent a6ea67b commit 3e85443
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 34 deletions.
6 changes: 3 additions & 3 deletions docs/src/content/docs/case-studies/blocks-localization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ spiele %music Ton|bei %note|für %duration
If you look closely in the script source, you will find guidance in the prompt to properly
handle the variables.

```js title="block-translator.genai.js"
```js title="block-translator.genai.mjs"
$`...
- Every variable name is prefixed with a '%' or a '$', like %foo or $bar.
- Do NOT translate variable names.
Expand All @@ -67,7 +67,7 @@ to encode the strings, to avoid encoding issues.
We use the `defFileMerge` feature to convert the parse key-value file, and merge them with the existing translations.


```js title="block-translator.genai.js"
```js title="block-translator.genai.mjs"
// register a callback to custom merge files
defFileMerge((filename, label, before, generated) => {
if (!filename.endsWith("-strings.json")) return undefined
Expand Down Expand Up @@ -110,7 +110,7 @@ using the `--vars lang=fr` argument.

The full script is show below.

<Code code={scriptSource} title="block-translator.genai.js" wrap={true} lang="js" />
<Code code={scriptSource} title="block-translator.genai.mjs" wrap={true} lang="js" />

The result from this script can be inspected
in this [pull request](https://github.com/microsoft/pxt-jacdac/pull/108).
10 changes: 5 additions & 5 deletions docs/src/content/docs/case-studies/image-alt-text.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ images and generate a description alt text.
To start, we assume that the script is run on a single image file
and we use [defImage](/genaiscript/reference/scripts/images) to add it to the prompt context.

```js title="image-alt-text.genai.js"
```js title="image-alt-text.genai.mjs"
const file = env.files[0]
defImages(file)
```

Then we give a task to the LLM to generate a good alt text.

```js title="image-alt-text.genai.js" wrap
```js title="image-alt-text.genai.mjs" wrap
...
$`You are an expert in assistive technology. You will analyze each image
and generate a description alt text for the image.`
Expand All @@ -50,7 +50,7 @@ and generate a description alt text for the image.`
finally, we use [defFileOutput](/genaiscript/reference/scripts/file-ouput) to define
a file output route.

```js title="image-alt-text.genai.js" wrap
```js title="image-alt-text.genai.mjs" wrap
...
defFileOutput(file.filename + ".txt", `Alt text for image ${file.filename}`)
```
Expand Down Expand Up @@ -85,7 +85,7 @@ for file in assets/**.png; do
To avoid regenerating the alt text, we also detect if a file exists in the script and cancel accordingly.
```sh title="image-alt-text.genai.js" wrap
```sh title="image-alt-text.genai.mjs" wrap
for file in assets/**.png; do
if [ ! -f "$file" ]; then
npx --yes genaiscript run image-alt-text "$file"
Expand All @@ -97,4 +97,4 @@ done
The full source looks like this:
<Code code={scriptSrc} wrap={true} lang="js" title="image-alt-text.genai.js" />
<Code code={scriptSrc} wrap={true} lang="js" title="image-alt-text.genai.mjs" />
6 changes: 3 additions & 3 deletions docs/src/content/docs/case-studies/release-notes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ We start our script by calling `git` a few times to retreive the previous releas
the list of commits, the diff since the tag.
(This magic was mostly found using a GitHub Copilot Chat session).

```js title="git-release-notes.genai.js" wrap
```js title="git-release-notes.genai.mjs" wrap
const { stdout: tag } = await host.exec("git", ["describe", "--tags", "--abbrev=0", "HEAD^",])
const { stdout: commits } = await host.exec("git", ["log", `HEAD...${tag}`,])
const { stdout: diff } = await host.exec("git", ["diff", `${tag}..HEAD`,])
Expand All @@ -41,7 +41,7 @@ const { stdout: diff } = await host.exec("git", ["diff", `${tag}..HEAD`,])
We use the `def` function with `maxTokens` to inline this information without exceeding the content window
of the model (32k input).

```js title="git-release-notes.genai.js" wrap
```js title="git-release-notes.genai.mjs" wrap
def("COMMITS", commits, { maxTokens: 4000 })
def("DIFF", diff, { maxTokens: 20000 })
```
Expand Down Expand Up @@ -69,7 +69,7 @@ for the upcoming release.

The full script as it is running in GenAIScript is as follows:

<Code code={scriptSrc} wrap={true} lang="js" title="git-release-notes.genai.js" />
<Code code={scriptSrc} wrap={true} lang="js" title="git-release-notes.genai.mjs" />

## Release-it integration

Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/case-studies/seo-frontmatter.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The script below will generate SEO information
and update the existing file. The script uses a custom merge strategy
to merge the new front matter with the existing front matter.

<Code code={importedCode} wrap={true} lang="js" title="slides.genai.js" />
<Code code={importedCode} wrap={true} lang="js" title="slides.genai.mjs" />

## Batching over all files

Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/case-studies/tla-ai-linter.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The following is a TLA+ spec that models a seminal solution to the [termination

The following GenAI script will lint the TLA+ spec above. More specifically, it will check if the prose comments in the spec are consistent with the TLA+ definitions.

<Code code={scriptSource} wrap={true} lang="js" title="tlAI-Linter.genai.js" />
<Code code={scriptSource} wrap={true} lang="js" title="tlAI-Linter.genai.mjs" />

- line numbers are added to the file content to help the LLM precisely locate the issues.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using the [Visual Studio Code Debugger](https://code.visualstudio.com/Docs/edito

## Starting a debugging session

- Open the `.genai.js` file to debug and add breakpoints.
- Open the `.genai.mjs` file to debug and add breakpoints.

### From the env files

Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Markdown is a lightweight markup language created by John Gruber in 2004, known

<!-- genaiscript output end -->

GenAIScript will execute `summarize.genai.js` and generate the `👤 user` message that will be sent to the LLM chat. It also populates the `env.files` variable with the files selected in the context (from a user UI interaction or CLI arguments).
GenAIScript will execute `summarize.genai.mjs` and generate the `👤 user` message that will be sent to the LLM chat. It also populates the `env.files` variable with the files selected in the context (from a user UI interaction or CLI arguments).

The LLM responds with the `🤖 assistant` message and GenAIScript parses the output
to extract structured data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Steps } from "@astrojs/starlight/components"
import { Content as CreateScript } from "../../../components/CreateScript.mdx"

GenAIScript use stylized JavaScript with minimal syntax.
They are stored as files (`genaisrc/*.genai.js` or `genaisrc/*.genai.mjs`) in your project.
They are stored as files (`genaisrc/*.genai.mjs` or `genaisrc/*.genai.mts`) in your project.
The execution of a genaiscript creates the prompt that will be sent to the LLM.

<Steps>
Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/docs/guides/business-card-scanner.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defImages(env.files)

All together the script looks like the following:

<Code title="scan-business-card.genai.js" code={importedCode} wrap={true} lang="js" />
<Code title="scan-business-card.genai.mjs" code={importedCode} wrap={true} lang="js" />

## Using a schema

Expand All @@ -63,4 +63,4 @@ const schema = defSchema("EXPENSE", {

And the script above is adapter to use the schema instead of the CSV description.

<Code title="scan-business-card.genai.js" code={importedSchemaCode} wrap={true} lang="js" />
<Code title="scan-business-card.genai.mjs" code={importedSchemaCode} wrap={true} lang="js" />
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The goal is to create a script that detects when the `description` field in the

GenAIScript is meant to run on files and provides a special variable `env.files` that contains the list of files to be analyzed. You can use this variable to include the files in the context using the [def](/genaiscript/reference/scripts/context) function. We limit each file to 2000 tokens to avoid exploding the content on large files.

```js title="detect-outdated-descriptions.genai.js"
```js title="detect-outdated-descriptions.genai.mjs"
// Define the file to be analyzed
def("DOCS", env.files, { endsWith: ".md", maxTokens: 2000 })
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/guides/present-my-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import importedCode from "../../../../../packages/sample/genaisrc/slides.genai?r

Save the script below in your project as `genaisrc/slides.genai.js`.

<Code code={importedCode} wrap={true} lang="js" title="slides.genai.js" />
<Code code={importedCode} wrap={true} lang="js" title="slides.genai.mjs" />

</li>

Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/guides/pull-request-reviewer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ script({

### All together

<Code code={importedCode} wrap={true} lang="js" title="pr-review.genai.js" />
<Code code={importedCode} wrap={true} lang="js" title="pr-review.genai.mjs" />

## Step 2: Automation in Github Actions

Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/docs/reference/scripts/aici.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This feature is experimental and may change in the future.

Let's take a look at an example.

```js title="answer-to-everything.genai.js"
```js title="answer-to-everything.genai.mjs"
$`Ultimate answer is to the life, universe
and everything is ${AICI.gen({ regex: /\d\d/ })}`
```
Expand Down Expand Up @@ -55,7 +55,7 @@ And the text output is `42`.

An AICI template should set the `aici` provider in the model identifier.

```js title="answer-to-everything.genai.js"
```js title="answer-to-everything.genai.mjs"
script({ ...
model: "aici:mixtral",
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ defChatParticipant((_, messages) => {

This script uses a multi-turn chat to generate questions, answers and validate the quality of the answers.

<Code code={scriptSource} wrap={true} lang="js" title="qa-gen.genai.js" />
<Code code={scriptSource} wrap={true} lang="js" title="qa-gen.genai.mjs" />
4 changes: 2 additions & 2 deletions docs/src/content/docs/reference/scripts/prompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ genaiscript:

The `$` is a JavaScript [tagged template](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) that expands the string into the final prompt.

```js title="example.genai.js" assistant=false user=true
```js title="example.genai.mjs" assistant=false user=true
$`You are a helpful assistant.`
```

Expand All @@ -39,7 +39,7 @@ You are a helpful assistant.

You can weave expressions in the template using `${...}`. Expression can be promises and will be awaited when rendering the final prompt.

```js title="example.genai.js" assistant=false user=true
```js title="example.genai.mjs" assistant=false user=true
$`Today is ${new Date().toDateString()}.`
```

Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/reference/scripts/prompty.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ user:

## Running .prompty with GenAIScript

You can run a `.prompty` file from the [cli](/genaiscript/reference/cli) or Visual Studio Code as any other `.genai.js` script.
You can run a `.prompty` file from the [cli](/genaiscript/reference/cli) or Visual Studio Code as any other `.genai.mjs` script.

GenAIScript will convert the `.prompty` content as a script and execute it. It supports most of the front matter options but mostly ignores the model configuration section.

Expand Down
8 changes: 4 additions & 4 deletions docs/src/content/docs/reference/scripts/tools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ that takes a location as input and returns the weather.

This example uses the `current_weather` tool to get the weather for Brussels.

<Code code={weatherScriptSource} wrap={true} lang="js" title="weather.genai.js" />
<Code code={weatherScriptSource} wrap={true} lang="js" title="weather.genai.mjs" />

### Math tool example

Expand All @@ -63,9 +63,9 @@ to evaluate a math expression.

To pick and choose which tools to include in a script,
you can group them in system scripts. For example,
the `current_weather` tool can be included the `system.current_weather.genai.js` script.
the `current_weather` tool can be included the `system.current_weather.genai.mjs` script.

```javascript file="system.current_weather.genai.js" 'defTool("current_weather", ...)'
```javascript file="system.current_weather.genai.mjs" 'defTool("current_weather", ...)'
script({
title: "Get the current weather",
})
Expand All @@ -90,7 +90,7 @@ Let's illustrate how tools come together with a question answering script.
In the script below, we add the `system.retrieval_web_search` which registers the `retrieval_web_search` tool. This tool
will call into `retrieval.webSearch` as needed.

```js file="answers.genai.js"
```js file="answers.genai.mjs"
script({
title: "Answer questions",
system: ["system", "system.retrieval_web_search"]
Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/reference/scripts/web-search.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ BING_SEARCH_API_KEY="your-api-key"

## Tool

Add the [system.retrieval_web_search](https://github.com/microsoft/genaiscript/blob/main/packages/core/src/genaisrc/system.retrieval_web_search.genai.js) system script to register a [tool](/genaiscript/reference/scripts/tools) that uses `retrieval.webSearch`.
Add the [system.retrieval_web_search](https://github.com/microsoft/genaiscript/blob/main/packages/core/src/genaisrc/system.retrieval_web_search.genai.mjs) system script to register a [tool](/genaiscript/reference/scripts/tools) that uses `retrieval.webSearch`.

```js
script({
Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/docs/reference/security-and-trust.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ to understand the capabilities and limitations of GenAIScript.

## Don't trust the scripts

Since the GenAIScript files `.genai.js` are executable JavaScript files and are in fact using a JavaScript runtime (VSCode or Node). It is important to understand that the script can do anything that JavaScript can do. This includes reading and writing files, making network requests, and executing JavaScript arbitrary code.
Since the GenAIScript files `.genai.mjs` are executable JavaScript files and are in fact using a JavaScript runtime (VSCode or Node). It is important to understand that the script can do anything that JavaScript can do. This includes reading and writing files, making network requests, and executing JavaScript arbitrary code.

:::caution

Do not run `.genai.js` scripts from untrusted sources.
Do not run `.genai.mjs` scripts from untrusted sources.

:::

Expand Down

0 comments on commit 3e85443

Please sign in to comment.