Skip to content

Commit

Permalink
deploy: ee78d52
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiTao-Li committed Sep 3, 2024
1 parent 85c995d commit 879f3e8
Show file tree
Hide file tree
Showing 24 changed files with 45 additions and 221 deletions.
Binary file modified en/.doctrees/agentscope.rag.doctree
Binary file not shown.
Binary file modified en/.doctrees/agentscope.rag.knowledge_bank.doctree
Binary file not shown.
Binary file modified en/.doctrees/environment.pickle
Binary file not shown.
Binary file modified en/.doctrees/index.doctree
Binary file not shown.
19 changes: 12 additions & 7 deletions en/_modules/agentscope/rag/knowledge_bank.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ <h1>Source code for agentscope.rag.knowledge_bank</h1><div class="highlight"><pr
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Optional</span><span class="p">,</span> <span class="n">Union</span>
<span class="kn">from</span> <span class="nn">loguru</span> <span class="kn">import</span> <span class="n">logger</span>
<span class="kn">from</span> <span class="nn">agentscope.agents</span> <span class="kn">import</span> <span class="n">AgentBase</span>
<span class="kn">from</span> <span class="nn">.llama_index_knowledge</span> <span class="kn">import</span> <span class="n">LlamaIndexKnowledge</span>
<span class="kn">from</span> <span class="nn">..manager</span> <span class="kn">import</span> <span class="n">ModelManager</span>
<span class="kn">from</span> <span class="nn">.knowledge</span> <span class="kn">import</span> <span class="n">Knowledge</span>

<span class="n">DEFAULT_INDEX_CONFIG</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;knowledge_id&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
Expand Down Expand Up @@ -163,13 +163,14 @@ <h1>Source code for agentscope.rag.knowledge_bank</h1><div class="highlight"><pr
<span class="n">configs</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">dict</span><span class="p">,</span> <span class="nb">str</span><span class="p">],</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;initialize the knowledge bank&quot;&quot;&quot;</span>

<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">configs</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Loading configs from </span><span class="si">{</span><span class="n">configs</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">configs</span><span class="p">,</span> <span class="s2">&quot;r&quot;</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s2">&quot;utf-8&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fp</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">configs</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">())</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">configs</span> <span class="o">=</span> <span class="n">configs</span>
<span class="bp">self</span><span class="o">.</span><span class="n">stored_knowledge</span><span class="p">:</span> <span class="nb">dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">LlamaIndexKnowledge</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">stored_knowledge</span><span class="p">:</span> <span class="nb">dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Knowledge</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_init_knowledge</span><span class="p">()</span></div>


Expand Down Expand Up @@ -227,6 +228,8 @@ <h1>Source code for agentscope.rag.knowledge_bank</h1><div class="highlight"><pr
<span class="sd"> )</span>
<span class="sd"> &#39;&#39;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">.llama_index_knowledge</span> <span class="kn">import</span> <span class="n">LlamaIndexKnowledge</span>

<span class="k">if</span> <span class="n">knowledge_id</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">stored_knowledge</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;knowledge_id </span><span class="si">{</span><span class="n">knowledge_id</span><span class="si">}</span><span class="s2"> already exists.&quot;</span><span class="p">)</span>

Expand All @@ -248,9 +251,11 @@ <h1>Source code for agentscope.rag.knowledge_bank</h1><div class="highlight"><pr
<span class="n">knowledge_id</span><span class="o">=</span><span class="n">knowledge_id</span><span class="p">,</span>
<span class="n">emb_model</span><span class="o">=</span><span class="n">model_manager</span><span class="o">.</span><span class="n">get_model_by_config_name</span><span class="p">(</span><span class="n">emb_model_name</span><span class="p">),</span>
<span class="n">knowledge_config</span><span class="o">=</span><span class="n">knowledge_config</span><span class="p">,</span>
<span class="n">model</span><span class="o">=</span><span class="n">model_manager</span><span class="o">.</span><span class="n">get_model_by_config_name</span><span class="p">(</span><span class="n">model_name</span><span class="p">)</span>
<span class="k">if</span> <span class="n">model_name</span>
<span class="k">else</span> <span class="kc">None</span><span class="p">,</span>
<span class="n">model</span><span class="o">=</span><span class="p">(</span>
<span class="n">model_manager</span><span class="o">.</span><span class="n">get_model_by_config_name</span><span class="p">(</span><span class="n">model_name</span><span class="p">)</span>
<span class="k">if</span> <span class="n">model_name</span>
<span class="k">else</span> <span class="kc">None</span>
<span class="p">),</span>
<span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;data loaded for knowledge_id = </span><span class="si">{</span><span class="n">knowledge_id</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span></div>

Expand All @@ -261,7 +266,7 @@ <h1>Source code for agentscope.rag.knowledge_bank</h1><div class="highlight"><pr
<span class="bp">self</span><span class="p">,</span>
<span class="n">knowledge_id</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
<span class="n">duplicate</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">LlamaIndexKnowledge</span><span class="p">:</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Knowledge</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Get a Knowledge object from the knowledge bank.</span>
<span class="sd"> Args:</span>
Expand All @@ -270,7 +275,7 @@ <h1>Source code for agentscope.rag.knowledge_bank</h1><div class="highlight"><pr
<span class="sd"> duplicate (bool):</span>
<span class="sd"> whether return a copy of the Knowledge object.</span>
<span class="sd"> Returns:</span>
<span class="sd"> LlamaIndexKnowledge:</span>
<span class="sd"> Knowledge:</span>
<span class="sd"> the Knowledge object defined with Llama-index</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">knowledge_id</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">stored_knowledge</span><span class="p">:</span>
Expand Down
8 changes: 4 additions & 4 deletions en/_modules/agentscope/rag/llama_index_knowledge.html
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ <h1>Source code for agentscope.rag.llama_index_knowledge</h1><div class="highlig


<div class="viewcode-block" id="LlamaIndexKnowledge">
<a class="viewcode-back" href="../../../agentscope.rag.llama_index_knowledge.html#agentscope.rag.LlamaIndexKnowledge">[docs]</a>
<a class="viewcode-back" href="../../../agentscope.rag.llama_index_knowledge.html#agentscope.rag.llama_index_knowledge.LlamaIndexKnowledge">[docs]</a>
<span class="k">class</span> <span class="nc">LlamaIndexKnowledge</span><span class="p">(</span><span class="n">Knowledge</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> This class is a wrapper with the llama index RAG.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<div class="viewcode-block" id="LlamaIndexKnowledge.__init__">
<a class="viewcode-back" href="../../../agentscope.rag.llama_index_knowledge.html#agentscope.rag.LlamaIndexKnowledge.__init__">[docs]</a>
<a class="viewcode-back" href="../../../agentscope.rag.llama_index_knowledge.html#agentscope.rag.llama_index_knowledge.LlamaIndexKnowledge.__init__">[docs]</a>
<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">knowledge_id</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
Expand Down Expand Up @@ -575,7 +575,7 @@ <h1>Source code for agentscope.rag.llama_index_knowledge</h1><div class="highlig
<span class="k">return</span> <span class="n">retriever</span>

<div class="viewcode-block" id="LlamaIndexKnowledge.retrieve">
<a class="viewcode-back" href="../../../agentscope.rag.llama_index_knowledge.html#agentscope.rag.LlamaIndexKnowledge.retrieve">[docs]</a>
<a class="viewcode-back" href="../../../agentscope.rag.llama_index_knowledge.html#agentscope.rag.llama_index_knowledge.LlamaIndexKnowledge.retrieve">[docs]</a>
<span class="k">def</span> <span class="nf">retrieve</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span>
<span class="n">query</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
Expand Down Expand Up @@ -617,7 +617,7 @@ <h1>Source code for agentscope.rag.llama_index_knowledge</h1><div class="highlig


<div class="viewcode-block" id="LlamaIndexKnowledge.refresh_index">
<a class="viewcode-back" href="../../../agentscope.rag.llama_index_knowledge.html#agentscope.rag.LlamaIndexKnowledge.refresh_index">[docs]</a>
<a class="viewcode-back" href="../../../agentscope.rag.llama_index_knowledge.html#agentscope.rag.llama_index_knowledge.LlamaIndexKnowledge.refresh_index">[docs]</a>
<span class="k">def</span> <span class="nf">refresh_index</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Refresh the index when needed.</span>
Expand Down
6 changes: 0 additions & 6 deletions en/agentscope.html
Original file line number Diff line number Diff line change
Expand Up @@ -757,12 +757,6 @@ <h2>Subpackages<a class="headerlink" href="#subpackages" title="Link to this hea
<li class="toctree-l4"><a class="reference internal" href="agentscope.rag.html#agentscope.rag.Knowledge.post_processing"><code class="docutils literal notranslate"><span class="pre">Knowledge.post_processing()</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="agentscope.rag.html#agentscope.rag.LlamaIndexKnowledge"><code class="docutils literal notranslate"><span class="pre">LlamaIndexKnowledge</span></code></a><ul>
<li class="toctree-l4"><a class="reference internal" href="agentscope.rag.html#agentscope.rag.LlamaIndexKnowledge.__init__"><code class="docutils literal notranslate"><span class="pre">LlamaIndexKnowledge.__init__()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="agentscope.rag.html#agentscope.rag.LlamaIndexKnowledge.retrieve"><code class="docutils literal notranslate"><span class="pre">LlamaIndexKnowledge.retrieve()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="agentscope.rag.html#agentscope.rag.LlamaIndexKnowledge.refresh_index"><code class="docutils literal notranslate"><span class="pre">LlamaIndexKnowledge.refresh_index()</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="agentscope.rag.html#agentscope.rag.KnowledgeBank"><code class="docutils literal notranslate"><span class="pre">KnowledgeBank</span></code></a><ul>
<li class="toctree-l4"><a class="reference internal" href="agentscope.rag.html#agentscope.rag.KnowledgeBank.__init__"><code class="docutils literal notranslate"><span class="pre">KnowledgeBank.__init__()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="agentscope.rag.html#agentscope.rag.KnowledgeBank.add_data_as_knowledge"><code class="docutils literal notranslate"><span class="pre">KnowledgeBank.add_data_as_knowledge()</span></code></a></li>
Expand Down
Loading

0 comments on commit 879f3e8

Please sign in to comment.