DEV Community

Cover image for Building an AI Fairy Tale Generator with JavaScript, PowerShell, .NET, and Local Ollama (AdvantageBuilder Demo)
Advantage Builder
Advantage Builder

Posted on

Building an AI Fairy Tale Generator with JavaScript, PowerShell, .NET, and Local Ollama (AdvantageBuilder Demo)

Recently I published a demo showing how AdvantageBuilder can orchestrate multiple runtimes — JavaScript V8, PowerShell, .NET, and local AI (Ollama) — to generate and narrate fairy tales on demand.

🎬 Watch the full demo:

https://youtu.be/ah8jf_WwkLE

This article breaks down how the workflow works and includes real code examples you can use inside AdvantageBuilder.

⭐ Why This Demo Is Interesting
Most AI demos rely on cloud APIs. This one runs entirely locally:

JavaScript V8 macro

PowerShell helper

Ollama model (llama3.1:8b-instruct-q4_K_M)

.NET System.Speech voice narration

All orchestrated inside AdvantageBuilder

It’s a clean example of multi‑runtime automation.

⭐ Part 1 — JavaScript V8 Macro (Main Workflow)

The main macro is written in JavaScript V8. It calls two helpers:

AI Ollama Helper → generates the fairy tale

InvokeSpeech → narrates the fairy tale aloud

Here’s a simplified version of the JS macro:

[!JAVASCRIPTV8]

// --- Step 1: Generate a fairy tale using the AI helper ---
let aiParams = {};
aiParams.Model = "llama3.1:8b-instruct-q4_K_M";
aiParams.Prompt = "Write a short fairy tale suitable for narration. Keep it under 200 words.";

let fairyTale = callMacro(false, 'AI Ollama Helper', 'Macro Main Helpers', aiParams);

// --- Step 2: Feed the fairy tale to the voice helper ---
let voiceParams = {};
voiceParams.Voice = "Microsoft Zira Desktop";   // or David
voiceParams.TextToSpeech = fairyTale;

callMacro(false, 'InvokeSpeech', 'Macro Main Helpers', voiceParams);

[!/JAVASCRIPTV8]

Enter fullscreen mode Exit fullscreen mode

AdvantageBuilder automatically handles:

  • argument passing
  • runtime switching
  • JSON serialization
  • macro invocation

So JavaScript can call PowerShell seamlessly.

⭐ Part 2 — AI Ollama Helper (PowerShell)

This helper sends a prompt to Ollama’s local REST API and returns the generated text.

[!POWERSHELLSCRIPT]

# $_args.Model
# $_args.Prompt

$model = "llama3.1:8b-instruct-q4_K_M"
$prompt = ""

if($_args -ne $null){

    $model = $_args.Model
    $prompt = $_args.Prompt
}

$body = @{
    model  = $model
    prompt = $prompt
    stream = $false
} | ConvertTo-Json -Depth 5

$response = Invoke-RestMethod -Uri "http://localhost:11434/api/generate" `
    -Method POST `
    -Body $body `
    -ContentType "application/json"

$response.response

[!/POWERSHELLSCRIPT]
Enter fullscreen mode Exit fullscreen mode

This is all you need to integrate local AI into AdvantageBuilder.

⭐ Part 3 — InvokeSpeech Helper (.NET + PowerShell)

This helper uses System.Speech to speak the generated fairy tale aloud.

[!POWERSHELLSCRIPT]

Add-Type -AssemblyName System.Speech

# Create synthesizer
$synth = New-Object System.Speech.Synthesis.SpeechSynthesizer

$synth.SelectVoice($_args.Voice)
$synth.Speak($_args.TextToSpeech)

[!/POWERSHELLSCRIPT]
Enter fullscreen mode Exit fullscreen mode

AdvantageBuilder’s WinFormsHelper can also build a UI for selecting voices.

⭐ Why AdvantageBuilder Makes This Easy

AdvantageBuilder is designed for multi‑runtime orchestration:

  • JavaScript V8
  • PowerShell
  • .NET
  • COM
  • Local AI engines
  • UI helpers
  • Database helpers

In this workflow:

  • JavaScript calls PowerShell
  • PowerShell calls Ollama
  • Ollama returns text
  • JavaScript calls PowerShell again
  • PowerShell calls .NET speech synthesis

All inside one macro.

This is the kind of automation that normally requires multiple tools, but AdvantageBuilder handles it natively.

⭐ What You Can Build Next

This architecture can power:

  • AI‑generated bedtime stories
  • Voice‑driven assistants
  • Local AI chatbots
  • Desktop automation tools
  • Data analysis pipelines
  • Custom UI apps
  • AI‑enhanced workflows

If you want to explore local AI without cloud dependencies, this setup is a great starting point.

🎬 Watch the Full Demo

See the entire workflow — including the helpers, narration, and macro execution — in the video:

👉 https://youtu.be/ah8jf_WwkLE

Top comments (0)