Skip to content

Automation

2 posts with the tag “Automation”

Automatic Web Page Content Analysis

In this blog post, we’ll dive into a practical example showcasing how to leverage GenAIScript for automatic web page content analysis. GenAIScript uses the playwright browser automation library which allows to load, interact and inspect web pages.

Step-by-Step Explanation of the Code

The following snippet provides a concise and effective way to analyze a web page’s content using GenAIScript:

const page = await host.browse("https://bing.com")
const screenshot = await page.screenshot()
defImages(screenshot, { maxWidth: 800 })
const text = parsers.HTMLtoMarkdown(await page.content())
def("PAGE_TEXT", text)
$`Analyze the content of the page and provide insights.`

Let’s break down what each line of this script does:

1. Navigating to a Web Page

const page = await host.browse("https://example.com")

This line automatically navigates to the specified URL (https://example.com). The host.browse function is a powerful feature of GenAIScript that initializes a browser session and returns a page object for further interactions.

2. Taking a Screenshot

const screenshot = await page.screenshot()

Here, the script captures a screenshot of the current view of the page. This is particularly useful for archiving or visual analysis.

3. Defining Images for Analysis

defImages(screenshot, { maxWidth: 800 })

After capturing the screenshot, this line registers the image for further analysis. defImages is a function that makes the screenshot available to subsequent analytical or AI-driven functions in the script.

4. Extracting Text Content

const text = parsers.HTMLtoMarkdown(await page.content())

This command extracts all text content from the page, which can be invaluable for content audits or textual analysis.

5. Storing Text for Further Use

def("PAGE_TEXT", text)

The extracted text is then stored under the identifier PAGE_TEXT, allowing it to be referenced in later parts of the script or for documentation purposes.

6. Analyzing the Content

$`Analyze the content of the page and provide insights.`

Finally, this line represents a call to an AI or script-defined function that analyzes the captured content and provides insights. This is where the real power of automation and AI integration into GenAIScript shines, enabling detailed analysis without manual intervention.

Conclusion

With a simple yet powerful script like the one discussed, GenAIScript makes it feasible to automate the process of web page content analysis. Whether you’re conducting competitive analysis, performing content audits, or simply archiving web pages, GenAIScript offers a scalable and efficient solution.

Creating Release Notes with GenAI

Automating Your Release Notes with GenAI

Bringing a new version of a product into the world is always exciting! But alongside the thrill comes the duty of informing users about what’s changed. That’s where generating crisp, engaging release notes comes into play. ✨

Today, we’re going to explore a script that automates the creation of release notes for GenAI. The script is part of the GenAIScript ecosystem, which harnesses the power of AI to bring efficiency to software development processes. 🚀

If you want to dive straight into the script, it’s available on GitHub right here.

This blog post was co-authored with a script.

Breaking Down the Script

The script is a .genai.mjs file, meaning it’s a JavaScript file designed to be run with the GenAIScript CLI. The code within orchestrates the creation of release notes by leveraging Git commands and GenAI’s capabilities.

Let’s walk through the script, step by step:

Step 1: Initializing the Script

script({ system: ["system"], temperature: 0.5, model: "openai:gpt-4-turbo" })

The script starts by initializing with a script function. We’re setting it up to access system commands and specifying the AI model to use. The temperature controls the creativity of the AI, with 0.5 being a balanced choice.

Step 2: Setting the Product Name

const product = env.vars.product || "GenAIScript"

Here, we’re using an environment variable to set the product name, defaulting to “GenAIScript” if it’s not provided.

Step 3: Finding the Previous Tag

const pkg = await workspace.readJSON("package.json")
const { version } = pkg
const { stdout: tag } = await host.exec("git", [
"describe",
"--tags",
"--abbrev=0",
"HEAD^",
])

We are reading the current version from package.json and using Git to find the previous release tag in the repository.

Step 4: Gathering Commits

const { stdout: commits } = await host.exec("git", [
"log",
"--grep='skip ci'",
"--invert-grep",
"--no-merges",
`HEAD...${tag}`,
])

This block runs a Git command to retrieve the list of commits that will be included in the release notes, excluding any with ‘skip ci’ in the message.

Step 5: Obtaining the Diff

const { stdout: diff } = await host.exec("git", [
"diff",
`${tag}..HEAD`,
"--no-merges",
"--",
":!**/package.json",
":!**/genaiscript.d.ts",
":!**/jsconfig.json",
":!docs/**",
":!.github/*",
":!.vscode/*",
":!*yarn.lock",
":!*THIRD_PARTY_NOTICES.md",
])

Next, we get the diff of changes since the last release, excluding certain files and directories that aren’t relevant to the user-facing release notes.

Step 6: Defining Placeholders

const commitsName = def("COMMITS", commits, { maxTokens: 4000 })
const diffName = def("DIFF", diff, { maxTokens: 20000 })

We define two placeholders, COMMITS and DIFF, which will be used to reference the commits and diff within the prompt.

Step 7: Writing the Prompt

$`
You are an expert software developer and release manager.
## Task
Generate a clear, exciting, relevant, useful release notes
for the upcoming release ${version} of ${product} on GitHub.
- The commits in the release are in ${commitsName}.
- The diff of the changes are in ${diffName}.
## Guidelines
- only include the most important changes. All changes must be in the commits.
- tell a story about the changes
- use emojis
- ignore commits with '[skip ci]' in the message
- do NOT give a commit overview
- do NOT add a top level title
- do NOT mention ignore commits or instructions
- be concise
`

Finally, the script ends with a prompt that instructs GenAI to generate the release notes. It details the task, guidelines for what to include, and the style to adhere to.

How to Run the Script with Genaiscript CLI

Once you’ve crafted your script, running it is a breeze with the Genaiscript CLI. If you haven’t installed the CLI yet, you can find the instructions here.

To execute the script, navigate to your project’s root directory in the terminal and run:

Terminal window
genaiscript run git-release-notes

Remember, we use the script filename without the .genai.mjs extension when invoking it with the CLI.

And that’s it! The GenAIScript CLI will take care of the rest, combining the power of AI with your code to generate those sleek release notes for your project’s next big launch. 🌟