← Back to recipes

Ask the local LLM

Send a prompt to the configured local LLM and optionally summarize the active page.

MCP and AI Intermediate JavaScript ask_the_llm.js

Prerequisites

  • An LLM provider configured in Settings > AI
  • A local model name available to the configured provider

Expected result

Guida logs the model response, and summarizes page text if a browser tab has content loaded.

Source example

ask_the_llm.js

Use the local LLM API when a script needs text generation, classification, extraction, or summarization.

// Ask the LLM — Use a local AI model for analysis
//
// This script sends a prompt to the configured LLM
// and logs the response.
// Requires an LLM provider configured in Settings > AI.
g.log("Sending prompt to LLM...");
// Simple text generation (specify your model name)
const model = "llama3"; // Change to your installed model
const response = await g.llm.promptLocalLlm(
model,
"Explain what a web scraper does in two sentences."
);
g.log("LLM response:");
g.log(response);
// You can also combine LLM with page content
// (requires a browser tab with a loaded page)
const tabs = g.tabs.getTabs();
if (tabs && tabs.length > 0) {
const pageText = await g.dom.extractContent("body");
if (pageText && pageText.length > 0) {
// Trim to first 500 chars to stay within context limits
const snippet = pageText.substring(0, 500);
const summary = await g.llm.promptLocalLlm(
model,
"Summarize this web page in one paragraph:\n\n" + snippet
);
g.log("Page summary: " + summary);
} else {
g.log("Page has no text content to summarize.");
}
}