{"id":1674,"date":"2023-05-17T13:18:42","date_gmt":"2023-05-17T17:18:42","guid":{"rendered":"https:\/\/jeffq.com\/blog\/?p=1674"},"modified":"2023-05-17T13:18:43","modified_gmt":"2023-05-17T17:18:43","slug":"an-introduction-to-guidance-babyagi-without-openai","status":"publish","type":"post","link":"http:\/\/jeffq.com\/blog\/an-introduction-to-guidance-babyagi-without-openai\/","title":{"rendered":"An introduction to Guidance: BabyAGI without OpenAI"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<body class=\"jp-Notebook\" data-jp-theme-light=\"true\" data-jp-theme-name=\"JupyterLab Light\">\n<div class=\"jp-Cell jp-MarkdownCell jp-Notebook-cell\">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\"><div class=\"jp-InputPrompt jp-InputArea-prompt\">\n<\/div><div class=\"jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput \" data-mime-type=\"text\/markdown\">\n<ul>\n<li><em>Twitter: <a href=\"https:\/\/twitter.com\/theemozilla\">theemozilla<\/a><\/em><\/li>\n<li><em>Jupyter Notebook: <a href=\"https:\/\/github.com\/jquesnelle\/notebooks\/blob\/master\/babyagi-without-openai-guidance.ipynb\">babyagi-without-openai-guidance.ipynb<\/a><\/em><\/li>\n<\/ul>\n<h3 id=\"Guidance\">Guidance<a class=\"anchor-link\" href=\"#Guidance\">\u00b6<\/a><\/h3><p><em>If you&#8217;re already convinced of how awesome Guidance is, you can skip this section<\/em><\/p>\n<p><a href=\"https:\/\/github.com\/microsoft\/guidance\">Guidance<\/a> is a new template language from Microsoft that allows you to guide the output of lanugage models.\nThis may not sound revolutionary on the surface, but if you&#8217;ve ever tried to compose together ouputs from a LM in a non-trivial manner and spent hours re-processing the same prompt or writing tons of boilerplate chaining code, Guidance really can be a next-level unlock.<\/p>\n<p>One of the biggest frustrations when it comes to chaining LM outputs is trying to &#8220;force&#8221; the model to generate in a specific way, for example following certain steps or in a structure that&#8217;s easily programatically interpreted.\nIndeed, the classic chain-of-thought prompt (i.e. &#8220;let&#8217;s think about it step-by-step&#8221;) is merely a prompting technique to guide the model to reason about the task in a desireable way.\nBut what if we could just like&#8230; make the model do what we want?\nThat&#8217;s where Guidance comes in.<\/p>\n<p>Guidance is essentially <a href=\"https:\/\/handlebarsjs.com\/\">Handlebars<\/a> templates for language models, where a magic <code>gen<\/code> command invokes the model in the context of the evaluated template up to this point.\nAs developers, we write the template structure of what we want the output of the model to be, and Guidance manages having the model &#8220;fill in the blanks&#8221;.\nBy way of illustration, consider:<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div><div class=\"jp-Cell jp-CodeCell jp-Notebook-cell   \">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\">\n<div class=\"jp-InputPrompt jp-InputArea-prompt\">In&nbsp;[&nbsp;]:<\/div>\n<div class=\"jp-CodeMirrorEditor jp-Editor jp-InputArea-editor\" data-type=\"inline\">\n     <div class=\"CodeMirror cm-s-jupyter\">\n<div class=\" highlight hl-ipython3\"><pre><span><\/span><span class=\"kn\">from<\/span> <span class=\"nn\">IPython.display<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">Image<\/span>\n<span class=\"kn\">from<\/span> <span class=\"nn\">IPython.core.display<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">HTML<\/span> \n<span class=\"n\">Image<\/span><span class=\"p\">(<\/span><span class=\"n\">url<\/span><span class=\"o\">=<\/span><span class=\"s2\">\"https:\/\/raw.githubusercontent.com\/microsoft\/guidance\/main\/docs\/figures\/json_animation.gif\"<\/span><span class=\"p\">,<\/span> <span class=\"n\">width<\/span><span class=\"o\">=<\/span><span class=\"mi\">376<\/span><span class=\"p\">,<\/span> <span class=\"n\">height<\/span><span class=\"o\">=<\/span><span class=\"mi\">234<\/span><span class=\"p\">)<\/span>\n<\/pre><\/div>\n\n     <\/div>\n<\/div>\n<\/div>\n<\/div>\n\n<div class=\"jp-Cell-outputWrapper\">\n<div class=\"jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser\">\n<\/div>\n\n\n<div class=\"jp-OutputArea jp-Cell-outputArea\">\n<div class=\"jp-OutputArea-child jp-OutputArea-executeResult\">\n    \n    <div class=\"jp-OutputPrompt jp-OutputArea-prompt\">Out[&nbsp;]:<\/div>\n\n\n\n<div class=\"jp-RenderedHTMLCommon jp-RenderedHTML jp-OutputArea-output jp-OutputArea-executeResult\" data-mime-type=\"text\/html\">\n<img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/raw.githubusercontent.com\/microsoft\/guidance\/main\/docs\/figures\/json_animation.gif\" width=\"376\" height=\"234\">\n<\/div>\n\n<\/div>\n\n<\/div>\n\n<\/div>\n\n<\/div>\n<div class=\"jp-Cell jp-MarkdownCell jp-Notebook-cell\">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\"><div class=\"jp-InputPrompt jp-InputArea-prompt\">\n<\/div><div class=\"jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput \" data-mime-type=\"text\/markdown\">\n<p>Here, the text on the white background is static, the blue background text represents variables passed in at runtime, and the green background text are the outputs generated by the language model.\nThe Guidance code for this is:<\/p>\n<pre><code>The following is a character profile for an RPG game in JSON format.\n```json\n{\n    \"id\": \"{{id}}\",\n    \"description\": \"{{description}}\",\n    \"name\": \"{{gen 'name'}}\",\n    \"age\": {{gen 'age' pattern='[0-9]+' stop=','}},\n    \"armor\": \"{{#select 'armor'}}leather{{or}}chainmail{{or}}plate{{\/select}}\",\n    \"weapon\": \"{{select 'weapon' options=valid_weapons}}\",\n    \"class\": \"{{gen 'class'}}\",\n    \"mantra\": \"{{gen 'mantra' temperature=0.7}}\",\n    \"strength\": {{gen 'strength' pattern='[0-9]+' stop=','}},\n    \"items\": [{{#geneach 'items' num_iterations=5 join=', '}}\"{{gen 'this' temperature=0.7}}\"{{\/geneach}}]\n}```\n<\/code><\/pre>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"jp-Cell jp-MarkdownCell jp-Notebook-cell\">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\"><div class=\"jp-InputPrompt jp-InputArea-prompt\">\n<\/div><div class=\"jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput \" data-mime-type=\"text\/markdown\">\n<p>In Guidance we specify how we want our final text to look, using control statements such as <code>gen<\/code> to specify where the model should be used to generate specific pieces.\nThere are tons of different control statements &#8212; in the above example we use the <code>select<\/code> statement to choose between only a few options (underneath Guidance compares the log proabilities of the options and chooses the most likely one).\nWe can also specify regular expressions that define the valid form of an output (making <code>strength<\/code> be numeric).\nThe Guidance repo has tons of <a href=\"https:\/\/github.com\/microsoft\/guidance\/tree\/main\/notebooks\">example notebooks<\/a> that show off its various capabilities.\nOne thing I will say is that, as of this writing (May 2023) there is almost no formalized documentation as Guidance is still <strong>very<\/strong> much a work-in-progess.\nI did all of my learning by looking through the example notebooks.<\/p>\n<h4 id=\"Local-models-in-Guidance\">Local models in Guidance<a class=\"anchor-link\" href=\"#Local-models-in-Guidance\">\u00b6<\/a><\/h4><p>One of the best things about Guidance is its first-class support of running on local models via <a href=\"https:\/\/github.com\/huggingface\/transformers\">transformers<\/a>.\nI would go so far as to say that in Guidance local models are strictly better than using the OpenAI API (although it does support this as well).\nPerhaps its greatest feature from a quality-of-life perspective when using local models is &#8220;acceleration&#8221;.<\/p>\n<p>Guidance acceleration works by caching the intermediate states of the model up to the boundary points within the template.\nWhen the the template is re-evaluated, Guidance can &#8220;skip ahead&#8221; to the point where the prompt actually changes.\nThis greatly speeds up the core write-run-evaluate core developer loop when designing templates.\nIf you&#8217;ve ever sat there re-running the same prompt for the ten thousandth time just to get to where you&#8217;ve made a change, then acceleration is truly a life saver.<\/p>\n<h3 id=\"BabyAGI\">BabyAGI<a class=\"anchor-link\" href=\"#BabyAGI\">\u00b6<\/a><\/h3><p><a href=\"https:\/\/github.com\/yoheinakajima\/babyagi\/\">BabyAGI<\/a> is a proof-of-concept &#8220;AGI&#8221;. In reality, it&#8217;s a task management system that uses a vector database and instructs the language model to plan out and exceute tasks aimed at completing a specific objective (for example, &#8220;paperclip the universe&#8221;).<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div><div class=\"jp-Cell jp-CodeCell jp-Notebook-cell   \">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\">\n<div class=\"jp-InputPrompt jp-InputArea-prompt\">In&nbsp;[&nbsp;]:<\/div>\n<div class=\"jp-CodeMirrorEditor jp-Editor jp-InputArea-editor\" data-type=\"inline\">\n     <div class=\"CodeMirror cm-s-jupyter\">\n<div class=\" highlight hl-ipython3\"><pre><span><\/span><span class=\"n\">Image<\/span><span class=\"p\">(<\/span><span class=\"n\">url<\/span><span class=\"o\">=<\/span><span class=\"s2\">\"https:\/\/user-images.githubusercontent.com\/21254008\/235015461-543a897f-70cc-4b63-941a-2ae3c9172b11.png\"<\/span><span class=\"p\">,<\/span> <span class=\"n\">width<\/span><span class=\"o\">=<\/span><span class=\"mi\">496<\/span><span class=\"p\">,<\/span> <span class=\"n\">height<\/span><span class=\"o\">=<\/span><span class=\"mi\">367<\/span><span class=\"p\">)<\/span>\n<\/pre><\/div>\n\n     <\/div>\n<\/div>\n<\/div>\n<\/div>\n\n<div class=\"jp-Cell-outputWrapper\">\n<div class=\"jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser\">\n<\/div>\n\n\n<div class=\"jp-OutputArea jp-Cell-outputArea\">\n<div class=\"jp-OutputArea-child jp-OutputArea-executeResult\">\n    \n    <div class=\"jp-OutputPrompt jp-OutputArea-prompt\">Out[&nbsp;]:<\/div>\n\n\n\n<div class=\"jp-RenderedHTMLCommon jp-RenderedHTML jp-OutputArea-output jp-OutputArea-executeResult\" data-mime-type=\"text\/html\">\n<img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/user-images.githubusercontent.com\/21254008\/235015461-543a897f-70cc-4b63-941a-2ae3c9172b11.png\" width=\"496\" height=\"367\">\n<\/div>\n\n<\/div>\n\n<\/div>\n\n<\/div>\n\n<\/div>\n<div class=\"jp-Cell jp-MarkdownCell jp-Notebook-cell\">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\"><div class=\"jp-InputPrompt jp-InputArea-prompt\">\n<\/div><div class=\"jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput \" data-mime-type=\"text\/markdown\">\n<p>The <a href=\"https:\/\/github.com\/yoheinakajima\/babyagi\/blob\/main\/babyagi.py\">reference BabyAGI code<\/a> uses the OpenAI APIs.\nI will refrain from editorializing here, but let&#8217;s just say I&#8217;d prefer to be able to do this using open source models &#x1f642;.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"jp-Cell jp-MarkdownCell jp-Notebook-cell\">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\"><div class=\"jp-InputPrompt jp-InputArea-prompt\">\n<\/div><div class=\"jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput \" data-mime-type=\"text\/markdown\">\n<h3 id=\"BabyAGI-in-Guidance\">BabyAGI in Guidance<a class=\"anchor-link\" href=\"#BabyAGI-in-Guidance\">\u00b6<\/a><\/h3>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"jp-Cell jp-MarkdownCell jp-Notebook-cell\">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\"><div class=\"jp-InputPrompt jp-InputArea-prompt\">\n<\/div><div class=\"jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput \" data-mime-type=\"text\/markdown\">\n<p>First, we need to install the prerequisites.\nWe&#8217;ll be using <code>transformers<\/code> and <code>accelerate<\/code> to run our local models and <code>langchain<\/code>, <code>faiss-cpu<\/code>, and <code>sentence_transformers<\/code> for embeddings and vector database.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div><div class=\"jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs  \">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\">\n<div class=\"jp-InputPrompt jp-InputArea-prompt\">In&nbsp;[&nbsp;]:<\/div>\n<div class=\"jp-CodeMirrorEditor jp-Editor jp-InputArea-editor\" data-type=\"inline\">\n     <div class=\"CodeMirror cm-s-jupyter\">\n<div class=\" highlight hl-ipython3\"><pre><span><\/span><span class=\"o\">!<\/span>pip<span class=\"w\"> <\/span>install<span class=\"w\"> <\/span>transformers<span class=\"w\"> <\/span>accelerate<span class=\"w\"> <\/span>langchain<span class=\"w\"> <\/span>faiss-cpu<span class=\"w\"> <\/span>sentence_transformers<span class=\"w\"> <\/span>ipywidgets\n<\/pre><\/div>\n\n     <\/div>\n<\/div>\n<\/div>\n<\/div>\n\n<\/div>\n<div class=\"jp-Cell jp-MarkdownCell jp-Notebook-cell\">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\"><div class=\"jp-InputPrompt jp-InputArea-prompt\">\n<\/div><div class=\"jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput \" data-mime-type=\"text\/markdown\">\n<p>We&#8217;ll be using <a href=\"https:\/\/lmsys.org\/blog\/2023-03-30-vicuna\/\">Vicuna<\/a> as our language model.\nVicuna has shown to be an excellent open-source competitor to GPT-3.5.\nIt is a 13B parameter model finetuned from Llama.<\/p>\n<p>Loading a 13B parameter model takes 52 GB of RAM when loaded at full precision or 26 GB at half precision.\n<code>transformers<\/code> has the helpful <code>load_in_8bit<\/code> parameter that reduces this to 13 GB, but unfortunately Guidance doesn&#8217;t support this yet (until <a href=\"https:\/\/github.com\/microsoft\/guidance\/pull\/8\">PR #8<\/a> merged).\nI have a fork of Guidance that adds in support &#8212; install this if you want to use 8-bit quantization. Otherwise, the regular <code>guidance<\/code> package suffices.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div><div class=\"jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs  \">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\">\n<div class=\"jp-InputPrompt jp-InputArea-prompt\">In&nbsp;[&nbsp;]:<\/div>\n<div class=\"jp-CodeMirrorEditor jp-Editor jp-InputArea-editor\" data-type=\"inline\">\n     <div class=\"CodeMirror cm-s-jupyter\">\n<div class=\" highlight hl-ipython3\"><pre><span><\/span><span class=\"c1\"># 8-bit quantization support<\/span>\n<span class=\"o\">!<\/span>pip<span class=\"w\"> <\/span>install<span class=\"w\"> <\/span>git+https:\/\/github.com\/jquesnelle\/guidance@transformers-quantization-parameters<span class=\"w\"> <\/span>bitsandbytes\n\n<span class=\"c1\"># or, regular guidance<\/span>\n<span class=\"c1\"># !pip install guidance<\/span>\n<\/pre><\/div>\n\n     <\/div>\n<\/div>\n<\/div>\n<\/div>\n\n<\/div>\n<div class=\"jp-Cell jp-MarkdownCell jp-Notebook-cell\">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\"><div class=\"jp-InputPrompt jp-InputArea-prompt\">\n<\/div><div class=\"jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput \" data-mime-type=\"text\/markdown\">\n<p>Next, it&#8217;s time to load our model!<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div><div class=\"jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs  \">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\">\n<div class=\"jp-InputPrompt jp-InputArea-prompt\">In&nbsp;[&nbsp;]:<\/div>\n<div class=\"jp-CodeMirrorEditor jp-Editor jp-InputArea-editor\" data-type=\"inline\">\n     <div class=\"CodeMirror cm-s-jupyter\">\n<div class=\" highlight hl-ipython3\"><pre><span><\/span><span class=\"kn\">import<\/span> <span class=\"nn\">guidance<\/span>\n\n<span class=\"n\">llm<\/span> <span class=\"o\">=<\/span> <span class=\"n\">guidance<\/span><span class=\"o\">.<\/span><span class=\"n\">llms<\/span><span class=\"o\">.<\/span><span class=\"n\">transformers<\/span><span class=\"o\">.<\/span><span class=\"n\">Vicuna<\/span><span class=\"p\">(<\/span>\n    <span class=\"n\">model<\/span><span class=\"o\">=<\/span><span class=\"s2\">\"eachadea\/vicuna-13b-1.1\"<\/span><span class=\"p\">,<\/span>\n    <span class=\"n\">device_map<\/span><span class=\"o\">=<\/span><span class=\"s2\">\"auto\"<\/span><span class=\"p\">,<\/span>\n    <span class=\"n\">load_in_8bit<\/span><span class=\"o\">=<\/span><span class=\"kc\">True<\/span>\n<span class=\"p\">)<\/span>\n<\/pre><\/div>\n\n     <\/div>\n<\/div>\n<\/div>\n<\/div>\n\n<\/div>\n<div class=\"jp-Cell jp-MarkdownCell jp-Notebook-cell\">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\"><div class=\"jp-InputPrompt jp-InputArea-prompt\">\n<\/div><div class=\"jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput \" data-mime-type=\"text\/markdown\">\n<p>We&#8217;ll use <a href=\"https:\/\/github.com\/hwchase17\/langchain\">LangChain<\/a> to help us with embeddings and vector databases.\nThe <code>HuggingFaceEmbeddings<\/code> class uses <a href=\"https:\/\/huggingface.co\/sentence-transformers\/all-mpnet-base-v2\">all-mpnet-base-v2<\/a> to generate embeddings, and we&#8217;ll use the simple <a href=\"https:\/\/github.com\/facebookresearch\/faiss\">FAISS vector database<\/a> from Meta.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div><div class=\"jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs  \">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\">\n<div class=\"jp-InputPrompt jp-InputArea-prompt\">In&nbsp;[&nbsp;]:<\/div>\n<div class=\"jp-CodeMirrorEditor jp-Editor jp-InputArea-editor\" data-type=\"inline\">\n     <div class=\"CodeMirror cm-s-jupyter\">\n<div class=\" highlight hl-ipython3\"><pre><span><\/span><span class=\"kn\">import<\/span> <span class=\"nn\">faiss<\/span>\n<span class=\"kn\">from<\/span> <span class=\"nn\">langchain<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">InMemoryDocstore<\/span>\n<span class=\"kn\">from<\/span> <span class=\"nn\">langchain.embeddings<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">HuggingFaceEmbeddings<\/span>\n<span class=\"kn\">from<\/span> <span class=\"nn\">langchain.vectorstores<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">FAISS<\/span>\n\n<span class=\"n\">embeddings_model<\/span> <span class=\"o\">=<\/span> <span class=\"n\">HuggingFaceEmbeddings<\/span><span class=\"p\">(<\/span><span class=\"n\">model_kwargs<\/span><span class=\"o\">=<\/span><span class=\"p\">{<\/span><span class=\"s2\">\"device\"<\/span><span class=\"p\">:<\/span> <span class=\"s2\">\"cuda:0\"<\/span><span class=\"p\">})<\/span>\n<span class=\"n\">embedding_size<\/span> <span class=\"o\">=<\/span> <span class=\"mi\">768<\/span>\n\n<span class=\"k\">def<\/span> <span class=\"nf\">make_vectorstore<\/span><span class=\"p\">():<\/span>\n    <span class=\"n\">index<\/span> <span class=\"o\">=<\/span> <span class=\"n\">faiss<\/span><span class=\"o\">.<\/span><span class=\"n\">IndexFlatL2<\/span><span class=\"p\">(<\/span><span class=\"n\">embedding_size<\/span><span class=\"p\">)<\/span>\n    <span class=\"k\">return<\/span> <span class=\"n\">FAISS<\/span><span class=\"p\">(<\/span><span class=\"n\">embeddings_model<\/span><span class=\"o\">.<\/span><span class=\"n\">embed_query<\/span><span class=\"p\">,<\/span> <span class=\"n\">index<\/span><span class=\"p\">,<\/span> <span class=\"n\">InMemoryDocstore<\/span><span class=\"p\">({}),<\/span> <span class=\"p\">{})<\/span>\n<\/pre><\/div>\n\n     <\/div>\n<\/div>\n<\/div>\n<\/div>\n\n<\/div>\n<div class=\"jp-Cell jp-MarkdownCell jp-Notebook-cell\">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\"><div class=\"jp-InputPrompt jp-InputArea-prompt\">\n<\/div><div class=\"jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput \" data-mime-type=\"text\/markdown\">\n<p>Okay, let&#8217;s write some Guidance. \nBabyAGI has three core prompts: task execution, task creation, and task prioritization.\nWe&#8217;ll start with the task execution prompt.\nThe reference implementation can be found <a href=\"https:\/\/github.com\/yoheinakajima\/babyagi\/blob\/64e8bdb8ce5efab31b1e7e2e5a14c2ddfc6a0ee7\/babyagi.py#L497\">here<\/a>.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div><div class=\"jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs  \">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\">\n<div class=\"jp-InputPrompt jp-InputArea-prompt\">In&nbsp;[&nbsp;]:<\/div>\n<div class=\"jp-CodeMirrorEditor jp-Editor jp-InputArea-editor\" data-type=\"inline\">\n     <div class=\"CodeMirror cm-s-jupyter\">\n<div class=\" highlight hl-ipython3\"><pre><span><\/span><span class=\"n\">execution_prompt<\/span> <span class=\"o\">=<\/span> <span class=\"n\">guidance<\/span><span class=\"p\">(<\/span><span class=\"s2\">\"\"\"<\/span>\n<span class=\"s2\">{{#system~}}<\/span>\n<span class=\"s2\">{{llm.default_system_prompt}}<\/span>\n<span class=\"s2\">{{~\/system}}<\/span>\n\n<span class=\"s2\">{{#user~}}<\/span>\n<span class=\"s2\">You are an AI who performs one task based on the following objective: {{objective}}.<\/span>\n<span class=\"s2\">Take into account these previously completed tasks: {{context}}.<\/span>\n<span class=\"s2\">Your task: {{task}}.<\/span>\n<span class=\"s2\">{{~\/user}}<\/span>\n\n<span class=\"s2\">{{#assistant~}}<\/span>\n<span class=\"s2\">{{gen 'result'}}<\/span>\n<span class=\"s2\">{{~\/assistant~}}<\/span>\n<span class=\"s2\">\"\"\"<\/span><span class=\"p\">)<\/span>\n<\/pre><\/div>\n\n     <\/div>\n<\/div>\n<\/div>\n<\/div>\n\n<\/div>\n<div class=\"jp-Cell jp-MarkdownCell jp-Notebook-cell\">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\"><div class=\"jp-InputPrompt jp-InputArea-prompt\">\n<\/div><div class=\"jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput \" data-mime-type=\"text\/markdown\">\n<p>Many models are &#8220;chat&#8221; trained.\nThat is to say, they&#8217;ve been finetuned to act as a chatbot.\nTo get the best performance out of these models, you need to prompt them in the same way that they were trained.\nUnfortunately, each model has its own idiosyncrasies for this prompting.\nNormally, this would mean you would need different prompts for each model.\nHowever, Guidance solves this by the special <code>#system<\/code>, <code>#user<\/code>, and <code>#assistant<\/code> commands.\nSeveral popular models are supported (Vicuna, StableLM, MPT) and adding support for a new model is a simple subclass.\nOnce supported, the same prompt can be used across different chat trained models.<\/p>\n<p>In this prompt, <code>objective<\/code>, <code>context<\/code>, and <code>task<\/code> are variables we&#8217;ll pass in at runtime.\nWe&#8217;ll generate the <code>result<\/code> variable, which will be accessible as a property of the returned object when we call <code>execution_prompt<\/code>.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div><div class=\"jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs  \">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\">\n<div class=\"jp-InputPrompt jp-InputArea-prompt\">In&nbsp;[&nbsp;]:<\/div>\n<div class=\"jp-CodeMirrorEditor jp-Editor jp-InputArea-editor\" data-type=\"inline\">\n     <div class=\"CodeMirror cm-s-jupyter\">\n<div class=\" highlight hl-ipython3\"><pre><span><\/span><span class=\"k\">def<\/span> <span class=\"nf\">get_top_tasks<\/span><span class=\"p\">(<\/span><span class=\"n\">vectorstore<\/span><span class=\"p\">,<\/span> <span class=\"n\">query<\/span><span class=\"p\">,<\/span> <span class=\"n\">k<\/span><span class=\"p\">):<\/span>\n    <span class=\"n\">results<\/span> <span class=\"o\">=<\/span> <span class=\"n\">vectorstore<\/span><span class=\"o\">.<\/span><span class=\"n\">similarity_search_with_score<\/span><span class=\"p\">(<\/span><span class=\"n\">query<\/span><span class=\"p\">,<\/span> <span class=\"n\">k<\/span><span class=\"o\">=<\/span><span class=\"n\">k<\/span><span class=\"p\">)<\/span>\n    <span class=\"k\">if<\/span> <span class=\"ow\">not<\/span> <span class=\"n\">results<\/span><span class=\"p\">:<\/span>\n        <span class=\"k\">return<\/span> <span class=\"p\">[]<\/span>\n    <span class=\"n\">sorted_results<\/span><span class=\"p\">,<\/span> <span class=\"n\">_<\/span> <span class=\"o\">=<\/span> <span class=\"nb\">zip<\/span><span class=\"p\">(<\/span><span class=\"o\">*<\/span><span class=\"nb\">sorted<\/span><span class=\"p\">(<\/span><span class=\"n\">results<\/span><span class=\"p\">,<\/span> <span class=\"n\">key<\/span><span class=\"o\">=<\/span><span class=\"k\">lambda<\/span> <span class=\"n\">x<\/span><span class=\"p\">:<\/span> <span class=\"n\">x<\/span><span class=\"p\">[<\/span><span class=\"mi\">1<\/span><span class=\"p\">],<\/span> <span class=\"n\">reverse<\/span><span class=\"o\">=<\/span><span class=\"kc\">True<\/span><span class=\"p\">))<\/span>\n    <span class=\"k\">return<\/span> <span class=\"p\">[<\/span><span class=\"nb\">str<\/span><span class=\"p\">(<\/span><span class=\"n\">item<\/span><span class=\"o\">.<\/span><span class=\"n\">page_content<\/span><span class=\"p\">)<\/span> <span class=\"k\">for<\/span> <span class=\"n\">item<\/span> <span class=\"ow\">in<\/span> <span class=\"n\">sorted_results<\/span><span class=\"p\">]<\/span>\n\n<span class=\"k\">def<\/span> <span class=\"nf\">execute_task<\/span><span class=\"p\">(<\/span><span class=\"n\">vectorstore<\/span><span class=\"p\">,<\/span> <span class=\"n\">objective<\/span><span class=\"p\">,<\/span> <span class=\"n\">task<\/span><span class=\"p\">,<\/span> <span class=\"n\">k<\/span><span class=\"o\">=<\/span><span class=\"mi\">5<\/span><span class=\"p\">):<\/span>\n    <span class=\"n\">context<\/span> <span class=\"o\">=<\/span> <span class=\"n\">get_top_tasks<\/span><span class=\"p\">(<\/span><span class=\"n\">vectorstore<\/span><span class=\"o\">=<\/span><span class=\"n\">vectorstore<\/span><span class=\"p\">,<\/span> <span class=\"n\">query<\/span><span class=\"o\">=<\/span><span class=\"n\">objective<\/span><span class=\"p\">,<\/span> <span class=\"n\">k<\/span><span class=\"o\">=<\/span><span class=\"n\">k<\/span><span class=\"p\">)<\/span> \\\n            <span class=\"k\">if<\/span> <span class=\"n\">vectorstore<\/span> <span class=\"ow\">is<\/span> <span class=\"ow\">not<\/span> <span class=\"kc\">None<\/span> <span class=\"k\">else<\/span> <span class=\"p\">[]<\/span>\n    <span class=\"k\">return<\/span> <span class=\"n\">execution_prompt<\/span><span class=\"p\">(<\/span><span class=\"n\">objective<\/span><span class=\"o\">=<\/span><span class=\"n\">objective<\/span><span class=\"p\">,<\/span> <span class=\"n\">context<\/span><span class=\"o\">=<\/span><span class=\"n\">context<\/span><span class=\"p\">,<\/span> <span class=\"n\">task<\/span><span class=\"o\">=<\/span><span class=\"n\">task<\/span><span class=\"p\">,<\/span> <span class=\"n\">llm<\/span><span class=\"o\">=<\/span><span class=\"n\">llm<\/span><span class=\"p\">)[<\/span><span class=\"s2\">\"result\"<\/span><span class=\"p\">]<\/span>\n<\/pre><\/div>\n\n     <\/div>\n<\/div>\n<\/div>\n<\/div>\n\n<\/div><div class=\"jp-Cell jp-CodeCell jp-Notebook-cell   \">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\">\n<div class=\"jp-InputPrompt jp-InputArea-prompt\">In&nbsp;[&nbsp;]:<\/div>\n<div class=\"jp-CodeMirrorEditor jp-Editor jp-InputArea-editor\" data-type=\"inline\">\n     <div class=\"CodeMirror cm-s-jupyter\">\n<div class=\" highlight hl-ipython3\"><pre><span><\/span><span class=\"n\">sample_objective<\/span> <span class=\"o\">=<\/span> <span class=\"s2\">\"Write a weather report for SF today\"<\/span>\n<span class=\"n\">FIRST_TASK<\/span> <span class=\"o\">=<\/span> <span class=\"s2\">\"Write a todo list to complete the objective\"<\/span>\n<span class=\"n\">sample_execute_task<\/span> <span class=\"o\">=<\/span> <span class=\"n\">execute_task<\/span><span class=\"p\">(<\/span><span class=\"n\">vectorstore<\/span><span class=\"o\">=<\/span><span class=\"kc\">None<\/span><span class=\"p\">,<\/span> <span class=\"n\">objective<\/span><span class=\"o\">=<\/span><span class=\"n\">sample_objective<\/span><span class=\"p\">,<\/span> <span class=\"n\">task<\/span><span class=\"o\">=<\/span><span class=\"n\">FIRST_TASK<\/span><span class=\"p\">)<\/span>\n<span class=\"n\">sample_execute_task<\/span>\n<\/pre><\/div>\n\n     <\/div>\n<\/div>\n<\/div>\n<\/div>\n\n<div class=\"jp-Cell-outputWrapper\">\n<div class=\"jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser\">\n<\/div>\n\n\n<div class=\"jp-OutputArea jp-Cell-outputArea\">\n<div class=\"jp-OutputArea-child\">\n    \n    <div class=\"jp-OutputPrompt jp-OutputArea-prompt\"><\/div>\n\n\n\n<div class=\"jp-RenderedHTMLCommon jp-RenderedHTML jp-OutputArea-output \" data-mime-type=\"text\/html\">\n<div id=\"guidance-stop-button-3babbdc8-b13d-48ad-bc95-1440f3a75482\" style=\"cursor: pointer; margin: 0px; display: none; float: right; padding: 3px; border-radius: 4px 4px 4px 4px; border: 0px solid rgba(127, 127, 127, 1); padding-left: 10px; padding-right: 10px; font-size: 13px; background-color: rgba(127, 127, 127, 0.25);\">Stop program<\/div><div id=\"guidance-content-3babbdc8-b13d-48ad-bc95-1440f3a75482\"><pre style=\"margin: 0px; padding: 0px; padding-left: 8px; margin-left: -8px; border-radius: 0px; border-left: 1px solid rgba(127, 127, 127, 0.2); white-space: pre-wrap; font-family: ColfaxAI, Arial; font-size: 15px; line-height: 23px;\"><div style=\"display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;\"><div style=\"flex: 0 0 80px; opacity: 0.5;\">system<\/div><div style=\"flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;\"><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{llm.default_system_prompt}}\">A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.<\/span><\/div><\/div><div style=\"display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;\"><div style=\"flex: 0 0 80px; opacity: 0.5;\">user<\/div><div style=\"flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;\">You are an AI who performs one task based on the following objective: <span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{objective}}\">Write a weather report for SF today<\/span>.\nTake into account these previously completed tasks: <span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{context}}\">[]<\/span>.\nYour task: <span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{task}}\">Write a todo list to complete the objective<\/span>.<\/div><\/div><div style=\"display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;\"><div style=\"flex: 0 0 80px; opacity: 0.5;\">assistant<\/div><div style=\"flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;\"><span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'result'}}\">1. Gather current weather data for San Francisco.\n2. Analyze data to determine current weather conditions in San Francisco.\n3. Write a clear and concise weather report for San Francisco based on the data gathered and analysis completed.\n4. Include any relevant information about the forecast for the rest of the day and any potential weather-related hazards or concerns.\n5. Organize the information in a logical and easy-to-understand format.\n6. Review and edit the weather report for accuracy and clarity.\n7. Present the weather report in a professional and engaging manner.<\/span><\/div><\/div><\/pre><\/div>\n<script type=\"text\/javascript\">(()=>{var t={296:(t,e,n)=>{var i=NaN,o=\"[object Symbol]\",r=\/^\\s+|\\s+$\/g,a=\/^[-+]0x[0-9a-f]+$\/i,s=\/^0b[01]+$\/i,c=\/^0o[0-7]+$\/i,d=parseInt,u=\"object\"==typeof n.g&&n.g&&n.g.Object===Object&&n.g,l=\"object\"==typeof self&&self&&self.Object===Object&&self,f=u||l||Function(\"return this\")(),h=Object.prototype.toString,p=Math.max,m=Math.min,g=function(){return f.Date.now()};function b(t){var e=typeof t;return!!t&&(\"object\"==e||\"function\"==e)}function y(t){if(\"number\"==typeof t)return t;if(function(t){return\"symbol\"==typeof t||function(t){return!!t&&\"object\"==typeof t}(t)&&h.call(t)==o}(t))return i;if(b(t)){var e=\"function\"==typeof t.valueOf?t.valueOf():t;t=b(e)?e+\"\":e}if(\"string\"!=typeof t)return 0===t?t:+t;t=t.replace(r,\"\");var n=s.test(t);return n||c.test(t)?d(t.slice(2),n?2:8):a.test(t)?i:+t}t.exports=function(t,e,n){var i,o,r,a,s,c,d=0,u=!1,l=!1,f=!0;if(\"function\"!=typeof t)throw new TypeError(\"Expected a function\");function h(e){var n=i,r=o;return i=o=void 0,d=e,a=t.apply(r,n)}function v(t){var n=t-c;return void 0===c||n>=e||n<0||l&#038;&#038;t-d>=r}function _(){var t=g();if(v(t))return w(t);s=setTimeout(_,function(t){var n=e-(t-c);return l?m(n,r-(t-d)):n}(t))}function w(t){return s=void 0,f&&i?h(t):(i=o=void 0,a)}function j(){var t=g(),n=v(t);if(i=arguments,o=this,c=t,n){if(void 0===s)return function(t){return d=t,s=setTimeout(_,e),u?h(t):a}(c);if(l)return s=setTimeout(_,e),h(c)}return void 0===s&&(s=setTimeout(_,e)),a}return e=y(e)||0,b(n)&&(u=!!n.leading,r=(l=\"maxWait\"in n)?p(y(n.maxWait)||0,e):r,f=\"trailing\"in n?!!n.trailing:f),j.cancel=function(){void 0!==s&&clearTimeout(s),d=0,i=c=o=s=void 0},j.flush=function(){return void 0===s?a:w(g())},j}},777:t=>{var e,n,i=Math.max,o=(e=function(t,e){return function(t,e,n){if(\"function\"!=typeof t)throw new TypeError(\"Expected a function\");return setTimeout((function(){t.apply(void 0,n)}),1)}(t,0,e)},n=i(void 0===n?e.length-1:n,0),function(){for(var t=arguments,o=-1,r=i(t.length-n,0),a=Array(r);++o<r;)a[o]=t[n+o];o=-1;for(var s=Array(n+1);++o<n;)s[o]=t[o];return s[n]=a,function(t,e,n){switch(n.length){case 0:return t.call(e);case 1:return t.call(e,n[0]);case 2:return t.call(e,n[0],n[1]);case 3:return t.call(e,n[0],n[1],n[2])}return t.apply(e,n)}(e,this,s)});t.exports=o}},e={};function n(i){var o=e[i];if(void 0!==o)return o.exports;var r=e[i]={exports:{}};return t[i](r,r.exports,n),r.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.g=function(){if(\"object\"==typeof globalThis)return globalThis;try{return this||new Function(\"return this\")()}catch(t){if(\"object\"==typeof window)return window}}(),n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),(()=>{\"use strict\";const t=t=>{const e=new Set;do{for(const n of Reflect.ownKeys(t))e.add([t,n])}while((t=Reflect.getPrototypeOf(t))&&t!==Object.prototype);return e};function e(e,{include:n,exclude:i}={}){const o=t=>{const e=e=>\"string\"==typeof e?t===e:e.test(t);return n?n.some(e):!i||!i.some(e)};for(const[n,i]of t(e.constructor.prototype)){if(\"constructor\"===i||!o(i))continue;const t=Reflect.getOwnPropertyDescriptor(n,i);t&&\"function\"==typeof t.value&&(e[i]=e[i].bind(e))}return e}var i=n(777),o=n.n(i),r=n(296),a=n.n(r);class s{constructor(t,n){e(this),this.interfaceId=t,this.callbackMap={},this.data={},this.pendingData={},this.jcomm=new c(\"guidance_interface_target_\"+this.interfaceId,this.updateData,\"open\"),this.debouncedSendPendingData500=a()(this.sendPendingData,500),this.debouncedSendPendingData1000=a()(this.sendPendingData,1e3),n&&o()(n)}send(t,e){this.addPendingData(t,e),this.sendPendingData()}sendEvent(t){for(const e of Object.keys(t))this.addPendingData(e,t[e]);this.sendPendingData()}debouncedSendEvent500(t){for(const e of Object.keys(t))this.addPendingData(e,t[e]);this.debouncedSendPendingData500()}debouncedSend500(t,e){this.addPendingData(t,e),this.debouncedSendPendingData500()}debouncedSend1000(t,e){this.addPendingData(t,e),this.debouncedSendPendingData1000()}addPendingData(t,e){Array.isArray(t)||(t=[t]);for(const n in t)this.pendingData[t[n]]=e}updateData(t){t=JSON.parse(t.data);for(const e in t)this.data[e]=t[e];for(const e in t)e in this.callbackMap&&this.callbackMap[e](this.data[e])}subscribe(t,e){this.callbackMap[t]=e,o()((e=>this.callbackMap[t](this.data[t])))}sendPendingData(){this.jcomm.send_data(this.pendingData),this.pendingData={}}}class c{constructor(t,e,n=\"open\"){this._fire_callback=this._fire_callback.bind(this),this._register=this._register.bind(this),this.jcomm=void 0,this.callback=e,void 0!==window.Jupyter?\"register\"===n?Jupyter.notebook.kernel.comm_manager.register_target(t,this._register):(this.jcomm=Jupyter.notebook.kernel.comm_manager.new_comm(t),this.jcomm.on_msg(this._fire_callback)):void 0!==window._mgr&&(\"register\"===n?window._mgr.widgetManager.proxyKernel.registerCommTarget(t,this._register):(this.jcomm=window._mgr.widgetManager.proxyKernel.createComm(t),this.jcomm.open({},\"\"),this.jcomm.onMsg=this._fire_callback))}send_data(t){void 0!==this.jcomm?this.jcomm.send(t):console.error(\"Jupyter comm module not yet loaded! So we can't send the message.\")}_register(t,e){this.jcomm=t,this.jcomm.on_msg(this._fire_callback)}_fire_callback(t){this.callback(t.content.data)}}class d{constructor(t,n){e(this),this.id=t,this.comm=new s(t),this.comm.subscribe(\"append\",this.appendData),this.comm.subscribe(\"replace\",this.replaceData),this.comm.subscribe(\"event\",this.eventOccurred),this.element=document.getElementById(\"guidance-content-\"+t),this.stop_button=document.getElementById(\"guidance-stop-button-\"+t),this.stop_button.onclick=()=>this.comm.send(\"event\",\"stop\")}appendData(t){t&&(this.stop_button.style.display=\"inline-block\",this.element.innerHTML+=t)}replaceData(t){t&&(this.stop_button.style.display=\"inline-block\",this.element.innerHTML=t)}eventOccurred(t){\"complete\"===t&&(this.stop_button.style.display=\"none\")}}window._guidanceDisplay=function(t,e){return new d(t,e)}})()})();; window._guidanceDisplay(\"3babbdc8-b13d-48ad-bc95-1440f3a75482\");<\/script>\n<\/div>\n\n<\/div>\n<div class=\"jp-OutputArea-child jp-OutputArea-executeResult\">\n    \n    <div class=\"jp-OutputPrompt jp-OutputArea-prompt\">Out[&nbsp;]:<\/div>\n\n\n\n\n<div class=\"jp-RenderedText jp-OutputArea-output jp-OutputArea-executeResult\" data-mime-type=\"text\/plain\">\n<pre>'1. Gather current weather data for San Francisco.\\n2. Analyze data to determine current weather conditions in San Francisco.\\n3. Write a clear and concise weather report for San Francisco based on the data gathered and analysis completed.\\n4. Include any relevant information about the forecast for the rest of the day and any potential weather-related hazards or concerns.\\n5. Organize the information in a logical and easy-to-understand format.\\n6. Review and edit the weather report for accuracy and clarity.\\n7. Present the weather report in a professional and engaging manner.'<\/pre>\n<\/div>\n\n<\/div>\n\n<\/div>\n\n<\/div>\n\n<\/div>\n<div class=\"jp-Cell jp-MarkdownCell jp-Notebook-cell\">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\"><div class=\"jp-InputPrompt jp-InputArea-prompt\">\n<\/div><div class=\"jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput \" data-mime-type=\"text\/markdown\">\n<p>When executing in a Jupyter notebook, Guidance automatically presents the output in an easily digestable format.\nWe can see the seperate <code>system<\/code>, <code>user<\/code>, and <code>assistant<\/code> sections and see where runtime varabiles were inserted (blue) ana the model generated new text (green).\nEvery variable that is created via <code>gen<\/code> is available in the result object directly &#8212; already parsed!<\/p>\n<p>Next up is the task creation prompt.\nA large part of the <a href=\"https:\/\/github.com\/yoheinakajima\/babyagi\/blob\/main\/babyagi.py#L420\">reference implementation<\/a> is concerned with cleaning up the response from the model, and hoping (praying) it will follow instructions regarding how to structure the output so it can be programatically iterepreted.\nBut, this is just the task the Guidance excels at!<\/p>\n<p>Our goal is to have the model take whatever the output of the previous task was and create a list of tasks to carry out the objective.\nThis is done iteratively, so we pass in any previously incomplete tasks, and ask the model for new tasks.\nWhile we politely ask the model to output the tasks as an array, with Guidance we can actually <em>make<\/em> it happen.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div><div class=\"jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs  \">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\">\n<div class=\"jp-InputPrompt jp-InputArea-prompt\">In&nbsp;[&nbsp;]:<\/div>\n<div class=\"jp-CodeMirrorEditor jp-Editor jp-InputArea-editor\" data-type=\"inline\">\n     <div class=\"CodeMirror cm-s-jupyter\">\n<div class=\" highlight hl-ipython3\"><pre><span><\/span><span class=\"n\">creation_prompt<\/span> <span class=\"o\">=<\/span> <span class=\"n\">guidance<\/span><span class=\"p\">(<\/span><span class=\"s2\">\"\"\"<\/span>\n<span class=\"s2\">{{#system~}}<\/span>\n<span class=\"s2\">{{llm.default_system_prompt}}<\/span>\n<span class=\"s2\">{{~\/system}}<\/span>\n\n<span class=\"s2\">{{#user~}}<\/span>\n<span class=\"s2\">You are a task creation AI that uses the result of an execution agent to create new tasks with the following objective: {{objective}}.<\/span>\n<span class=\"s2\">The last completed task has the result: {{result}}.<\/span>\n<span class=\"s2\">This result was based on this task description: {{task_description}}.<\/span>\n<span class=\"s2\">These are the incomplete tasks: {{incomplete_tasks}}.<\/span>\n<span class=\"s2\">Based on the result, create new tasks to be completed by the AI system that do not overlap with the incomplete tasks.<\/span>\n<span class=\"s2\">{{~\/user}}<\/span>\n\n<span class=\"s2\">{{#assistant~}}<\/span>\n<span class=\"s2\">```json<\/span>\n<span class=\"s2\">[{{#geneach 'tasks' stop=\"]\"}}{{#unless @first}}, {{\/unless}}\"{{gen 'this'}}\"{{\/geneach}}]<\/span>\n<span class=\"s2\">```<\/span>\n<span class=\"s2\">{{~\/assistant~}}<\/span>\n<span class=\"s2\">\"\"\"<\/span><span class=\"p\">)<\/span>\n<\/pre><\/div>\n\n     <\/div>\n<\/div>\n<\/div>\n<\/div>\n\n<\/div>\n<div class=\"jp-Cell jp-MarkdownCell jp-Notebook-cell\">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\"><div class=\"jp-InputPrompt jp-InputArea-prompt\">\n<\/div><div class=\"jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput \" data-mime-type=\"text\/markdown\">\n<p>The <code>geneach<\/code> command tells Guidance to do a looped generation, creating a list of <code>tasks<\/code>.\nBy placing <code>geneach<\/code> inside of <code>[\"\"]<\/code> we can enforce a JSON array structure (the <code>unless<\/code> command is used to add neccessary commas).<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div><div class=\"jp-Cell jp-CodeCell jp-Notebook-cell   \">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\">\n<div class=\"jp-InputPrompt jp-InputArea-prompt\">In&nbsp;[&nbsp;]:<\/div>\n<div class=\"jp-CodeMirrorEditor jp-Editor jp-InputArea-editor\" data-type=\"inline\">\n     <div class=\"CodeMirror cm-s-jupyter\">\n<div class=\" highlight hl-ipython3\"><pre><span><\/span><span class=\"k\">def<\/span> <span class=\"nf\">create_tasks<\/span><span class=\"p\">(<\/span><span class=\"n\">result<\/span><span class=\"p\">,<\/span> <span class=\"n\">task_description<\/span><span class=\"p\">,<\/span> <span class=\"n\">task_list<\/span><span class=\"p\">,<\/span> <span class=\"n\">objective<\/span><span class=\"p\">):<\/span>\n    <span class=\"n\">response<\/span> <span class=\"o\">=<\/span> <span class=\"n\">creation_prompt<\/span><span class=\"p\">(<\/span>\n        <span class=\"n\">result<\/span><span class=\"o\">=<\/span><span class=\"n\">result<\/span><span class=\"p\">,<\/span>\n        <span class=\"n\">task_description<\/span><span class=\"o\">=<\/span><span class=\"n\">task_description<\/span><span class=\"p\">,<\/span>\n        <span class=\"n\">incomplete_tasks<\/span><span class=\"o\">=<\/span><span class=\"n\">task_list<\/span><span class=\"p\">,<\/span>\n        <span class=\"n\">objective<\/span><span class=\"o\">=<\/span><span class=\"n\">objective<\/span><span class=\"p\">,<\/span>\n        <span class=\"n\">llm<\/span><span class=\"o\">=<\/span><span class=\"n\">llm<\/span>\n    <span class=\"p\">)<\/span>\n    <span class=\"n\">new_tasks<\/span> <span class=\"o\">=<\/span> <span class=\"p\">[<\/span><span class=\"n\">task<\/span> <span class=\"k\">for<\/span> <span class=\"n\">task<\/span> <span class=\"ow\">in<\/span> <span class=\"n\">response<\/span><span class=\"p\">[<\/span><span class=\"s2\">\"tasks\"<\/span><span class=\"p\">]<\/span> <span class=\"k\">if<\/span> <span class=\"n\">task<\/span> <span class=\"ow\">not<\/span> <span class=\"ow\">in<\/span> <span class=\"n\">task_list<\/span><span class=\"p\">]<\/span>\n    <span class=\"k\">return<\/span> <span class=\"p\">[{<\/span><span class=\"s2\">\"task_name\"<\/span><span class=\"p\">:<\/span> <span class=\"n\">task_name<\/span><span class=\"p\">}<\/span> <span class=\"k\">for<\/span> <span class=\"n\">task_name<\/span> <span class=\"ow\">in<\/span> <span class=\"n\">new_tasks<\/span> <span class=\"k\">if<\/span> <span class=\"n\">task_name<\/span><span class=\"o\">.<\/span><span class=\"n\">strip<\/span><span class=\"p\">()]<\/span>\n\n<span class=\"n\">sample_created_tasks<\/span> <span class=\"o\">=<\/span> <span class=\"n\">create_tasks<\/span><span class=\"p\">(<\/span>\n    <span class=\"n\">result<\/span><span class=\"o\">=<\/span><span class=\"n\">sample_execute_task<\/span><span class=\"p\">,<\/span>\n    <span class=\"n\">task_description<\/span><span class=\"o\">=<\/span><span class=\"n\">FIRST_TASK<\/span><span class=\"p\">,<\/span>\n    <span class=\"n\">task_list<\/span><span class=\"o\">=<\/span><span class=\"p\">[],<\/span>\n    <span class=\"n\">objective<\/span><span class=\"o\">=<\/span><span class=\"n\">sample_objective<\/span>\n<span class=\"p\">)<\/span>\n<span class=\"n\">sample_created_tasks<\/span>\n<\/pre><\/div>\n\n     <\/div>\n<\/div>\n<\/div>\n<\/div>\n\n<div class=\"jp-Cell-outputWrapper\">\n<div class=\"jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser\">\n<\/div>\n\n\n<div class=\"jp-OutputArea jp-Cell-outputArea\">\n<div class=\"jp-OutputArea-child\">\n    \n    <div class=\"jp-OutputPrompt jp-OutputArea-prompt\"><\/div>\n\n\n\n<div class=\"jp-RenderedHTMLCommon jp-RenderedHTML jp-OutputArea-output \" data-mime-type=\"text\/html\">\n<div id=\"guidance-stop-button-0a3af691-e9f7-4a5f-b690-8a6decf54e2c\" style=\"cursor: pointer; margin: 0px; display: none; float: right; padding: 3px; border-radius: 4px 4px 4px 4px; border: 0px solid rgba(127, 127, 127, 1); padding-left: 10px; padding-right: 10px; font-size: 13px; background-color: rgba(127, 127, 127, 0.25);\">Stop program<\/div><div id=\"guidance-content-0a3af691-e9f7-4a5f-b690-8a6decf54e2c\"><pre style=\"margin: 0px; padding: 0px; padding-left: 8px; margin-left: -8px; border-radius: 0px; border-left: 1px solid rgba(127, 127, 127, 0.2); white-space: pre-wrap; font-family: ColfaxAI, Arial; font-size: 15px; line-height: 23px;\"><div style=\"display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;\"><div style=\"flex: 0 0 80px; opacity: 0.5;\">system<\/div><div style=\"flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;\"><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{llm.default_system_prompt}}\">A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.<\/span><\/div><\/div><div style=\"display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;\"><div style=\"flex: 0 0 80px; opacity: 0.5;\">user<\/div><div style=\"flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;\">You are a task creation AI that uses the result of an execution agent to create new tasks with the following objective: <span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{objective}}\">Write a weather report for SF today<\/span>.\nThe last completed task has the result: <span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{result}}\">1. Gather current weather data for San Francisco.\n2. Analyze data to determine current weather conditions in San Francisco.\n3. Write a clear and concise weather report for San Francisco based on the data gathered and analysis completed.\n4. Include any relevant information about the forecast for the rest of the day and any potential weather-related hazards or concerns.\n5. Organize the information in a logical and easy-to-understand format.\n6. Review and edit the weather report for accuracy and clarity.\n7. Present the weather report in a professional and engaging manner.<\/span>.\nThis result was based on this task description: <span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{task_description}}\">Write a todo list to complete the objective<\/span>.\nThese are the incomplete tasks: <span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{incomplete_tasks}}\">[]<\/span>.\nBased on the result, create new tasks to be completed by the AI system that do not overlap with the incomplete tasks.<\/div><\/div><div style=\"display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;\"><div style=\"flex: 0 0 80px; opacity: 0.5;\">assistant<\/div><div style=\"flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;\">```json\n[<span style=\"opacity: 1.0; display: inline; background-color: rgba(165, 165, 165, 0.1);\" title=\"{{#geneach 'tasks' stop=&quot;]&quot;}}{{#unless @first}}, {{\/unless}}&quot;{{gen 'this'}}&quot;{{\/geneach}}\"><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#unless @first}}, {{\/unless}}\"><\/span>\"<span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this'}}\">Write a clear and concise weather report for San Francisco based on the data gathered and analysis completed.<\/span>\"<span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#unless @first}}, {{\/unless}}\">, <\/span>\"<span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this'}}\">Include any relevant information about the forecast for the rest of the day and any potential weather-related hazards or concerns.<\/span>\"<span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#unless @first}}, {{\/unless}}\">, <\/span>\"<span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this'}}\">Organize the information in a logical and easy-to-understand format.<\/span>\"<span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#unless @first}}, {{\/unless}}\">, <\/span>\"<span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this'}}\">Review and edit the weather report for accuracy and clarity.<\/span>\"<span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#unless @first}}, {{\/unless}}\">, <\/span>\"<span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this'}}\">Present the weather report in a professional and engaging manner.<\/span>\"<\/span>]\n```<\/div><\/div><\/pre><\/div>\n<script type=\"text\/javascript\">(()=>{var t={296:(t,e,n)=>{var i=NaN,o=\"[object Symbol]\",r=\/^\\s+|\\s+$\/g,a=\/^[-+]0x[0-9a-f]+$\/i,s=\/^0b[01]+$\/i,c=\/^0o[0-7]+$\/i,d=parseInt,u=\"object\"==typeof n.g&&n.g&&n.g.Object===Object&&n.g,l=\"object\"==typeof self&&self&&self.Object===Object&&self,f=u||l||Function(\"return this\")(),h=Object.prototype.toString,p=Math.max,m=Math.min,g=function(){return f.Date.now()};function b(t){var e=typeof t;return!!t&&(\"object\"==e||\"function\"==e)}function y(t){if(\"number\"==typeof t)return t;if(function(t){return\"symbol\"==typeof t||function(t){return!!t&&\"object\"==typeof t}(t)&&h.call(t)==o}(t))return i;if(b(t)){var e=\"function\"==typeof t.valueOf?t.valueOf():t;t=b(e)?e+\"\":e}if(\"string\"!=typeof t)return 0===t?t:+t;t=t.replace(r,\"\");var n=s.test(t);return n||c.test(t)?d(t.slice(2),n?2:8):a.test(t)?i:+t}t.exports=function(t,e,n){var i,o,r,a,s,c,d=0,u=!1,l=!1,f=!0;if(\"function\"!=typeof t)throw new TypeError(\"Expected a function\");function h(e){var n=i,r=o;return i=o=void 0,d=e,a=t.apply(r,n)}function v(t){var n=t-c;return void 0===c||n>=e||n<0||l&#038;&#038;t-d>=r}function _(){var t=g();if(v(t))return w(t);s=setTimeout(_,function(t){var n=e-(t-c);return l?m(n,r-(t-d)):n}(t))}function w(t){return s=void 0,f&&i?h(t):(i=o=void 0,a)}function j(){var t=g(),n=v(t);if(i=arguments,o=this,c=t,n){if(void 0===s)return function(t){return d=t,s=setTimeout(_,e),u?h(t):a}(c);if(l)return s=setTimeout(_,e),h(c)}return void 0===s&&(s=setTimeout(_,e)),a}return e=y(e)||0,b(n)&&(u=!!n.leading,r=(l=\"maxWait\"in n)?p(y(n.maxWait)||0,e):r,f=\"trailing\"in n?!!n.trailing:f),j.cancel=function(){void 0!==s&&clearTimeout(s),d=0,i=c=o=s=void 0},j.flush=function(){return void 0===s?a:w(g())},j}},777:t=>{var e,n,i=Math.max,o=(e=function(t,e){return function(t,e,n){if(\"function\"!=typeof t)throw new TypeError(\"Expected a function\");return setTimeout((function(){t.apply(void 0,n)}),1)}(t,0,e)},n=i(void 0===n?e.length-1:n,0),function(){for(var t=arguments,o=-1,r=i(t.length-n,0),a=Array(r);++o<r;)a[o]=t[n+o];o=-1;for(var s=Array(n+1);++o<n;)s[o]=t[o];return s[n]=a,function(t,e,n){switch(n.length){case 0:return t.call(e);case 1:return t.call(e,n[0]);case 2:return t.call(e,n[0],n[1]);case 3:return t.call(e,n[0],n[1],n[2])}return t.apply(e,n)}(e,this,s)});t.exports=o}},e={};function n(i){var o=e[i];if(void 0!==o)return o.exports;var r=e[i]={exports:{}};return t[i](r,r.exports,n),r.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.g=function(){if(\"object\"==typeof globalThis)return globalThis;try{return this||new Function(\"return this\")()}catch(t){if(\"object\"==typeof window)return window}}(),n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),(()=>{\"use strict\";const t=t=>{const e=new Set;do{for(const n of Reflect.ownKeys(t))e.add([t,n])}while((t=Reflect.getPrototypeOf(t))&&t!==Object.prototype);return e};function e(e,{include:n,exclude:i}={}){const o=t=>{const e=e=>\"string\"==typeof e?t===e:e.test(t);return n?n.some(e):!i||!i.some(e)};for(const[n,i]of t(e.constructor.prototype)){if(\"constructor\"===i||!o(i))continue;const t=Reflect.getOwnPropertyDescriptor(n,i);t&&\"function\"==typeof t.value&&(e[i]=e[i].bind(e))}return e}var i=n(777),o=n.n(i),r=n(296),a=n.n(r);class s{constructor(t,n){e(this),this.interfaceId=t,this.callbackMap={},this.data={},this.pendingData={},this.jcomm=new c(\"guidance_interface_target_\"+this.interfaceId,this.updateData,\"open\"),this.debouncedSendPendingData500=a()(this.sendPendingData,500),this.debouncedSendPendingData1000=a()(this.sendPendingData,1e3),n&&o()(n)}send(t,e){this.addPendingData(t,e),this.sendPendingData()}sendEvent(t){for(const e of Object.keys(t))this.addPendingData(e,t[e]);this.sendPendingData()}debouncedSendEvent500(t){for(const e of Object.keys(t))this.addPendingData(e,t[e]);this.debouncedSendPendingData500()}debouncedSend500(t,e){this.addPendingData(t,e),this.debouncedSendPendingData500()}debouncedSend1000(t,e){this.addPendingData(t,e),this.debouncedSendPendingData1000()}addPendingData(t,e){Array.isArray(t)||(t=[t]);for(const n in t)this.pendingData[t[n]]=e}updateData(t){t=JSON.parse(t.data);for(const e in t)this.data[e]=t[e];for(const e in t)e in this.callbackMap&&this.callbackMap[e](this.data[e])}subscribe(t,e){this.callbackMap[t]=e,o()((e=>this.callbackMap[t](this.data[t])))}sendPendingData(){this.jcomm.send_data(this.pendingData),this.pendingData={}}}class c{constructor(t,e,n=\"open\"){this._fire_callback=this._fire_callback.bind(this),this._register=this._register.bind(this),this.jcomm=void 0,this.callback=e,void 0!==window.Jupyter?\"register\"===n?Jupyter.notebook.kernel.comm_manager.register_target(t,this._register):(this.jcomm=Jupyter.notebook.kernel.comm_manager.new_comm(t),this.jcomm.on_msg(this._fire_callback)):void 0!==window._mgr&&(\"register\"===n?window._mgr.widgetManager.proxyKernel.registerCommTarget(t,this._register):(this.jcomm=window._mgr.widgetManager.proxyKernel.createComm(t),this.jcomm.open({},\"\"),this.jcomm.onMsg=this._fire_callback))}send_data(t){void 0!==this.jcomm?this.jcomm.send(t):console.error(\"Jupyter comm module not yet loaded! So we can't send the message.\")}_register(t,e){this.jcomm=t,this.jcomm.on_msg(this._fire_callback)}_fire_callback(t){this.callback(t.content.data)}}class d{constructor(t,n){e(this),this.id=t,this.comm=new s(t),this.comm.subscribe(\"append\",this.appendData),this.comm.subscribe(\"replace\",this.replaceData),this.comm.subscribe(\"event\",this.eventOccurred),this.element=document.getElementById(\"guidance-content-\"+t),this.stop_button=document.getElementById(\"guidance-stop-button-\"+t),this.stop_button.onclick=()=>this.comm.send(\"event\",\"stop\")}appendData(t){t&&(this.stop_button.style.display=\"inline-block\",this.element.innerHTML+=t)}replaceData(t){t&&(this.stop_button.style.display=\"inline-block\",this.element.innerHTML=t)}eventOccurred(t){\"complete\"===t&&(this.stop_button.style.display=\"none\")}}window._guidanceDisplay=function(t,e){return new d(t,e)}})()})();; window._guidanceDisplay(\"0a3af691-e9f7-4a5f-b690-8a6decf54e2c\");<\/script>\n<\/div>\n\n<\/div>\n<div class=\"jp-OutputArea-child jp-OutputArea-executeResult\">\n    \n    <div class=\"jp-OutputPrompt jp-OutputArea-prompt\">Out[&nbsp;]:<\/div>\n\n\n\n\n<div class=\"jp-RenderedText jp-OutputArea-output jp-OutputArea-executeResult\" data-mime-type=\"text\/plain\">\n<pre>[{'task_name': 'Write a clear and concise weather report for San Francisco based on the data gathered and analysis completed.'},\n {'task_name': 'Include any relevant information about the forecast for the rest of the day and any potential weather-related hazards or concerns.'},\n {'task_name': 'Organize the information in a logical and easy-to-understand format.'},\n {'task_name': 'Review and edit the weather report for accuracy and clarity.'},\n {'task_name': 'Present the weather report in a professional and engaging manner.'}]<\/pre>\n<\/div>\n\n<\/div>\n\n<\/div>\n\n<\/div>\n\n<\/div>\n<div class=\"jp-Cell jp-MarkdownCell jp-Notebook-cell\">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\"><div class=\"jp-InputPrompt jp-InputArea-prompt\">\n<\/div><div class=\"jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput \" data-mime-type=\"text\/markdown\">\n<p>Our <code>tasks<\/code> correctly generated and parsed!\nWe then place these in a dictionary under the key <code>task_name<\/code> for later use in the full BabyAGI procedure.<\/p>\n<p>The last prompt to write is the task prioritization prompt.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div><div class=\"jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs  \">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\">\n<div class=\"jp-InputPrompt jp-InputArea-prompt\">In&nbsp;[&nbsp;]:<\/div>\n<div class=\"jp-CodeMirrorEditor jp-Editor jp-InputArea-editor\" data-type=\"inline\">\n     <div class=\"CodeMirror cm-s-jupyter\">\n<div class=\" highlight hl-ipython3\"><pre><span><\/span><span class=\"n\">prioritization_prompt<\/span> <span class=\"o\">=<\/span> <span class=\"n\">guidance<\/span><span class=\"p\">(<\/span><span class=\"s2\">\"\"\"<\/span>\n<span class=\"s2\">{{#system~}}<\/span>\n<span class=\"s2\">{{llm.default_system_prompt}}<\/span>\n<span class=\"s2\">{{~\/system}}<\/span>\n\n<span class=\"s2\">{{#user~}}<\/span>\n<span class=\"s2\">You are a task prioritization AI tasked with cleaning the formatting of and reprioritizing the following tasks: {{task_names}}.<\/span>\n<span class=\"s2\">Consider the ultimate objective of your team: {{objective}}.<\/span>\n<span class=\"s2\">Do not remove any tasks. Return the result as a numbered list, like:<\/span>\n<span class=\"s2\">#. First task<\/span>\n<span class=\"s2\">#. Second task<\/span>\n<span class=\"s2\">Start the task list with number {{next_task_id}}.<\/span>\n<span class=\"s2\">{{~\/user}}<\/span>\n\n<span class=\"s2\">{{#assistant~}}<\/span>\n<span class=\"s2\">{{#geneach 'tasks'}}{{#if (equal @index last_task_index)}}{{break}}{{\/if}}{{add @index next_task_id}}. {{gen 'this' stop=\"<\/span><span class=\"se\">\\\\<\/span><span class=\"s2\">n\"}}<\/span>\n<span class=\"s2\">{{\/geneach}}<\/span>\n<span class=\"s2\">{{~\/assistant~}}<\/span>\n<span class=\"s2\">\"\"\"<\/span><span class=\"p\">)<\/span>\n<\/pre><\/div>\n\n     <\/div>\n<\/div>\n<\/div>\n<\/div>\n\n<\/div>\n<div class=\"jp-Cell jp-MarkdownCell jp-Notebook-cell\">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\"><div class=\"jp-InputPrompt jp-InputArea-prompt\">\n<\/div><div class=\"jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput \" data-mime-type=\"text\/markdown\">\n<p>In the task creation prompt we asked the model to output the tasks as a JSON array.\nNow we&#8217;ll try a harder use case: an ordered numerical list starting with some arbitrary number.<\/p>\n<p>Based on experience, the model often hallucinates here and invents new tasks or repeats them.\nHowever, we want it to simply re-order the exisiting tasks.\nWhile this could be solved with a redesigned prompt or a more aligned model, we can also use the <code>if<\/code> command to control the number of tasks that can be outputted and stop after a predetermined number.<\/p>\n<p>Here, we compare the special <code>@index<\/code> of the current task being generated (a magic number updated by Guidance after each loop) and <code>break<\/code> out if it&#8217;s equal to the number of tasks we know we passed in.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div><div class=\"jp-Cell jp-CodeCell jp-Notebook-cell   \">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\">\n<div class=\"jp-InputPrompt jp-InputArea-prompt\">In&nbsp;[&nbsp;]:<\/div>\n<div class=\"jp-CodeMirrorEditor jp-Editor jp-InputArea-editor\" data-type=\"inline\">\n     <div class=\"CodeMirror cm-s-jupyter\">\n<div class=\" highlight hl-ipython3\"><pre><span><\/span><span class=\"k\">def<\/span> <span class=\"nf\">prioritize_tasks<\/span><span class=\"p\">(<\/span><span class=\"n\">this_task_id<\/span><span class=\"p\">,<\/span> <span class=\"n\">task_list<\/span><span class=\"p\">,<\/span> <span class=\"n\">objective<\/span><span class=\"p\">):<\/span>\n    <span class=\"n\">task_names<\/span> <span class=\"o\">=<\/span> <span class=\"p\">[<\/span><span class=\"n\">t<\/span><span class=\"p\">[<\/span><span class=\"s2\">\"task_name\"<\/span><span class=\"p\">]<\/span> <span class=\"k\">for<\/span> <span class=\"n\">t<\/span> <span class=\"ow\">in<\/span> <span class=\"n\">task_list<\/span><span class=\"p\">]<\/span>\n    <span class=\"n\">next_task_id<\/span> <span class=\"o\">=<\/span> <span class=\"nb\">int<\/span><span class=\"p\">(<\/span><span class=\"n\">this_task_id<\/span><span class=\"p\">)<\/span> <span class=\"o\">+<\/span> <span class=\"mi\">1<\/span>\n    <span class=\"n\">response<\/span> <span class=\"o\">=<\/span> <span class=\"n\">prioritization_prompt<\/span><span class=\"p\">(<\/span>\n        <span class=\"n\">task_names<\/span><span class=\"o\">=<\/span><span class=\"n\">task_names<\/span><span class=\"p\">,<\/span>\n        <span class=\"n\">next_task_id<\/span><span class=\"o\">=<\/span><span class=\"n\">next_task_id<\/span><span class=\"p\">,<\/span>\n        <span class=\"n\">objective<\/span><span class=\"o\">=<\/span><span class=\"n\">objective<\/span><span class=\"p\">,<\/span>\n        <span class=\"n\">last_task_index<\/span><span class=\"o\">=<\/span><span class=\"nb\">len<\/span><span class=\"p\">(<\/span><span class=\"n\">task_names<\/span><span class=\"p\">)<\/span> <span class=\"o\">-<\/span> <span class=\"mi\">1<\/span><span class=\"p\">,<\/span>\n        <span class=\"n\">llm<\/span><span class=\"o\">=<\/span><span class=\"n\">llm<\/span>\n    <span class=\"p\">)<\/span>\n    <span class=\"k\">return<\/span> <span class=\"p\">[<\/span>\n        <span class=\"p\">{<\/span><span class=\"s2\">\"task_id\"<\/span><span class=\"p\">:<\/span> <span class=\"n\">task_id<\/span><span class=\"p\">,<\/span> <span class=\"s2\">\"task_name\"<\/span><span class=\"p\">:<\/span> <span class=\"n\">task_name<\/span><span class=\"p\">}<\/span> \n            <span class=\"k\">for<\/span> <span class=\"n\">task_id<\/span><span class=\"p\">,<\/span> <span class=\"n\">task_name<\/span> <span class=\"ow\">in<\/span> \n                <span class=\"nb\">zip<\/span><span class=\"p\">(<\/span><span class=\"nb\">range<\/span><span class=\"p\">(<\/span><span class=\"n\">next_task_id<\/span><span class=\"p\">,<\/span> <span class=\"n\">next_task_id<\/span><span class=\"o\">+<\/span><span class=\"nb\">len<\/span><span class=\"p\">(<\/span><span class=\"n\">task_list<\/span><span class=\"p\">)),<\/span> <span class=\"n\">response<\/span><span class=\"p\">[<\/span><span class=\"s2\">\"tasks\"<\/span><span class=\"p\">])<\/span>\n    <span class=\"p\">]<\/span>\n\n<span class=\"n\">sample_prioritized_tasks<\/span> <span class=\"o\">=<\/span> <span class=\"n\">prioritize_tasks<\/span><span class=\"p\">(<\/span>\n    <span class=\"n\">this_task_id<\/span><span class=\"o\">=<\/span><span class=\"mi\">1<\/span><span class=\"p\">,<\/span>\n    <span class=\"n\">task_list<\/span><span class=\"o\">=<\/span><span class=\"n\">sample_created_tasks<\/span><span class=\"p\">,<\/span>\n    <span class=\"n\">objective<\/span><span class=\"o\">=<\/span><span class=\"n\">sample_objective<\/span><span class=\"p\">,<\/span>\n<span class=\"p\">)<\/span>\n<span class=\"n\">sample_prioritized_tasks<\/span>\n<\/pre><\/div>\n\n     <\/div>\n<\/div>\n<\/div>\n<\/div>\n\n<div class=\"jp-Cell-outputWrapper\">\n<div class=\"jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser\">\n<\/div>\n\n\n<div class=\"jp-OutputArea jp-Cell-outputArea\">\n<div class=\"jp-OutputArea-child\">\n    \n    <div class=\"jp-OutputPrompt jp-OutputArea-prompt\"><\/div>\n\n\n\n<div class=\"jp-RenderedHTMLCommon jp-RenderedHTML jp-OutputArea-output \" data-mime-type=\"text\/html\">\n<div id=\"guidance-stop-button-a5a1b34d-2c1b-4960-ae43-0467b29085b9\" style=\"cursor: pointer; margin: 0px; display: none; float: right; padding: 3px; border-radius: 4px 4px 4px 4px; border: 0px solid rgba(127, 127, 127, 1); padding-left: 10px; padding-right: 10px; font-size: 13px; background-color: rgba(127, 127, 127, 0.25);\">Stop program<\/div><div id=\"guidance-content-a5a1b34d-2c1b-4960-ae43-0467b29085b9\"><pre style=\"margin: 0px; padding: 0px; padding-left: 8px; margin-left: -8px; border-radius: 0px; border-left: 1px solid rgba(127, 127, 127, 0.2); white-space: pre-wrap; font-family: ColfaxAI, Arial; font-size: 15px; line-height: 23px;\"><div style=\"display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;\"><div style=\"flex: 0 0 80px; opacity: 0.5;\">system<\/div><div style=\"flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;\"><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{llm.default_system_prompt}}\">A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.<\/span><\/div><\/div><div style=\"display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;\"><div style=\"flex: 0 0 80px; opacity: 0.5;\">user<\/div><div style=\"flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;\">You are a task prioritization AI tasked with cleaning the formatting of and reprioritizing the following tasks: <span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{task_names}}\">['Write a clear and concise weather report for San Francisco based on the data gathered and analysis completed.', 'Include any relevant information about the forecast for the rest of the day and any potential weather-related hazards or concerns.', 'Organize the information in a logical and easy-to-understand format.', 'Review and edit the weather report for accuracy and clarity.', 'Present the weather report in a professional and engaging manner.']<\/span>.\nConsider the ultimate objective of your team: <span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{objective}}\">Write a weather report for SF today<\/span>.\nDo not remove any tasks. Return the result as a numbered list, like:\n#. First task\n#. Second task\nStart the task list with number <span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{next_task_id}}\">2<\/span>.<\/div><\/div><div style=\"display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;\"><div style=\"flex: 0 0 80px; opacity: 0.5;\">assistant<\/div><div style=\"flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;\"><span style=\"opacity: 1.0; display: inline; background-color: rgba(165, 165, 165, 0.1);\" title=\"{{#geneach 'tasks'}}{{#if (equal @index last_task_index)}}{{break}}{{\/if}}{{add @index next_task_id}}. {{gen 'this' stop=&quot;\\n&quot;}}\n{{\/geneach}}\"><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#if (equal @index last_task_index)}}{{break}}{{\/if}}\"><\/span><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{add @index next_task_id}}\">2<\/span>. <span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this' stop=&quot;\\n&quot;}}\">Review and edit the weather report for accuracy and clarity.<\/span>\n<span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#if (equal @index last_task_index)}}{{break}}{{\/if}}\"><\/span><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{add @index next_task_id}}\">3<\/span>. <span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this' stop=&quot;\\n&quot;}}\">Organize the information in a logical and easy-to-understand format.<\/span>\n<span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#if (equal @index last_task_index)}}{{break}}{{\/if}}\"><\/span><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{add @index next_task_id}}\">4<\/span>. <span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this' stop=&quot;\\n&quot;}}\">Present the weather report in a professional and engaging manner.<\/span>\n<span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#if (equal @index last_task_index)}}{{break}}{{\/if}}\"><\/span><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{add @index next_task_id}}\">5<\/span>. <span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this' stop=&quot;\\n&quot;}}\">Write a clear and concise weather report for San Francisco based on the data gathered and analysis completed.<\/span>\n<span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#if (equal @index last_task_index)}}{{break}}{{\/if}}\"><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{break}}\"><\/span><\/span><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{add @index next_task_id}}\">6<\/span>. <span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this' stop=&quot;\\n&quot;}}\">Include any relevant information about the forecast for the rest of the day and any potential weather-related hazards or concerns.<\/span>\n<\/span><\/div><\/div><\/pre><\/div>\n<script type=\"text\/javascript\">(()=>{var t={296:(t,e,n)=>{var i=NaN,o=\"[object Symbol]\",r=\/^\\s+|\\s+$\/g,a=\/^[-+]0x[0-9a-f]+$\/i,s=\/^0b[01]+$\/i,c=\/^0o[0-7]+$\/i,d=parseInt,u=\"object\"==typeof n.g&&n.g&&n.g.Object===Object&&n.g,l=\"object\"==typeof self&&self&&self.Object===Object&&self,f=u||l||Function(\"return this\")(),h=Object.prototype.toString,p=Math.max,m=Math.min,g=function(){return f.Date.now()};function b(t){var e=typeof t;return!!t&&(\"object\"==e||\"function\"==e)}function y(t){if(\"number\"==typeof t)return t;if(function(t){return\"symbol\"==typeof t||function(t){return!!t&&\"object\"==typeof t}(t)&&h.call(t)==o}(t))return i;if(b(t)){var e=\"function\"==typeof t.valueOf?t.valueOf():t;t=b(e)?e+\"\":e}if(\"string\"!=typeof t)return 0===t?t:+t;t=t.replace(r,\"\");var n=s.test(t);return n||c.test(t)?d(t.slice(2),n?2:8):a.test(t)?i:+t}t.exports=function(t,e,n){var i,o,r,a,s,c,d=0,u=!1,l=!1,f=!0;if(\"function\"!=typeof t)throw new TypeError(\"Expected a function\");function h(e){var n=i,r=o;return i=o=void 0,d=e,a=t.apply(r,n)}function v(t){var n=t-c;return void 0===c||n>=e||n<0||l&#038;&#038;t-d>=r}function _(){var t=g();if(v(t))return w(t);s=setTimeout(_,function(t){var n=e-(t-c);return l?m(n,r-(t-d)):n}(t))}function w(t){return s=void 0,f&&i?h(t):(i=o=void 0,a)}function j(){var t=g(),n=v(t);if(i=arguments,o=this,c=t,n){if(void 0===s)return function(t){return d=t,s=setTimeout(_,e),u?h(t):a}(c);if(l)return s=setTimeout(_,e),h(c)}return void 0===s&&(s=setTimeout(_,e)),a}return e=y(e)||0,b(n)&&(u=!!n.leading,r=(l=\"maxWait\"in n)?p(y(n.maxWait)||0,e):r,f=\"trailing\"in n?!!n.trailing:f),j.cancel=function(){void 0!==s&&clearTimeout(s),d=0,i=c=o=s=void 0},j.flush=function(){return void 0===s?a:w(g())},j}},777:t=>{var e,n,i=Math.max,o=(e=function(t,e){return function(t,e,n){if(\"function\"!=typeof t)throw new TypeError(\"Expected a function\");return setTimeout((function(){t.apply(void 0,n)}),1)}(t,0,e)},n=i(void 0===n?e.length-1:n,0),function(){for(var t=arguments,o=-1,r=i(t.length-n,0),a=Array(r);++o<r;)a[o]=t[n+o];o=-1;for(var s=Array(n+1);++o<n;)s[o]=t[o];return s[n]=a,function(t,e,n){switch(n.length){case 0:return t.call(e);case 1:return t.call(e,n[0]);case 2:return t.call(e,n[0],n[1]);case 3:return t.call(e,n[0],n[1],n[2])}return t.apply(e,n)}(e,this,s)});t.exports=o}},e={};function n(i){var o=e[i];if(void 0!==o)return o.exports;var r=e[i]={exports:{}};return t[i](r,r.exports,n),r.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.g=function(){if(\"object\"==typeof globalThis)return globalThis;try{return this||new Function(\"return this\")()}catch(t){if(\"object\"==typeof window)return window}}(),n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),(()=>{\"use strict\";const t=t=>{const e=new Set;do{for(const n of Reflect.ownKeys(t))e.add([t,n])}while((t=Reflect.getPrototypeOf(t))&&t!==Object.prototype);return e};function e(e,{include:n,exclude:i}={}){const o=t=>{const e=e=>\"string\"==typeof e?t===e:e.test(t);return n?n.some(e):!i||!i.some(e)};for(const[n,i]of t(e.constructor.prototype)){if(\"constructor\"===i||!o(i))continue;const t=Reflect.getOwnPropertyDescriptor(n,i);t&&\"function\"==typeof t.value&&(e[i]=e[i].bind(e))}return e}var i=n(777),o=n.n(i),r=n(296),a=n.n(r);class s{constructor(t,n){e(this),this.interfaceId=t,this.callbackMap={},this.data={},this.pendingData={},this.jcomm=new c(\"guidance_interface_target_\"+this.interfaceId,this.updateData,\"open\"),this.debouncedSendPendingData500=a()(this.sendPendingData,500),this.debouncedSendPendingData1000=a()(this.sendPendingData,1e3),n&&o()(n)}send(t,e){this.addPendingData(t,e),this.sendPendingData()}sendEvent(t){for(const e of Object.keys(t))this.addPendingData(e,t[e]);this.sendPendingData()}debouncedSendEvent500(t){for(const e of Object.keys(t))this.addPendingData(e,t[e]);this.debouncedSendPendingData500()}debouncedSend500(t,e){this.addPendingData(t,e),this.debouncedSendPendingData500()}debouncedSend1000(t,e){this.addPendingData(t,e),this.debouncedSendPendingData1000()}addPendingData(t,e){Array.isArray(t)||(t=[t]);for(const n in t)this.pendingData[t[n]]=e}updateData(t){t=JSON.parse(t.data);for(const e in t)this.data[e]=t[e];for(const e in t)e in this.callbackMap&&this.callbackMap[e](this.data[e])}subscribe(t,e){this.callbackMap[t]=e,o()((e=>this.callbackMap[t](this.data[t])))}sendPendingData(){this.jcomm.send_data(this.pendingData),this.pendingData={}}}class c{constructor(t,e,n=\"open\"){this._fire_callback=this._fire_callback.bind(this),this._register=this._register.bind(this),this.jcomm=void 0,this.callback=e,void 0!==window.Jupyter?\"register\"===n?Jupyter.notebook.kernel.comm_manager.register_target(t,this._register):(this.jcomm=Jupyter.notebook.kernel.comm_manager.new_comm(t),this.jcomm.on_msg(this._fire_callback)):void 0!==window._mgr&&(\"register\"===n?window._mgr.widgetManager.proxyKernel.registerCommTarget(t,this._register):(this.jcomm=window._mgr.widgetManager.proxyKernel.createComm(t),this.jcomm.open({},\"\"),this.jcomm.onMsg=this._fire_callback))}send_data(t){void 0!==this.jcomm?this.jcomm.send(t):console.error(\"Jupyter comm module not yet loaded! So we can't send the message.\")}_register(t,e){this.jcomm=t,this.jcomm.on_msg(this._fire_callback)}_fire_callback(t){this.callback(t.content.data)}}class d{constructor(t,n){e(this),this.id=t,this.comm=new s(t),this.comm.subscribe(\"append\",this.appendData),this.comm.subscribe(\"replace\",this.replaceData),this.comm.subscribe(\"event\",this.eventOccurred),this.element=document.getElementById(\"guidance-content-\"+t),this.stop_button=document.getElementById(\"guidance-stop-button-\"+t),this.stop_button.onclick=()=>this.comm.send(\"event\",\"stop\")}appendData(t){t&&(this.stop_button.style.display=\"inline-block\",this.element.innerHTML+=t)}replaceData(t){t&&(this.stop_button.style.display=\"inline-block\",this.element.innerHTML=t)}eventOccurred(t){\"complete\"===t&&(this.stop_button.style.display=\"none\")}}window._guidanceDisplay=function(t,e){return new d(t,e)}})()})();; window._guidanceDisplay(\"a5a1b34d-2c1b-4960-ae43-0467b29085b9\");<\/script>\n<\/div>\n\n<\/div>\n<div class=\"jp-OutputArea-child jp-OutputArea-executeResult\">\n    \n    <div class=\"jp-OutputPrompt jp-OutputArea-prompt\">Out[&nbsp;]:<\/div>\n\n\n\n\n<div class=\"jp-RenderedText jp-OutputArea-output jp-OutputArea-executeResult\" data-mime-type=\"text\/plain\">\n<pre>[{'task_id': 2,\n  'task_name': 'Review and edit the weather report for accuracy and clarity.'},\n {'task_id': 3,\n  'task_name': 'Organize the information in a logical and easy-to-understand format.'},\n {'task_id': 4,\n  'task_name': 'Present the weather report in a professional and engaging manner.'},\n {'task_id': 5,\n  'task_name': 'Write a clear and concise weather report for San Francisco based on the data gathered and analysis completed.'},\n {'task_id': 6,\n  'task_name': 'Include any relevant information about the forecast for the rest of the day and any potential weather-related hazards or concerns.'}]<\/pre>\n<\/div>\n\n<\/div>\n\n<\/div>\n\n<\/div>\n\n<\/div>\n<div class=\"jp-Cell jp-MarkdownCell jp-Notebook-cell\">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\"><div class=\"jp-InputPrompt jp-InputArea-prompt\">\n<\/div><div class=\"jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput \" data-mime-type=\"text\/markdown\">\n<p>Now it&#8217;s time for the full BabyAGI procedure.\nIt may be helpful to refer back to the diagram that shows the flow of logic, but essentially it&#8217;s our three prompts being run in succession.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div><div class=\"jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs  \">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\">\n<div class=\"jp-InputPrompt jp-InputArea-prompt\">In&nbsp;[&nbsp;]:<\/div>\n<div class=\"jp-CodeMirrorEditor jp-Editor jp-InputArea-editor\" data-type=\"inline\">\n     <div class=\"CodeMirror cm-s-jupyter\">\n<div class=\" highlight hl-ipython3\"><pre><span><\/span><span class=\"kn\">from<\/span> <span class=\"nn\">collections<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">deque<\/span>\n\n<span class=\"k\">def<\/span> <span class=\"nf\">babyagi<\/span><span class=\"p\">(<\/span><span class=\"n\">objective<\/span><span class=\"p\">,<\/span> <span class=\"n\">max_iterations<\/span><span class=\"o\">=<\/span><span class=\"mi\">5<\/span><span class=\"p\">):<\/span>\n    <span class=\"n\">task_list<\/span> <span class=\"o\">=<\/span> <span class=\"n\">deque<\/span><span class=\"p\">([{<\/span>\n        <span class=\"s2\">\"task_id\"<\/span><span class=\"p\">:<\/span> <span class=\"mi\">1<\/span><span class=\"p\">,<\/span>\n        <span class=\"s2\">\"task_name\"<\/span><span class=\"p\">:<\/span> <span class=\"n\">FIRST_TASK<\/span>\n    <span class=\"p\">}])<\/span>\n    <span class=\"n\">task_id_counter<\/span> <span class=\"o\">=<\/span> <span class=\"mi\">1<\/span>\n    <span class=\"n\">vectorstore<\/span> <span class=\"o\">=<\/span> <span class=\"n\">make_vectorstore<\/span><span class=\"p\">()<\/span>\n\n    <span class=\"k\">while<\/span> <span class=\"n\">max_iterations<\/span> <span class=\"ow\">is<\/span> <span class=\"kc\">None<\/span> <span class=\"ow\">or<\/span> <span class=\"n\">max_iterations<\/span> <span class=\"o\">&gt;<\/span> <span class=\"mi\">0<\/span><span class=\"p\">:<\/span>\n        <span class=\"k\">if<\/span> <span class=\"n\">task_list<\/span><span class=\"p\">:<\/span>\n\n            <span class=\"c1\"># Step 1: Pull the first task<\/span>\n            <span class=\"n\">task<\/span> <span class=\"o\">=<\/span> <span class=\"n\">task_list<\/span><span class=\"o\">.<\/span><span class=\"n\">popleft<\/span><span class=\"p\">()<\/span>\n\n            <span class=\"c1\"># Step 2: Execute the task<\/span>\n            <span class=\"n\">result<\/span> <span class=\"o\">=<\/span> <span class=\"n\">execute_task<\/span><span class=\"p\">(<\/span>\n                <span class=\"n\">vectorstore<\/span><span class=\"o\">=<\/span><span class=\"n\">vectorstore<\/span><span class=\"p\">,<\/span>\n                <span class=\"n\">objective<\/span><span class=\"o\">=<\/span><span class=\"n\">objective<\/span><span class=\"p\">,<\/span>\n                <span class=\"n\">task<\/span><span class=\"o\">=<\/span><span class=\"n\">task<\/span><span class=\"p\">[<\/span><span class=\"s2\">\"task_name\"<\/span><span class=\"p\">]<\/span>\n            <span class=\"p\">)<\/span>\n            <span class=\"n\">this_task_id<\/span> <span class=\"o\">=<\/span> <span class=\"nb\">int<\/span><span class=\"p\">(<\/span><span class=\"n\">task<\/span><span class=\"p\">[<\/span><span class=\"s2\">\"task_id\"<\/span><span class=\"p\">])<\/span>\n\n            <span class=\"c1\"># Step 3: Store the result<\/span>\n            <span class=\"n\">result_id<\/span> <span class=\"o\">=<\/span> <span class=\"sa\">f<\/span><span class=\"s2\">\"result_<\/span><span class=\"si\">{<\/span><span class=\"n\">task<\/span><span class=\"p\">[<\/span><span class=\"s1\">'task_id'<\/span><span class=\"p\">]<\/span><span class=\"si\">}<\/span><span class=\"s2\">\"<\/span>\n            <span class=\"n\">vectorstore<\/span><span class=\"o\">.<\/span><span class=\"n\">add_texts<\/span><span class=\"p\">(<\/span>\n                <span class=\"n\">texts<\/span><span class=\"o\">=<\/span><span class=\"p\">[<\/span><span class=\"n\">result<\/span><span class=\"p\">],<\/span>\n                <span class=\"n\">metadatas<\/span><span class=\"o\">=<\/span><span class=\"p\">[{<\/span><span class=\"s2\">\"task\"<\/span><span class=\"p\">:<\/span> <span class=\"n\">task<\/span><span class=\"p\">[<\/span><span class=\"s2\">\"task_name\"<\/span><span class=\"p\">]}],<\/span>\n                <span class=\"n\">ids<\/span><span class=\"o\">=<\/span><span class=\"p\">[<\/span><span class=\"n\">result_id<\/span><span class=\"p\">],<\/span>\n            <span class=\"p\">)<\/span>\n\n            <span class=\"c1\"># Step 4: Create new tasks<\/span>\n            <span class=\"n\">new_tasks<\/span> <span class=\"o\">=<\/span> <span class=\"n\">create_tasks<\/span><span class=\"p\">(<\/span>\n                    <span class=\"n\">result<\/span><span class=\"o\">=<\/span><span class=\"n\">result<\/span><span class=\"p\">,<\/span>\n                    <span class=\"n\">task_description<\/span><span class=\"o\">=<\/span><span class=\"n\">task<\/span><span class=\"p\">[<\/span><span class=\"s2\">\"task_name\"<\/span><span class=\"p\">],<\/span>\n                    <span class=\"n\">task_list<\/span><span class=\"o\">=<\/span><span class=\"p\">[<\/span><span class=\"n\">t<\/span><span class=\"p\">[<\/span><span class=\"s2\">\"task_name\"<\/span><span class=\"p\">]<\/span> <span class=\"k\">for<\/span> <span class=\"n\">t<\/span> <span class=\"ow\">in<\/span> <span class=\"n\">task_list<\/span><span class=\"p\">],<\/span>\n                    <span class=\"n\">objective<\/span><span class=\"o\">=<\/span><span class=\"n\">objective<\/span><span class=\"p\">,<\/span>\n                <span class=\"p\">)<\/span>\n            <span class=\"k\">for<\/span> <span class=\"n\">new_task<\/span> <span class=\"ow\">in<\/span> <span class=\"n\">new_tasks<\/span><span class=\"p\">:<\/span>\n                <span class=\"n\">task_id_counter<\/span> <span class=\"o\">+=<\/span> <span class=\"mi\">1<\/span>\n                <span class=\"n\">new_task<\/span><span class=\"o\">.<\/span><span class=\"n\">update<\/span><span class=\"p\">({<\/span><span class=\"s2\">\"task_id\"<\/span><span class=\"p\">:<\/span> <span class=\"n\">task_id_counter<\/span><span class=\"p\">})<\/span>\n                <span class=\"n\">task_list<\/span><span class=\"o\">.<\/span><span class=\"n\">append<\/span><span class=\"p\">(<\/span><span class=\"n\">new_task<\/span><span class=\"p\">)<\/span>\n\n            <span class=\"c1\"># Step 5: Reprioritize task list<\/span>\n            <span class=\"n\">task_list<\/span> <span class=\"o\">=<\/span> <span class=\"n\">deque<\/span><span class=\"p\">(<\/span>\n                <span class=\"n\">prioritize_tasks<\/span><span class=\"p\">(<\/span>\n                    <span class=\"n\">this_task_id<\/span><span class=\"p\">,<\/span>\n                    <span class=\"nb\">list<\/span><span class=\"p\">(<\/span><span class=\"n\">task_list<\/span><span class=\"p\">),<\/span>\n                    <span class=\"n\">objective<\/span><span class=\"p\">,<\/span>\n                <span class=\"p\">)<\/span>\n            <span class=\"p\">)<\/span>\n        <span class=\"n\">max_iterations<\/span> <span class=\"o\">=<\/span> <span class=\"kc\">None<\/span> <span class=\"k\">if<\/span> <span class=\"n\">max_iterations<\/span> <span class=\"ow\">is<\/span> <span class=\"kc\">None<\/span> <span class=\"k\">else<\/span> <span class=\"n\">max_iterations<\/span> <span class=\"o\">-<\/span> <span class=\"mi\">1<\/span>\n\n    <span class=\"k\">return<\/span> <span class=\"n\">result<\/span>\n<\/pre><\/div>\n\n     <\/div>\n<\/div>\n<\/div>\n<\/div>\n\n<\/div><div class=\"jp-Cell jp-CodeCell jp-Notebook-cell   \">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\">\n<div class=\"jp-InputPrompt jp-InputArea-prompt\">In&nbsp;[&nbsp;]:<\/div>\n<div class=\"jp-CodeMirrorEditor jp-Editor jp-InputArea-editor\" data-type=\"inline\">\n     <div class=\"CodeMirror cm-s-jupyter\">\n<div class=\" highlight hl-ipython3\"><pre><span><\/span><span class=\"n\">babyagi<\/span><span class=\"p\">(<\/span><span class=\"s2\">\"Write a weather report for Detroit today\"<\/span><span class=\"p\">,<\/span> <span class=\"n\">max_iterations<\/span><span class=\"o\">=<\/span><span class=\"mi\">4<\/span><span class=\"p\">)<\/span>\n<\/pre><\/div>\n\n     <\/div>\n<\/div>\n<\/div>\n<\/div>\n\n<div class=\"jp-Cell-outputWrapper\">\n<div class=\"jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser\">\n<\/div>\n\n\n<div class=\"jp-OutputArea jp-Cell-outputArea\">\n<div class=\"jp-OutputArea-child\">\n    \n    <div class=\"jp-OutputPrompt jp-OutputArea-prompt\"><\/div>\n\n\n\n<div class=\"jp-RenderedHTMLCommon jp-RenderedHTML jp-OutputArea-output \" data-mime-type=\"text\/html\">\n<div id=\"guidance-stop-button-490a6f44-ab86-4ac5-a85b-93e5155b7ac1\" style=\"cursor: pointer; margin: 0px; display: none; float: right; padding: 3px; border-radius: 4px 4px 4px 4px; border: 0px solid rgba(127, 127, 127, 1); padding-left: 10px; padding-right: 10px; font-size: 13px; background-color: rgba(127, 127, 127, 0.25);\">Stop program<\/div><div id=\"guidance-content-490a6f44-ab86-4ac5-a85b-93e5155b7ac1\"><pre style=\"margin: 0px; padding: 0px; padding-left: 8px; margin-left: -8px; border-radius: 0px; border-left: 1px solid rgba(127, 127, 127, 0.2); white-space: pre-wrap; font-family: ColfaxAI, Arial; font-size: 15px; line-height: 23px;\"><div style=\"display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;\"><div style=\"flex: 0 0 80px; opacity: 0.5;\">system<\/div><div style=\"flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;\"><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{llm.default_system_prompt}}\">A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.<\/span><\/div><\/div><div style=\"display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;\"><div style=\"flex: 0 0 80px; opacity: 0.5;\">user<\/div><div style=\"flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;\">You are a task prioritization AI tasked with cleaning the formatting of and reprioritizing the following tasks: <span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{task_names}}\">['Make any necessary updates to the report based on new data or changes in the weather conditions', 'Ensure the report is accurate and up-to-date', 'Evaluate the effectiveness of the written report and visual graphic in conveying the weather information to the audience', 'Analyze the gathered weather data to determine the current weather conditions', 'Write a clear and concise weather report for Detroit, including temperature, precipitation, wind speed and direction, and any other relevant information', 'Determine the current weather conditions in Detroit', 'Write a clear and concise weather report for Detroit, including temperature, precipitation, wind speed and direction, and any other relevant information', 'Prioritize the tasks based on their importance and urgency to achieve the ultimate objective of writing a weather report for Detroit today.', 'Execute the tasks in the order of priority.']<\/span>.\nConsider the ultimate objective of your team: <span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{objective}}\">Write a weather report for Detroit today<\/span>.\nDo not remove any tasks. Return the result as a numbered list, like:\n#. First task\n#. Second task\nStart the task list with number <span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{next_task_id}}\">5<\/span>.<\/div><\/div><div style=\"display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;\"><div style=\"flex: 0 0 80px; opacity: 0.5;\">assistant<\/div><div style=\"flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;\"><span style=\"opacity: 1.0; display: inline; background-color: rgba(165, 165, 165, 0.1);\" title=\"{{#geneach 'tasks'}}{{#if (equal @index last_task_index)}}{{break}}{{\/if}}{{add @index next_task_id}}. {{gen 'this' stop=&quot;\\n&quot;}}\n{{\/geneach}}\"><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#if (equal @index last_task_index)}}{{break}}{{\/if}}\"><\/span><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{add @index next_task_id}}\">5<\/span>. <span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this' stop=&quot;\\n&quot;}}\">Prioritize the tasks based on their importance and urgency to achieve the ultimate objective of writing a weather report for Detroit today.<\/span>\n<span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#if (equal @index last_task_index)}}{{break}}{{\/if}}\"><\/span><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{add @index next_task_id}}\">6<\/span>. <span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this' stop=&quot;\\n&quot;}}\">Execute the tasks in the order of priority.<\/span>\n<span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#if (equal @index last_task_index)}}{{break}}{{\/if}}\"><\/span><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{add @index next_task_id}}\">7<\/span>. <span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this' stop=&quot;\\n&quot;}}\">Write a clear and concise weather report for Detroit, including temperature, precipitation, wind speed and direction, and any other relevant information.<\/span>\n<span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#if (equal @index last_task_index)}}{{break}}{{\/if}}\"><\/span><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{add @index next_task_id}}\">8<\/span>. <span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this' stop=&quot;\\n&quot;}}\">Determine the current weather conditions in Detroit.<\/span>\n<span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#if (equal @index last_task_index)}}{{break}}{{\/if}}\"><\/span><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{add @index next_task_id}}\">9<\/span>. <span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this' stop=&quot;\\n&quot;}}\">Evaluate the effectiveness of the written report and visual graphic in conveying the weather information to the audience.<\/span>\n<span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#if (equal @index last_task_index)}}{{break}}{{\/if}}\"><\/span><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{add @index next_task_id}}\">10<\/span>. <span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this' stop=&quot;\\n&quot;}}\">Make any necessary updates to the report based on new data or changes in the weather conditions.<\/span>\n<span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#if (equal @index last_task_index)}}{{break}}{{\/if}}\"><\/span><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{add @index next_task_id}}\">11<\/span>. <span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this' stop=&quot;\\n&quot;}}\">Analyze the gathered weather data to determine the current weather conditions.<\/span>\n<span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#if (equal @index last_task_index)}}{{break}}{{\/if}}\"><\/span><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{add @index next_task_id}}\">12<\/span>. <span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this' stop=&quot;\\n&quot;}}\">Ensure the report is accurate and up-to-date.<\/span>\n<span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{#if (equal @index last_task_index)}}{{break}}{{\/if}}\"><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{break}}\"><\/span><\/span><span style=\"background-color: rgba(0, 138.56128016, 250.76166089, 0.25); display: inline;\" title=\"{{add @index next_task_id}}\">13<\/span>. <span style=\"background-color: rgba(0, 165, 0, 0.25); opacity: 1.0; display: inline;\" title=\"{{gen 'this' stop=&quot;\\n&quot;}}\">Write a clear and concise weather report for Detroit, including temperature, precipitation, wind speed and direction, and any other relevant information.<\/span>\n<\/span><\/div><\/div><\/pre><\/div>\n<script type=\"text\/javascript\">(()=>{var t={296:(t,e,n)=>{var i=NaN,o=\"[object Symbol]\",r=\/^\\s+|\\s+$\/g,a=\/^[-+]0x[0-9a-f]+$\/i,s=\/^0b[01]+$\/i,c=\/^0o[0-7]+$\/i,d=parseInt,u=\"object\"==typeof n.g&&n.g&&n.g.Object===Object&&n.g,l=\"object\"==typeof self&&self&&self.Object===Object&&self,f=u||l||Function(\"return this\")(),h=Object.prototype.toString,p=Math.max,m=Math.min,g=function(){return f.Date.now()};function b(t){var e=typeof t;return!!t&&(\"object\"==e||\"function\"==e)}function y(t){if(\"number\"==typeof t)return t;if(function(t){return\"symbol\"==typeof t||function(t){return!!t&&\"object\"==typeof t}(t)&&h.call(t)==o}(t))return i;if(b(t)){var e=\"function\"==typeof t.valueOf?t.valueOf():t;t=b(e)?e+\"\":e}if(\"string\"!=typeof t)return 0===t?t:+t;t=t.replace(r,\"\");var n=s.test(t);return n||c.test(t)?d(t.slice(2),n?2:8):a.test(t)?i:+t}t.exports=function(t,e,n){var i,o,r,a,s,c,d=0,u=!1,l=!1,f=!0;if(\"function\"!=typeof t)throw new TypeError(\"Expected a function\");function h(e){var n=i,r=o;return i=o=void 0,d=e,a=t.apply(r,n)}function v(t){var n=t-c;return void 0===c||n>=e||n<0||l&#038;&#038;t-d>=r}function _(){var t=g();if(v(t))return w(t);s=setTimeout(_,function(t){var n=e-(t-c);return l?m(n,r-(t-d)):n}(t))}function w(t){return s=void 0,f&&i?h(t):(i=o=void 0,a)}function j(){var t=g(),n=v(t);if(i=arguments,o=this,c=t,n){if(void 0===s)return function(t){return d=t,s=setTimeout(_,e),u?h(t):a}(c);if(l)return s=setTimeout(_,e),h(c)}return void 0===s&&(s=setTimeout(_,e)),a}return e=y(e)||0,b(n)&&(u=!!n.leading,r=(l=\"maxWait\"in n)?p(y(n.maxWait)||0,e):r,f=\"trailing\"in n?!!n.trailing:f),j.cancel=function(){void 0!==s&&clearTimeout(s),d=0,i=c=o=s=void 0},j.flush=function(){return void 0===s?a:w(g())},j}},777:t=>{var e,n,i=Math.max,o=(e=function(t,e){return function(t,e,n){if(\"function\"!=typeof t)throw new TypeError(\"Expected a function\");return setTimeout((function(){t.apply(void 0,n)}),1)}(t,0,e)},n=i(void 0===n?e.length-1:n,0),function(){for(var t=arguments,o=-1,r=i(t.length-n,0),a=Array(r);++o<r;)a[o]=t[n+o];o=-1;for(var s=Array(n+1);++o<n;)s[o]=t[o];return s[n]=a,function(t,e,n){switch(n.length){case 0:return t.call(e);case 1:return t.call(e,n[0]);case 2:return t.call(e,n[0],n[1]);case 3:return t.call(e,n[0],n[1],n[2])}return t.apply(e,n)}(e,this,s)});t.exports=o}},e={};function n(i){var o=e[i];if(void 0!==o)return o.exports;var r=e[i]={exports:{}};return t[i](r,r.exports,n),r.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.g=function(){if(\"object\"==typeof globalThis)return globalThis;try{return this||new Function(\"return this\")()}catch(t){if(\"object\"==typeof window)return window}}(),n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),(()=>{\"use strict\";const t=t=>{const e=new Set;do{for(const n of Reflect.ownKeys(t))e.add([t,n])}while((t=Reflect.getPrototypeOf(t))&&t!==Object.prototype);return e};function e(e,{include:n,exclude:i}={}){const o=t=>{const e=e=>\"string\"==typeof e?t===e:e.test(t);return n?n.some(e):!i||!i.some(e)};for(const[n,i]of t(e.constructor.prototype)){if(\"constructor\"===i||!o(i))continue;const t=Reflect.getOwnPropertyDescriptor(n,i);t&&\"function\"==typeof t.value&&(e[i]=e[i].bind(e))}return e}var i=n(777),o=n.n(i),r=n(296),a=n.n(r);class s{constructor(t,n){e(this),this.interfaceId=t,this.callbackMap={},this.data={},this.pendingData={},this.jcomm=new c(\"guidance_interface_target_\"+this.interfaceId,this.updateData,\"open\"),this.debouncedSendPendingData500=a()(this.sendPendingData,500),this.debouncedSendPendingData1000=a()(this.sendPendingData,1e3),n&&o()(n)}send(t,e){this.addPendingData(t,e),this.sendPendingData()}sendEvent(t){for(const e of Object.keys(t))this.addPendingData(e,t[e]);this.sendPendingData()}debouncedSendEvent500(t){for(const e of Object.keys(t))this.addPendingData(e,t[e]);this.debouncedSendPendingData500()}debouncedSend500(t,e){this.addPendingData(t,e),this.debouncedSendPendingData500()}debouncedSend1000(t,e){this.addPendingData(t,e),this.debouncedSendPendingData1000()}addPendingData(t,e){Array.isArray(t)||(t=[t]);for(const n in t)this.pendingData[t[n]]=e}updateData(t){t=JSON.parse(t.data);for(const e in t)this.data[e]=t[e];for(const e in t)e in this.callbackMap&&this.callbackMap[e](this.data[e])}subscribe(t,e){this.callbackMap[t]=e,o()((e=>this.callbackMap[t](this.data[t])))}sendPendingData(){this.jcomm.send_data(this.pendingData),this.pendingData={}}}class c{constructor(t,e,n=\"open\"){this._fire_callback=this._fire_callback.bind(this),this._register=this._register.bind(this),this.jcomm=void 0,this.callback=e,void 0!==window.Jupyter?\"register\"===n?Jupyter.notebook.kernel.comm_manager.register_target(t,this._register):(this.jcomm=Jupyter.notebook.kernel.comm_manager.new_comm(t),this.jcomm.on_msg(this._fire_callback)):void 0!==window._mgr&&(\"register\"===n?window._mgr.widgetManager.proxyKernel.registerCommTarget(t,this._register):(this.jcomm=window._mgr.widgetManager.proxyKernel.createComm(t),this.jcomm.open({},\"\"),this.jcomm.onMsg=this._fire_callback))}send_data(t){void 0!==this.jcomm?this.jcomm.send(t):console.error(\"Jupyter comm module not yet loaded! So we can't send the message.\")}_register(t,e){this.jcomm=t,this.jcomm.on_msg(this._fire_callback)}_fire_callback(t){this.callback(t.content.data)}}class d{constructor(t,n){e(this),this.id=t,this.comm=new s(t),this.comm.subscribe(\"append\",this.appendData),this.comm.subscribe(\"replace\",this.replaceData),this.comm.subscribe(\"event\",this.eventOccurred),this.element=document.getElementById(\"guidance-content-\"+t),this.stop_button=document.getElementById(\"guidance-stop-button-\"+t),this.stop_button.onclick=()=>this.comm.send(\"event\",\"stop\")}appendData(t){t&&(this.stop_button.style.display=\"inline-block\",this.element.innerHTML+=t)}replaceData(t){t&&(this.stop_button.style.display=\"inline-block\",this.element.innerHTML=t)}eventOccurred(t){\"complete\"===t&&(this.stop_button.style.display=\"none\")}}window._guidanceDisplay=function(t,e){return new d(t,e)}})()})();; window._guidanceDisplay(\"490a6f44-ab86-4ac5-a85b-93e5155b7ac1\");<\/script>\n<\/div>\n\n<\/div>\n<div class=\"jp-OutputArea-child jp-OutputArea-executeResult\">\n    \n    <div class=\"jp-OutputPrompt jp-OutputArea-prompt\">Out[&nbsp;]:<\/div>\n\n\n\n\n<div class=\"jp-RenderedText jp-OutputArea-output jp-OutputArea-executeResult\" data-mime-type=\"text\/plain\">\n<pre>'Here is the weather report for Detroit:\\n\\nTemperature: The temperature in Detroit today is expected to reach a high of 75 degrees Fahrenheit and a low of 55 degrees Fahrenheit.\\n\\nPrecipitation: There is a chance of scattered thunderstorms throughout the day, with a 30% chance of precipitation.\\n\\nWind: The wind speed in Detroit today is expected to be light, with an average speed of 5-10 miles per hour. The wind is blowing from the southwest.\\n\\nOther relevant information: The humidity in Detroit today is expected to be around 60%, and the atmospheric pressure is 29.94 inches of mercury.\\n\\nPlease note that this weather report is based on current data and is subject to change. It is always a good idea to check the weather forecast before making any plans.\\n\\nIf you would like a visual graphic of the weather report, please let me know and I will be happy to provide one.'<\/pre>\n<\/div>\n\n<\/div>\n\n<\/div>\n\n<\/div>\n\n<\/div>\n<div class=\"jp-Cell jp-MarkdownCell jp-Notebook-cell\">\n<div class=\"jp-Cell-inputWrapper\">\n<div class=\"jp-Collapser jp-InputCollapser jp-Cell-inputCollapser\">\n<\/div>\n<div class=\"jp-InputArea jp-Cell-inputArea\"><div class=\"jp-InputPrompt jp-InputArea-prompt\">\n<\/div><div class=\"jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput \" data-mime-type=\"text\/markdown\">\n<p>And there you have it, BabyAGI in Guidance using only local, open source models!<\/p>\n<p>Hopefully this was a helpful introduction.\nLikely this will quickly get outdated as Guidance is under very active development.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/body>\n","protected":false},"excerpt":{"rendered":"<p>Twitter: theemozilla Jupyter Notebook: babyagi-without-openai-guidance.ipynb Guidance\u00b6 If you&#8217;re already convinced of how awesome Guidance is, you can skip this section Guidance is a new template language from Microsoft that allows you to guide the output of lanugage models. This may not sound revolutionary on the surface, but if you&#8217;ve ever tried to compose together ouputs [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/posts\/1674"}],"collection":[{"href":"http:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/comments?post=1674"}],"version-history":[{"count":4,"href":"http:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/posts\/1674\/revisions"}],"predecessor-version":[{"id":1678,"href":"http:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/posts\/1674\/revisions\/1678"}],"wp:attachment":[{"href":"http:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/media?parent=1674"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/categories?post=1674"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/tags?post=1674"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}