How to use data from file as part of an AI prompt?

Describe the problem/error/question

I have a workflow which retrieves all javascript files from a csv of mixed data. It then downloads the javascript from the source URL and passes it as output in a data object.

Now I need to analyse each javascript file by prompting my Ollama model to analyse the code and provide specific responses based on certain criteria (such as “Does this JavaScript make any network requests such as XMLHTTPRequest”. I have about 7 or 8 questions I need to ask about the provided JavaScript.

I cannot figure out the workflow nodes needed to do this - I don’t want to store the data in a vector store, I just want to pass the entire script in the prompt (my model has a very large context window).

What is the error message (if any)?

N/A

Please share your workflow

Share the output returned by the last node


[
{
"data": 
"jQuery(document).ready(function($){var html=jQuery("html");var hamburger=jQuery(".hamburger-trigger");var mobileMenu=jQuery("#mobile-menu");var blogFilter=jQuery(".blog__filter");var blogFilterTrigger=jQuery(".blog__filter__trigger");var mmTopLinkParent=mobileMenu.find(".menu-main__item--parent:not(.menu-main__item--has-search)");var mainListToMove=mobileMenu.find(".menu-main__list");var menuBack=mobileMenu.find("#mobile-menu__back");var submenuHeading=mobileMenu.find("#mobile-menu__subheading");var menuSearchTrigger=jQuery("#menu-main__search");var menuSearchContainer=jQuery("#menu-main__search__container");var menuHashLinks=mobileMenu.find('a[href="#"]');blogFilterTrigger.click(function(){blogFilter.toggleClass("active");});hamburger.click(function(){if(hamburger.hasClass("is--active")){html.removeClass("mm-is--active");hamburger.removeClass("is--active");}else{html.addClass("mm-is--active");hamburger.addClass("is--active");}});jQuery(document).on("click",".overlay",function(e){if(jQuery(e.target).hasClass("overlay")){html.removeClass("mm-is--active");hamburger.removeClass("is--active");}});mmTopLinkParent.click(function(){jQuery(this).addClass("is--active");mainListToMove.addClass("is--active");var headingText=jQuery(this).children("a")[0].innerText;console.log(submenuHeading);submenuHeading.text(headingText);});menuBack.click(function(){mmTopLinkParent.removeClass("is--active");mainListToMove.removeClass("is--active");});menuSearchTrigger.click(function(){if(menuSearchTrigger.hasClass("is--active")){menuSearchTrigger.removeClass("is--active");menuSearchContainer.removeClass("is--active");}else{menuSearchTrigger.addClass("is--active");menuSearchContainer.addClass("is--active");}});console.log(menuHashLinks)\nmenuHashLinks.click(function(e){e.preventDefault();})\nfunction calculateTopHeight(){var wpadminbar=jQuery("#wpadminbar");var wpadminbarHeight=wpadminbar.outerHeight();var header=jQuery("header");var headerHeight=header.outerHeight();var overlay=jQuery(".overlay");console.log(wpadminbarHeight+headerHeight+"px");var totalHeight=wpadminbarHeight+headerHeight+"px";mobileMenu.css("top",totalHeight);overlay.css("top",totalHeight);}\ncalculateTopHeight();jQuery(window).resize(function(){calculateTopHeight();var windowWidth=jQuery(window).width();if(windowWidth>1200){html.removeClass("mm-is--active");hamburger.removeClass("is--active");var overlay=jQuery(".overlay");overlay.removeClass("overlay--open");}});});"
}
]

Information on your n8n setup

  • **n8n version:**1.61.0
  • **Database (default: SQLite):**SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):**npm
  • **Operating system:**MacOS

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Please note I could only include one of the scripts in the output data due to the character limit for Questions - there are many different scripts returned from the previous node.

OK I managed to figure this out using Basic LLM Chain node - and I have to say, the results are very impressive :slight_smile:

Hey @ThatPrivacyGuy , have you tried adding the JS code (string) into the prompt of Basic LLM Chain and asking your questions about it?

Yeah I posted in my previous comment, I figured it out using the Basic LLM Chain node.

Now I just need to figure out how to put a pause after each object from the input data is audited so my Mac Studio doesn’t overheat.

Sometimes these reports have hundreds of scripts in them so running each prompt immediately after the other can lead to the M1 getting a little toasty and eventually throttling.

I expect I can potentially put a for loop node in front of the Basic LLM Chain node and add a setTimeout() at the end of the loop - will have a play tomorrow.

Yes, Loop and Wait (instead of setTimeout() in Code) nodes combined should help.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.