DEV Community

Cover image for Unlocking the Power of Prompts - A Gentle Introduction to GenAIScript 🚀
Peli de Halleux
Peli de Halleux

Posted on • Edited on • Originally published at microsoft.github.io

2 1

Unlocking the Power of Prompts - A Gentle Introduction to GenAIScript 🚀

Ever wondered how to leverage the power of AI and Large Language Models (LLMs) in your projects? Look no further!
Hello GenAIScript,
a tool designed to simplify the creation of prompts and interactions with LLMs. Let's dive in! 🌊

What is GenAIScript?

Image description

GenAIScript uses a stylized version of JavaScript to generate prompts, which are then sent to an LLM.
Scripts are stored as files (genaisrc/*.genai.mjs), executed to produce the prompt text and structured results (files, diagnostics) are extracted automatically. It runs as a VSCode extension or as a CLI.

Getting Started

Here's a simple example to get you started. Create a file named poem.genai.mjs in the genaisrc folder and add the following code:

$`Write a one sentence poem.`
Enter fullscreen mode Exit fullscreen mode

When executed, this script will generate the following prompt:

👤 User

Write a one sentence poem.
Enter fullscreen mode Exit fullscreen mode

🤖 Assistant

Roses bloom, hearts swoon, under the silver moon.
Enter fullscreen mode Exit fullscreen mode

Adding Context

GenAIScript can also use context variables, allowing you to interact with files or other data sources. Let's see an example where we define a context variable using env.files:

def("FILES", env.files)
$`You are an expert technical writer and proofreader.
Review the documents in FILES and report the 2 most important issues.`
Enter fullscreen mode Exit fullscreen mode

Execute this script to see the generated user message and the assistant's response. The context variable FILES will contain the list of files in the environment.

👤 User

FILES: 
file="src/samples/markdown.md"
What is Markdown?
Markdown is a lightweight markup language that...

You are an expert technical writer and proofreader.
Review the documents in FILES and report the 2 most important issues.
Enter fullscreen mode Exit fullscreen mode

🤖 Assistant

I reviewed the document in "src/samples/markdown.md" 
and found the following two important issues:

1. **Missing Consistency in Heading Styles**: ...
Enter fullscreen mode Exit fullscreen mode

Metadata and Script Configuration

You can add metadata to your script using the script function. This helps in organizing and configuring the script, including specifying the model and other parameters. GenAIScript supports various LLM providers, such as OpenAI, Azure OpenAI,
GitHub Models, Ollama and more.

script({
    title: "Technical proofreading",
    description: "Reviews the text as a tech writer.",
    model: "openai:gpt-3.5-turbo",
    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.`
Enter fullscreen mode Exit fullscreen mode

Next Steps

There you have it! A gentle introduction to GenAIScript to get you started on your prompt engineering journey. Happy scripting! 💻✨

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS Security LIVE!

Hosted by security experts, AWS Security LIVE! showcases AWS Partners tackling real-world security challenges. Join live and get your security questions answered.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️