← Retour aux recettes

Demander au LLM local

Envoyer un prompt au LLM local configuré et éventuellement résumer la page active.

MCP et IA Intermédiaire JavaScript ask_the_llm.js

Prérequis

  • Un fournisseur LLM configuré dans Settings > AI
  • Un nom de modèle local disponible pour le fournisseur configuré

Résultat attendu

Guida journalise la réponse du modèle et résume le texte de la page si un onglet navigateur contient une page chargée.

Documentation associée

Configuration LLMAPI IA, HTTP et outils

Exemple source

ask_the_llm.js

Utilisez l’API LLM locale lorsqu’un script a besoin de génération de texte, classification, extraction ou résumé.

// 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.");
}
}