### GenAIScript: LLM Message Payload Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/getting-started/index.mdx Shows an example of the JSON payload sent to an LLM server by GenAIScript. It includes system and user messages, demonstrating how the script's prompt is formatted for the LLM. ```javascript { ... messages: [ { role: "system", content: "You are helpful. ..." }, { role: "user", content: "Write a poem in code." } ] } ``` -------------------------------- ### Use System Tools for File Operations Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/getting-started/index.mdx Shows an example of using the `fs_read_file` system tool within a GenAIScript to read a file and have the LLM summarize its content. This approach allows the LLM to decide when to execute external code. ```javascript script({ tools: "fs_read_file" }) $` - read the file markdown.md - summarize it in one sentence. - save output to markdown.md.txt ` ``` -------------------------------- ### GenAIScript: Example Poem Output Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/getting-started/index.mdx An example of the output generated by an LLM in response to the 'poem.genai.mjs' script. This Python code snippet represents the poem generated by the LLM. ```markdown ```python def poem(): # In the silence of code, ... # And thus, in syntax sublime, # We find the art of the rhyme. ``` ``` -------------------------------- ### GenAIScript: Write a Poem Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/getting-started/index.mdx A basic GenAIScript example that prompts an LLM to write a poem. It utilizes the '$...' syntax for template literals to send a user message to the LLM. This script is typically saved with a '.genai.mjs' extension. ```javascript `$\"Write a poem in code.\"` ``` -------------------------------- ### Few-Shot Learning Examples in GenAIScript Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/blog/drafts/advanced-prompt-engineering-patterns-in-genaiscript-few-shot-learning-and-dynamic-composition.md Demonstrates how to provide examples to a language model to guide its responses. It defines an array of input/output pairs and formats them for use in a prompt, then uses these examples to prompt the model for a new translation. ```javascript const examples = [ { input: "Translate 'hello' to French", output: "bonjour" }, { input: "Translate 'goodbye' to French", output: "au revoir" }, { input: "Translate 'cat' to French", output: "chat" } ] def("EXAMPLES", examples.map(e => `Input: ${e.input}\nOutput: ${e.output}`).join("\n---\n")) def("PROMPT_INPUT", "Translate 'dog' to French") $` You are a translation expert. Use the following examples to guide your answer. {EXAMPLES} Now, {PROMPT_INPUT} `.role("system") const fewShotResult = await $` Input: {PROMPT_INPUT} Output: `.options({ temperature: 0.2 }) ``` -------------------------------- ### GenAIScript: Poem Prompt Example Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/getting-started/index.mdx Illustrates the structure of a user message sent to an LLM within a GenAIScript context. This is the raw text that the '$...' template literal renders, forming part of the prompt. ```text Write a poem in code. ``` -------------------------------- ### Process LLM Outputs to Generate Files Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/getting-started/index.mdx Demonstrates updating a summarizer script to specify an output file pattern using a prompt instruction. The GenAIScript runtime interprets the LLM's output to create files, such as '.summary' files. ```javascript // summarize all files in the env.files array def("FILE", env.files) $`Summarize each FILE in one sentence. Save each generated summary to ".summary"` ``` -------------------------------- ### GenAIScript CLI Usage Examples (Bash) Source: https://context7.com/microsoft/genaiscript/llms.txt Demonstrates various command-line interface commands for GenAIScript. Includes running scripts on files, specifying models and options, setting variables, running tests, parsing different file types (PDF, DOCX), performing retrieval operations (index, search), integrating with pull requests, starting a development server, and converting files. ```bash # Run a script on specific files npx genaiscript run code-review "src/**/*.ts" # Run with custom model and options npx genaiscript run summarize "docs/*.md" \ --model openai:gpt-4 \ --temperature 0.7 \ --out output/ # Run with variables npx genaiscript run analyzer "data.csv" \ --vars format=json \ --vars detailed=true # Test scripts npx genaiscript test code-review # Parse files npx genaiscript parse pdf document.pdf npx genaiscript parse docx report.docx # Retrieval operations npx genaiscript retrieval index "docs/**/*.md" npx genaiscript retrieval search "authentication" "docs/**/*.md" # Pull request integration npx genaiscript run lint "src/**/*.ts" \ --pull-request-reviews \ --pull-request-comment # Start server for VSCode npx genaiscript serve # Convert files with a script npx genaiscript convert blog-image "posts/*.md" ``` -------------------------------- ### Run Startup Script (Shell) Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/scripts/mcp-server.mdx Explains how to specify a startup script using the `--startup` option on the command line. This script runs after the MCP server starts and can be used for initial setup or loading resources. ```shell genaiscript mcp --startup load-resources ``` -------------------------------- ### Configure Prompt Variable Inclusion Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/getting-started/index.mdx Shows how to configure the `def` function with flags like `lineNumbers` and `maxTokens` to control how content is included in the prompt variable. This allows for fine-tuning the data passed to the LLM. ```javascript def("FILE", ..., { lineNumbers: true, maxTokens: 100 }) ``` -------------------------------- ### Declare Prompt Variables with def Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/getting-started/index.mdx Demonstrates declaring a prompt variable 'FILE' by reading the content of a specified text file using `workspace.readText`. This variable can then be referenced within the LLM prompt. Dependencies include the `genai` library and `workspace` object. ```javascript def("FILE", workspace.readText("some/relative/markdown.txt")) $`Summarize FILE in one sentence.` ``` -------------------------------- ### Running a Startup Script Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/webapi.mdx Specify a script to run automatically after the Web API server starts, useful for setup tasks. ```APIDOC ## Running a Startup Script ### Description Executes a specified GenAIScript after the Web API server has successfully started. This is useful for tasks like loading resources or performing initial setup. ### Command Example ```sh genaiscript webapi --startup load-resources ``` ### Parameter - `--startup `: The identifier of the script to execute upon server startup. ``` -------------------------------- ### Summarize File with agent_fs in GenAIScript (.mjs) Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/getting-started/index.mdx This script uses the 'agent_fs' tool to read a file, summarize its content using an LLM, and save the summary to a new file. It requires the 'agent_fs' tool to be available. The input is the file path 'src/rag/markdown.md', and the output is saved to 'markdown.md.txt'. ```javascript script({ tools: "agent_fs" }) $` - read the file src/rag/markdown.md - summarize it in one sentence. - save output to file markdown.md.txt (override existing) ` ``` -------------------------------- ### Install GenAIScript CLI Globally (npm) Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/cli/index.mdx Installs the GenAIScript CLI globally on your system using npm. This makes the `genaiscript` command available from any directory. Ensure you have Node.js and npm installed. ```shell npm install -g genaiscript ``` -------------------------------- ### Use File Parameters with env.files Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/getting-started/index.mdx Illustrates how to use the `env.files` variable to make scripts more reusable by processing files passed to the script, instead of hard-coding file paths. This is useful for batch processing. ```javascript // summarize all files in the env.files array def("FILE", env.files) $`Summarize FILE in one sentence.` ``` -------------------------------- ### Start LocalAI Docker Container Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/configuration/localai.mdx Commands to run, start, and monitor the LocalAI Docker container. This setup allows for local inferencing using open-source models on CPUs, providing an OpenAI API-compatible endpoint. ```shell docker run -p 8080:8080 --name local-ai -ti localai/localai:latest-aio-cpu docker start local-ai docker stats echo "LocalAI is running at http://127.0.0.1:8080" ``` -------------------------------- ### Execution and Installation Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/glossary.md Information on running GenAIScript without installation via npx and using the Node.js run API. ```APIDOC ## Execution and Installation ### Description Provides details on running GenAIScript without a local installation using `npx` and leveraging the Node.js run API for isolated execution. ### Features * **No Installation (npx)**: Run GenAIScript CLI with npx without prior installation. * **Node.JS run API**: API to run GenAIScript in isolated Node worker threads to prevent scope pollution. ``` -------------------------------- ### Start Ollama Serve Command Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/configuration/ollama.mdx Command to start the Ollama local server. This is a prerequisite for using Ollama models with GenAIScript locally. ```shell ollama serve ``` -------------------------------- ### Build Docker Image for GenAIScript Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/cli/serve.md Creates a Docker image named `genaiscript` based on `node:alpine`. It installs Git and globally installs `genaiscript`. This image can then be used to run the GenAIScript server in a containerized environment. ```sh docker build -t genaiscript -< FTP } cloud { [Example 1] } database "MySql" { folder "This is my folder" { [Folder 3] } frame "Foo" { [Frame 4] } } [Another Component] --> [Example 1] [Example 1] --> [Folder 3] [Folder 3] --> [Frame 4] @enduml ``` -------------------------------- ### Run GenAIScript CLI without Installation (npx) Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/cli/index.mdx Executes the GenAIScript CLI using npx, which downloads and runs the package on demand. This is useful for quick executions or in CI environments without a prior global or local installation. The `--yes` flag skips confirmation prompts. ```shell npx genaiscript ... npx --yes genaiscript ... ``` -------------------------------- ### Run with Custom Build and Format Commands Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/samples/cmt.mdx Example of running the GenAIScript commenter with custom 'build' and 'format' commands passed as variables. ```shell genaiscript run cmt --vars "build=npm run build" "format=npm run format" ``` -------------------------------- ### Prime LLM Response with Assistant Message (JavaScript) Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/scripts/response-priming.md This example demonstrates how to prime an LLM's response by providing an initial 'assistant' message in a GenAIScript. This is useful for steering the LLM towards a specific syntax or format, such as starting a JSON array. The code first defines a prompt for the LLM and then uses the `assistant()` function to provide the beginning of the desired output. ```javascript $`List 5 colors. Answer with a JSON array. Do not emit the enclosing markdown.` // help the LLM by starting the JSON array syntax // in the assistant response assistant(`[`) ``` -------------------------------- ### Example Markdown File Content Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/scripts/notebook.mdx An example of a Markdown file that could be included in a GenAIScript notebook. It contains front matter with metadata like title, description, and keywords. ```markdown --- title: What is Markdown? - Understanding Markdown Syntax description: Learn about Markdown, a lightweight markup language for formatting plain text, its syntax, and how it differs from WYSIWYG editors. keywords: Markdown, markup language, formatting, plain text, syntax sidebar: mydoc_sidebar --- What is Markdown? Markdown is a lightweight markup language that you can use to add formatting elements to plaintext text documents. Created by John Gruber in 2004, Markdown is now one of the world’s most popular markup languages. Using Markdown is different than using a WYSIWYG editor. In an application like Microsoft Word, you click buttons to format words and phrases, and the changes are visible immediately. Markdown isn’t like that. When you create a Markdown-formatted file, you add Markdown syntax to the text to indicate which words and phrases should look different. For example, to denote a heading, you add a number sign before it (e.g., # Heading One). Or to make a phrase bold, you add two asterisks before and after it (e.g., **this text is bold**). It may take a while to get used to seeing Markdown syntax in your text, especially if you’re accustomed to WYSIWYG applications. The screenshot below shows a Markdown file displayed in the Visual Studio Code text editor.... ``` -------------------------------- ### Run GenAIScript Commenter Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/samples/cmt.mdx Command to execute the GenAIScript commenter. Requires the GenAIScript CLI to be installed. ```shell genaiscript run cmt ``` -------------------------------- ### Start GenAIScript Execution (JavaScript) Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/blog/drafts/-state-management-in-genaiscript-persisting-and-sharing-data-across-script-runs-.md Initiates the interactive execution of a GenAIScript program by calling the main function. This is the entry point for the script's logic. ```javascript // Start the script main(); ``` -------------------------------- ### Start MCP Server - JavaScript Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/scripts/mcp-clients.mdx Starts an MCP server using the host.mcpServer function. Requires an identifier for the server, the command to execute, and its arguments. The server automatically stops when the prompt finishes. ```javascript const fs = await host.mcpServer({ id: "filesystem", command: "npx", args: ["-y", "@modelcontextprotocol/server-filesystem", path.resolve(".")], }) ``` -------------------------------- ### Example Markdown File Content Source: https://github.com/microsoft/genaiscript/blob/main/packages/vscode/tutorial.md This markdown snippet shows the structure and content of a sample markdown file, including front matter with metadata like title, description, and keywords. This content can be loaded via `env.files`. ```markdown --- title: What is Markdown? - Understanding Markdown Syntax description: Learn about Markdown, a lightweight markup language for formatting plain text, its syntax, and how it differs from WYSIWYG editors. keywords: Markdown, markup language, formatting, plain text, syntax sidebar: mydoc_sidebar --- What is Markdown? Markdown is a lightweight markup language that you can use to add formatting elements to plaintext text documents. Created by John Gruber in 2004, Markdown is now one of the world’s most popular markup languages. Using Markdown is different than using a WYSIWYG editor. In an application like Microsoft Word, you click buttons to format words and phrases, and the changes are visible immediately. Markdown isn’t like that. When you create a Markdown-formatted file, you add Markdown syntax to the text to indicate which words and phrases should look different. For example, to denote a heading, you add a number sign before it (e.g., # Heading One). Or to make a phrase bold, you add two asterisks before and after it (e.g., **this text is bold**). It may take a while to get used to seeing Markdown syntax in your text, especially if you’re accustomed to WYSIWYG applications. The screenshot below shows a Markdown file displayed in the Visual Studio Code text editor.... ``` -------------------------------- ### Start Local Web Server with GenAIScript Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/cli/serve.md Launches the GenAIScript local web server from the workspace root. This server is used for running the playground or Visual Studio Code locally. No specific inputs or outputs are detailed, but it serves as the entry point for local development. ```bash npx genaiscript serve ``` -------------------------------- ### GenAIScript Output Log Example Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/samples/prr.md An example of the output generated by a GenAIScript run. It displays model information, message previews, token usage, and execution time. This log helps in understanding the script's performance and identifying potential issues during development. ```text ┌─💬 github:gpt-4.1 ✉ 2 ~↑1.4kt ┌─📙 system │## Safety: Jailbreak │... (85 lines) │- **Do NOT use function names starting with 'functions.'. │- **Do NOT respond with multi_tool_use`. ┌─👤 user │ │--- /dev/null |+++ .github/workflows/genai-pr-review.yml |@@ -0,0 +1,22 @@ |--- /dev/null |[1] +++ genaisrc/.gitignore |... (3 lines) |Report errors in using the annotation format. |- Use best practices of the programming language of each file. |- If available, provide a URL to the official documentation for the best practice. do NOT invent URLs. |- Analyze ALL the code. Do not be lazy. This is IMPORTANT. |- Use tools to read the entire file content to get more context |- Do not report warnings, only errors. ::error file=.github/workflows/genai-pr-review.yml,line=1,endLine=22,code=missing_workflow_content::The workflow file is empty or missing mandatory workflow keys like `name`, `on`, and `jobs`. Every GitHub Actions workflow file must specify at least these top-level keys to define triggers and jobs. See official docs: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions └─🏁 github:gpt-4.1 ✉ 2 3446ms ⇅ 1.9kt ↑1.6kt ↓223t 0.505¢ genaiscript: success > 3446ms ↑1.6kt ↓223t 538.62t/s 0.505¢ github:gpt-4.1-2025-04-14> 3446ms ↑1.6kt ↓223t 538.62t/s 0.505¢ trace: ... output: ... ``` -------------------------------- ### Start a Container with a Custom Image Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/scripts/container.md Starts a new Docker container using a specified Docker image. This allows for different runtimes or pre-configured environments. For example, 'node:20' specifies the Node.js version 20 image. ```javascript const container = await host.container({ image: "node:20" }) ``` -------------------------------- ### Configure GenAIScript CLI Proxy Settings Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/cli/index.mdx Sets environment variables to configure HTTP/HTTPS proxy for the GenAIScript CLI, essential for enterprise environments. It also shows how to use `npm install --omit=optional` to gracefully handle optional packages that may not support proxy installations. ```shell HTTP_PROXY=http://proxy.acme.com:3128 HTTPS_PROXY=http://proxy.acme.com:3128 npm install --omit=optional ``` -------------------------------- ### Theme Configuration (YAML) Source: https://github.com/microsoft/genaiscript/blob/main/slides/reference.md Demonstrates how to switch between different themes in Slidev by modifying the `theme` property in the frontmatter. This example shows switching between 'default' and 'seriph' themes. ```yaml --- theme: default --- ``` ```yaml --- theme: seriph --- ``` -------------------------------- ### Run Code in Docker Containers with GenAIScript Source: https://github.com/microsoft/genaiscript/blob/main/README.md Executes code within a Docker container. This example shows how to start a Python container and execute a command to check the Python version. ```javascript const c = await host.container({ image: "python:alpine" }) const res = await c.exec("python --version") ``` -------------------------------- ### YouTube Transcript Extraction with MCP - JavaScript Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/scripts/mcp-clients.mdx An example of using the mcp/youtube-transcript server to extract the transcript of a YouTube video. This involves starting the Docker-based MCP server and calling its 'get_transcript' tool with a video URL. ```javascript const yt = await host.mcpServer({ id: "youtube_transcript", command: "docker", args: ["run", "-i", "--rm", "mcp/youtube-transcript"], }) const url = "https://youtu.be/ENunZe--7j0" const transcript = await yt.callTool("get_transcript", { url }) console.log(`transcript: ${transcript.text}`) ``` -------------------------------- ### Get Selection from User List (JavaScript) Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/scripts/user-input.mdx Presents the user with a list of options and waits for them to select one, returning the chosen string. Essential for guided user choices. Uses the 'host' object to display the selection prompt. ```javascript const choice = await host.select("Choose an option:", [ "Option 1", "Option 2", "Option 3", ]) ``` -------------------------------- ### Translate Audio to English Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/scripts/transcription.mdx This example shows how to simultaneously transcribe and translate the audio content to English using the `translate: true` flag. This feature is supported by specific models and simplifies the process of getting English translations from non-English audio. ```javascript const { srt } = await transcribe("...", { translate: true }) ``` -------------------------------- ### Define LLM Tools with GenAIScript Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/getting-started/tutorial.md This example shows how to register JavaScript functions as tools for the LLM. The `defTool` function allows the LLM to call these tools, passing arguments and receiving results, enabling complex task execution. ```javascript // requires openai, azure openai or github models defTool( "fetch", "Download text from a URL", { url: "https://..." }, ({ url }) => host.fetchText(url) ) $`Summarize https://raw.githubusercontent.com/microsoft/genaiscript/main/README.md in 1 sentence.` ``` -------------------------------- ### Interact with Git Repository Source: https://context7.com/microsoft/genaiscript/llms.txt Provides examples for interacting with a local Git repository. This includes getting the diff of staged changes, retrieving commit logs, checking the current branch, and inspecting the repository's status. These operations are essential for version control automation. ```javascript // Get diff const diff = await git.diff({ staged: true, askStageOnEmpty: true }) def("GIT_DIFF", diff, { maxTokens: 20000 }) $`Generate a concise commit message for these changes. - Follow conventional commit format - Focus on the 'why' not the 'what'` // Get commit log const log = await git.log({ count: 10 }) for (const commit of log) { console.log(`${commit.sha.slice(0, 7)} - ${commit.message}`) } // Get current branch const branch = await git.branch() console.log(`Current branch: ${branch}`) // Get repository status const status = await git.status() console.log(`Modified files: ${status.modified.length}`) ``` -------------------------------- ### Example Invocation of Main Script (JavaScript) Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/blog/drafts/writing-modular-genaiscript-scripts-techniques-for-script-reuse-composition-and-parameterization.md This commented-out JavaScript code demonstrates how to invoke the main script function. It shows how to pass specific parameters such as the file path, summary length, and maximum number of keywords, which is useful for CLI execution or testing purposes. ```javascript // Example invocation (for CLI or test) // main({ filePath: "input.txt", summaryLength: "long", maxKeywords: 10 }); ``` -------------------------------- ### Transform function documentation using LLM and AST Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/blog/ast-grep-and-transform.mdx This example shows how to use a GenAI script to transform code. It first uses `ast-grep` to get the text of a located node (e.g., a function) and then uses an LLM prompt to generate updated documentation, which is then applied to the AST. ```typescript $"Update the documentation of the function 'fn' to reflect the new behavior of the function." fence(node.text()) ``` -------------------------------- ### Run GenAIScript MakeItBetter Command Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/blog/makeitbetter.mdx Demonstrates the command-line interface command to execute the GenAIScript's code improvement feature. This is the primary method for initiating the script from the terminal. ```bash genaiscript run makeitbetter ``` -------------------------------- ### Execute Nested LLM Tasks (Sub-prompts) Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/getting-started/tutorial.md This snippet illustrates how to run nested LLM executions using `runPrompt`. It processes each file individually by summarizing it and then summarizes all the individual summaries, demonstrating a powerful way to handle complex summarization tasks. ```javascript // summarize each files individually for (const file of env.files) { const { text } = await runPrompt((_) => { _.def("FILE", file) _.$`Summarize the FILE.` }) def("FILE", { ...file, content: text }) } // summarize all summaries $`Summarize FILE.` ``` -------------------------------- ### LLM Composition with GenAIScript Source: https://github.com/microsoft/genaiscript/blob/main/README.md Builds LLM prompts dynamically using the 'runPrompt' function. This example iterates through files, summarizes each file using an LLM, and then summarizes all the summaries. ```javascript for (const file of env.files) { const { text } = await runPrompt((_) => { _.def("FILE", file) _.$`Summarize the FILE.` }) def("SUMMARY", text) } $`Summarize all the summaries.` ``` -------------------------------- ### GenAIScript Math Tool Example Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/scripts/tools.mdx An example GenAIScript file ('math-agent.genai.mjs') that demonstrates the use of a math tool to evaluate mathematical expressions. ```js import "@genaiscript/core" await $`Evaluate the expression ${math.evaluate('1 + 2 * 3')}.` ``` -------------------------------- ### GenAIScript Weather Tool Example Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/scripts/tools.mdx An example GenAIScript file ('weather.genai.js') that utilizes a predefined weather tool to fetch weather information for Brussels. ```js import "@genaiscript/core" await $`Get the weather for Brussels.` ``` -------------------------------- ### Initialize and Process Files for RAG with GenAIScript Source: https://github.com/microsoft/genaiscript/blob/main/packages/sample/genaisrc/vectorstore.genai.txt Initializes the GenAIScript environment and processes local files to create documents for a vector store. It handles file filtering and asynchronous document creation. Dependencies include the 'vectorstore' module. ```typescript import { init, createDocument, search } from "vectorstore" script({ files: "src/rag/*", tests: {}, }) await init((args) => process.stderr.write(".")) const docs = await Promise.all( env.files .filter(({ content }) => content) .map((file) => createDocument(file.content, file)) ) const res = await search( docs, await createDocument("what is markdown?"), 3, "hnsw-wasm" ) def( "FILE", res.map((r) => r.doc.metadata) ) $`Summarize FILE in one short sentence.` ``` -------------------------------- ### Configuring GenAIScript with Metadata Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/blog/gentle-introduction-to-genaiscript.mdx Demonstrates how to configure a GenAIScript with metadata like title, description, model, and temperature. This script also incorporates context variables for prompt generation, specifying an 'openai:gpt-4o' model. ```javascript script({ title: "Technical proofreading", description: "Reviews the text as a tech writer.", model: "openai:gpt-4o", temperature: 0.1, }) def("FILES", env.files) $`You are an expert technical writer and proofreader. Review the documents in FILES and report the 2 most important issues.` ``` -------------------------------- ### Install Azure SDK Packages Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/guides/images-in-azure-blob-storage.mdx Installs the necessary Azure SDK packages for interacting with Blob Storage and authenticating with Azure. ```sh npm install -D @azure/storage-blob @azure/identity ``` -------------------------------- ### Install Agentic Weather Tool Dependencies Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/guides/agentic-tools.mdx Installs the core agentic library and the weather tool package. This is required before you can utilize the weather tool. ```sh npm install @agentic/core @agentic/weather ``` -------------------------------- ### CLI Options and System Integration Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/glossary.md Details on CLI options like 'suffix' and the system behavior integration. ```APIDOC ## CLI Options and System Integration ### Description Details specific command-line options and the overall system integration framework. ### Features * **suffix option**: CLI `convert` command option to set a suffix for output files, handling markdown fences. * **System behavior**: Integration framework for code execution, foundation model/LLM invocations, and parsing results. ``` -------------------------------- ### Install genaiscript Package Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/blog/node-api.mdx Installs the genaiscript package as a development dependency using a package manager. This is a prerequisite for using the GenAIScript Node.js API. ```bash ``` -------------------------------- ### Install Agentic Calculator Tool Dependencies Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/guides/agentic-tools.mdx Installs the core agentic library and the calculator tool package. This is a prerequisite for using the calculator tool in your script. ```sh npm install @agentic/core @agentic/calculator ``` -------------------------------- ### TypeScript Greeter Class Instantiation Source: https://github.com/microsoft/genaiscript/blob/main/packages/sample/src/greeter.ts.slides.md Demonstrates how to create an instance of the 'Greeter' TypeScript class. It shows passing an initial message to the constructor and then calling the 'greet' method on the created object to retrieve the formatted greeting. ```typescript let greeter = new Greeter("world"); console.log(greeter.greet()); ``` -------------------------------- ### Mermaid Diagram Example Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/scripts/diagrams.md This is a basic example of a Mermaid diagram generated using graph LR syntax. It defines nodes and connections to represent a merge point. ```mermaid graph LR A[Master] --> B((Merge Point)) C[Feature Branch] --> B ``` -------------------------------- ### Run GenAIScript with o1-mini Model from GitHub Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/configuration/github.mdx Example of invoking the 'o1-mini' model available through the GitHub Models provider. Note that this model currently does not support streaming or system prompts, which GenAIScript handles internally. ```javascript script({ model: "github:openai/o1-mini", }) ``` -------------------------------- ### Install ffmpeg on Linux Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/scripts/videos.mdx Installs the ffmpeg package on Debian-based Linux distributions using apt-get. Ensures that ffmpeg and its associated tools are available in the system's PATH. ```shell sudo apt-get update && sudo apt-get install ffmpeg ``` -------------------------------- ### GenAIScript .env File Resolution Command Line Example Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/configuration-files.mdx This shell command demonstrates how to specify custom .env files for GenAIScript using the `--env` flag. Multiple environment files can be provided, and they will be loaded in the order specified. ```shell genaiscript run ... --env ./.env.debug --env ~/.env.dev ``` -------------------------------- ### Install SQL Language Package for ast-grep Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/reference/scripts/ast-grep.mdx Installs the additional npm package required to enable SQL language support for ast-grep. This command uses npm for package management. ```shell npm install -D @ast-grep/lang-sql ``` -------------------------------- ### Configure GitHub Actions for GenAIScript (Secrets and Output) Source: https://github.com/microsoft/genaiscript/blob/main/docs/src/content/docs/getting-started/automating-scripts.mdx Set up GitHub Actions to run GenAIScripts by passing necessary environment variables and secrets, such as API keys. Use the `--out ` flag to direct script results to a specific directory, which can then be uploaded as an artifact. This ensures secure access to LLM services and facilitates artifact management. ```yaml - run: npx --yes genaiscript run