Skip to content

Commit

Permalink
deploy: ac39baf
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Oct 27, 2024
1 parent b8fef11 commit 34060da
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 25 deletions.
Binary file modified .doctrees/apis/core/core.generator.doctree
Binary file not shown.
Binary file modified .doctrees/apis/datasets/datasets.types.doctree
Binary file not shown.
Binary file modified .doctrees/apis/datasets/index.doctree
Binary file not shown.
Binary file modified .doctrees/apis/utils/utils.cache.doctree
Binary file not shown.
Binary file modified .doctrees/environment.pickle
Binary file not shown.
38 changes: 29 additions & 9 deletions _modules/core/generator.html
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,9 @@ <h1>Source code for core.generator</h1><div class="highlight"><pre>

<span class="sd">It is a pipeline that consists of three subcomponents.&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">from</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="n">Path</span>

<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Any</span><span class="p">,</span> <span class="n">Dict</span><span class="p">,</span> <span class="n">Optional</span><span class="p">,</span> <span class="n">Union</span><span class="p">,</span> <span class="n">Callable</span><span class="p">,</span> <span class="n">Tuple</span><span class="p">,</span> <span class="n">List</span>
<span class="kn">import</span> <span class="nn">logging</span>
Expand Down Expand Up @@ -547,16 +548,14 @@ <h1>Source code for core.generator</h1><div class="highlight"><pre>

<span class="n">template</span> <span class="o">=</span> <span class="n">template</span> <span class="ow">or</span> <span class="n">DEFAULT_LIGHTRAG_SYSTEM_PROMPT</span>

<span class="c1"># Cache</span>
<span class="n">model_str</span> <span class="o">=</span> <span class="p">(</span>
<span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">model_client</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="si">}</span><span class="s2">_</span><span class="si">{</span><span class="n">model_kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;model&#39;</span><span class="p">,</span><span class="w"> </span><span class="s1">&#39;default&#39;</span><span class="p">)</span><span class="si">}</span><span class="s2">&quot;</span>
<span class="p">)</span>
<span class="n">_cache_path</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">get_adalflow_default_root_path</span><span class="p">()</span> <span class="k">if</span> <span class="n">cache_path</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">cache_path</span>
<span class="c1"># create the cache path and initialize the cache engine</span>

<span class="bp">self</span><span class="o">.</span><span class="n">set_cache_path</span><span class="p">(</span>
<span class="n">cache_path</span><span class="p">,</span> <span class="n">model_client</span><span class="p">,</span> <span class="n">model_kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;model&quot;</span><span class="p">,</span> <span class="s2">&quot;default&quot;</span><span class="p">)</span>
<span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cache_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">_cache_path</span><span class="p">,</span> <span class="sa">f</span><span class="s2">&quot;cache_</span><span class="si">{</span><span class="n">model_str</span><span class="si">}</span><span class="s2">.db&quot;</span><span class="p">)</span>

<span class="n">CachedEngine</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cache_path</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">cache_path</span><span class="p">)</span>

<span class="n">Component</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
<span class="n">GradComponent</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
<span class="n">CallbackManager</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
Expand All @@ -581,7 +580,6 @@ <h1>Source code for core.generator</h1><div class="highlight"><pre>
<span class="bp">self</span><span class="o">.</span><span class="n">mock_output_data</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">&quot;mock data&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">data_map_func</span><span class="p">:</span> <span class="n">Callable</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_data_map_func</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model_str</span> <span class="o">=</span> <span class="n">model_str</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_use_cache</span> <span class="o">=</span> <span class="n">use_cache</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_kwargs</span> <span class="o">=</span> <span class="p">{</span>
Expand All @@ -596,6 +594,28 @@ <h1>Source code for core.generator</h1><div class="highlight"><pre>
<span class="p">}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_teacher</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="s2">&quot;Generator&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>

<div class="viewcode-block" id="Generator.set_cache_path">
<a class="viewcode-back" href="../../apis/core/core.generator.html#core.generator.Generator.set_cache_path">[docs]</a>
<span class="k">def</span> <span class="nf">set_cache_path</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cache_path</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">model_client</span><span class="p">:</span> <span class="nb">object</span><span class="p">,</span> <span class="n">model</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Set the cache path for the generator.&quot;&quot;&quot;</span>

<span class="c1"># Construct a valid model string using the client class name and model</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model_str</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">model_client</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="si">}</span><span class="s2">_</span><span class="si">{</span><span class="n">model</span><span class="si">}</span><span class="s2">&quot;</span>

<span class="c1"># Remove any characters that are not allowed in file names (cross-platform)</span>
<span class="c1"># On Windows, characters like `:&lt;&gt;?/\|*` are prohibited.</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model_str</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;[^a-zA-Z0-9_\-]&quot;</span><span class="p">,</span> <span class="s2">&quot;_&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">model_str</span><span class="p">)</span>

<span class="n">_cache_path</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">get_adalflow_default_root_path</span><span class="p">()</span> <span class="k">if</span> <span class="n">cache_path</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">cache_path</span>
<span class="p">)</span>

<span class="c1"># Use pathlib to handle paths more safely across OS</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cache_path</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="n">_cache_path</span><span class="p">)</span> <span class="o">/</span> <span class="sa">f</span><span class="s2">&quot;cache_</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">model_str</span><span class="si">}</span><span class="s2">.db&quot;</span>

<span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Cache path set to: </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">cache_path</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span></div>


<div class="viewcode-block" id="Generator.get_cache_path">
<a class="viewcode-back" href="../../apis/core/core.generator.html#core.generator.Generator.get_cache_path">[docs]</a>
<span class="k">def</span> <span class="nf">get_cache_path</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
Expand Down
8 changes: 6 additions & 2 deletions _modules/utils/cache.html
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@
<h1>Source code for utils.cache</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">hashlib</span>
<span class="kn">import</span> <span class="nn">diskcache</span> <span class="k">as</span> <span class="nn">dc</span>
<span class="kn">from</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="n">Path</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Union</span>


<div class="viewcode-block" id="hash_text">
Expand All @@ -457,9 +459,11 @@ <h1>Source code for utils.cache</h1><div class="highlight"><pre>
<div class="viewcode-block" id="CachedEngine">
<a class="viewcode-back" href="../../apis/utils/utils.cache.html#utils.cache.CachedEngine">[docs]</a>
<span class="k">class</span> <span class="nc">CachedEngine</span><span class="p">:</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cache_path</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cache_path</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Path</span><span class="p">]):</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cache_path</span> <span class="o">=</span> <span class="n">cache_path</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cache_path</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="n">cache_path</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cache_path</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">parents</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">exist_ok</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">cache</span> <span class="o">=</span> <span class="n">dc</span><span class="o">.</span><span class="n">Cache</span><span class="p">(</span><span class="n">cache_path</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_check_cache</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">prompt</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
Expand Down
7 changes: 7 additions & 0 deletions apis/core/core.generator.html
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,12 @@
<span class="sig-name descname"><span class="pre">model_client</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">ModelClient</span></em><a class="headerlink" href="#core.generator.Generator.model_client" title="Link to this definition">#</a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="core.generator.Generator.set_cache_path">
<span class="sig-name descname"><span class="pre">set_cache_path</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cache_path</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">model_client</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">object</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">model</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/core/generator.html#Generator.set_cache_path"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#core.generator.Generator.set_cache_path" title="Link to this definition">#</a></dt>
<dd><p>Set the cache path for the generator.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="core.generator.Generator.get_cache_path">
<span class="sig-name descname"><span class="pre">get_cache_path</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">str</span></span></span><a class="reference internal" href="../../_modules/core/generator.html#Generator.get_cache_path"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#core.generator.Generator.get_cache_path" title="Link to this definition">#</a></dt>
Expand Down Expand Up @@ -847,6 +853,7 @@
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#core.generator.Generator"><code class="docutils literal notranslate"><span class="pre">Generator</span></code></a><ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#core.generator.Generator.model_type"><code class="docutils literal notranslate"><span class="pre">Generator.model_type</span></code></a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#core.generator.Generator.model_client"><code class="docutils literal notranslate"><span class="pre">Generator.model_client</span></code></a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#core.generator.Generator.set_cache_path"><code class="docutils literal notranslate"><span class="pre">Generator.set_cache_path()</span></code></a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#core.generator.Generator.get_cache_path"><code class="docutils literal notranslate"><span class="pre">Generator.get_cache_path()</span></code></a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#core.generator.Generator.set_mock_output"><code class="docutils literal notranslate"><span class="pre">Generator.set_mock_output()</span></code></a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#core.generator.Generator.reset_mock_output"><code class="docutils literal notranslate"><span class="pre">Generator.reset_mock_output()</span></code></a></li>
Expand Down
Loading

0 comments on commit 34060da

Please sign in to comment.