Recherche et récupération
Supposons que nous souhaitions planifier un voyage de week-end en utilisant un GenAIScript qui nous aidera à organiser ce voyage en utilisant la recherche web pour découvrir des activités à faire et la météo prévue.
-
Utilisez la commande
> GenAIScript : Créer un nouveau script...
dans la palette de commandes pour créer un nouveau script. -
Commencez le script en définissant le modèle et le titre :
script({title: "plan-weekend",description: "Given details about my goals, help plan my weekend",model: "openai:gpt-4o",}) -
Utilisez la fonction
webSearch
pour chercher des informations sur la destination. Si vous n’en avez pas, vous pouvez rechercher les pages web manuellement et utiliser les URL directement dans l’appel à la fonctionhost.fetchText
.const parkinfo = await retrieval.webSearch("mt rainier things to do") -
webSearch
renvoie une liste d’URL. UtilisezfetchText
pour récupérer le contenu de la 1ère URL.const parktext = await host.fetchText(parkinfo.webPages[0]) -
host.fetchText
retourne beaucoup de balises HTML de formatage, etc. UtilisezrunPrompt
pour appeler le LLM afin de nettoyer ces balises et ne garder que le texte.const cleanInfo = await runPrompt(_ => {// use def, $ and other helpers_.def("INFO", parktext.text)_.$`You are an expert in web content.Extract out of the file INFO, which is HTML with lots of CSS and HTML tags,the important information that a human would want to know.`}) -
Répétez pour obtenir les dernières informations météo sur votre destination.
const weather = await retrieval.webSearch("mt rainier weather") -
Remplacez le texte
"TELL THE LLM WHAT TO DO..."
par le type de vacances que vous souhaitez planifier.$`You are a helpful assistant that is an expert in planning weekend trips.I've included information about my destination in PARKINFO and WEATHER.Help me plan a weekend trip starting tomorrow.` -
Appuyez sur le bouton “Run” en haut à droite de l’éditeur pour exécuter le script. (Vous pouvez exécuter ce script de cette manière car il ne nécessite aucune autre entrée dans
env.files
)) -
La sortie sera affichée dans un nouvel onglet de document.
Voici un exemple de sortie que vous pourriez obtenir :
Based on the information provided in PARKINFO and the various weather forecasts, here's a concise plan for your weekend trip to Mount Rainier National Park starting tomorrow:
Day 1: Arrival and ExplorationMorning: Arrive at the park via the Nisqually entrance, which is open year-round.Afternoon: Visit Paradise, one of the most popular areas in the park. Check the weather before heading out, as the forecast suggests a heavy fall of snow and extremely cold temperatures. Dress warmly and carry snow chains if driving.Evening: Have dinner at the Paradise Inn, if open, and stay overnight in the park or nearby accommodation.
Voici le GenAIScript complet :
script({ title: "plan-weekend", description: "Given details about my goals, help plan my weekend", model: "openai:gpt-4o",})
const parkinfo = await retrieval.webSearch("mt rainier things to do")const parktext = await fetchText(parkinfo.webPages[0])
const cleanInfo = await runPrompt(_ => { // use def, $ and other helpers _.def("INFO", parktext.text) _.$`You are an expert in web content. Extract out of the file INFO, which is HTML with lots of CSS and HTML tags, the important information that a human would want to know.`})
if (cleanInfo) def("PARKINFO", cleanInfo.text)
const weather = await retrieval.webSearch("mt rainier weather")def("WEATHER", weather.webPages)
$`You are a helpful assistant that is an expert in planning weekend trips.I've included information about my destination in PARKINFO and ${weather}.Help me plan a weekend trip starting tomorrow.`