Repository: CIME-Software/perplexipy (language: python)

Issue:
Experimental:  process stdin as a code shippet that needs to be refactored
Experimental:  process stdin as a code shippet that needs to be refactored.  If no arguments are passed, check stdin, get all the input, and submit it as a single prompt.


Discussion / hints:

Fix patch:
diff --git a/README.md b/README.md
index 198426b..e1fce69 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-% perplexipy(3) Version 0.2.1 | Perplexity AI high level API documentation
+% perplexipy(3) Version 0.2.2 | Perplexity AI high level API documentation
 
 Name
 ====
diff --git a/codex-README.md b/codex-README.md
index 6027d0f..4d632e3 100644
--- a/codex-README.md
+++ b/codex-README.md
@@ -1,4 +1,4 @@
-% codex(3) Version 0.2.1 | PerplexiPy command line code explainer
+% codex(3) Version 0.2.2 | PerplexiPy command line code explainer
 
 Name
 ====
@@ -51,6 +51,17 @@ codex 'A coding question here; best if the language is specified.'
 The coding question, including any code snippets, must be enclosed in single
 quotes to prevent shell expansion in Unix-like systems.
 
+**codex** can also process input provided from stdin through redirection or a
+pipe:
+
+
+```bash
+echo "How do I reverse a string in Java?" | codex
+```
+
+The output always goes to stdout.  This simplifies integration with editors and
+IDEs that support a streaming interface like Vim, emacs, VS Code, etc.
+
 
 Vim
 ---
diff --git a/docs/perplexipy.html b/docs/perplexipy.html
index c87bec9..c3feb3f 100644
--- a/docs/perplexipy.html
+++ b/docs/perplexipy.html
@@ -496,7 +496,7 @@ <h1 class="modulename">
                 <section id="PERPLEXITY_VALID_ROLES">
                     <div class="attr variable">
             <span class="name">PERPLEXITY_VALID_ROLES</span>        =
-<span class="default_value">{&#39;user&#39;, &#39;system&#39;, &#39;assistant&#39;}</span>
+<span class="default_value">{&#39;system&#39;, &#39;assistant&#39;, &#39;user&#39;}</span>
 
         
     </div>
diff --git a/docs/perplexipy/codex.html b/docs/perplexipy/codex.html
index d8591d8..d24282b 100644
--- a/docs/perplexipy/codex.html
+++ b/docs/perplexipy/codex.html
@@ -59,82 +59,109 @@ <h1 class="modulename">
 
                         <label class="view-source-button" for="mod-codex-view-source"><span>View Source</span></label>
 
-                        <div class="pdoc-code codehilite"><pre><span></span><span id="L-1"><a href="#L-1"><span class="linenos"> 1</span></a><span class="c1"># See: https://github.com/CIME-Software/perplexipy/blob/master/LICENSE.txt</span>
-</span><span id="L-2"><a href="#L-2"><span class="linenos"> 2</span></a>
-</span><span id="L-3"><a href="#L-3"><span class="linenos"> 3</span></a>
-</span><span id="L-4"><a href="#L-4"><span class="linenos"> 4</span></a><span class="kn">from</span> <span class="nn">perplexipy</span> <span class="kn">import</span> <span class="n">PerplexityClient</span>
-</span><span id="L-5"><a href="#L-5"><span class="linenos"> 5</span></a><span class="kn">from</span> <span class="nn">perplexipy</span> <span class="kn">import</span> <span class="n">__VERSION__</span>
-</span><span id="L-6"><a href="#L-6"><span class="linenos"> 6</span></a>
-</span><span id="L-7"><a href="#L-7"><span class="linenos"> 7</span></a><span class="kn">import</span> <span class="nn">os</span>
-</span><span id="L-8"><a href="#L-8"><span class="linenos"> 8</span></a><span class="kn">import</span> <span class="nn">sys</span>
-</span><span id="L-9"><a href="#L-9"><span class="linenos"> 9</span></a>
-</span><span id="L-10"><a href="#L-10"><span class="linenos">10</span></a><span class="kn">import</span> <span class="nn">click</span>
-</span><span id="L-11"><a href="#L-11"><span class="linenos">11</span></a>
-</span><span id="L-12"><a href="#L-12"><span class="linenos">12</span></a>
-</span><span id="L-13"><a href="#L-13"><span class="linenos">13</span></a><span class="c1"># *** implementation ***</span>
-</span><span id="L-14"><a href="#L-14"><span class="linenos">14</span></a>
-</span><span id="L-15"><a href="#L-15"><span class="linenos">15</span></a><span class="k">def</span> <span class="nf">_die</span><span class="p">(</span><span class="n">msg</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">exitCode</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">99</span><span class="p">):</span>
-</span><span id="L-16"><a href="#L-16"><span class="linenos">16</span></a>    <span class="n">click</span><span class="o">.</span><span class="n">echo</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
-</span><span id="L-17"><a href="#L-17"><span class="linenos">17</span></a>    <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">99</span><span class="p">)</span>
-</span><span id="L-18"><a href="#L-18"><span class="linenos">18</span></a>
-</span><span id="L-19"><a href="#L-19"><span class="linenos">19</span></a>
-</span><span id="L-20"><a href="#L-20"><span class="linenos">20</span></a><span class="k">def</span> <span class="nf">_helpUser</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
-</span><span id="L-21"><a href="#L-21"><span class="linenos">21</span></a>    <span class="k">return</span> <span class="s2">&quot;Syntax: codex &#39;your coding question here in single quotes&#39;</span><span class="se">\n</span><span class="s2">&quot;</span>
-</span><span id="L-22"><a href="#L-22"><span class="linenos">22</span></a>
-</span><span id="L-23"><a href="#L-23"><span class="linenos">23</span></a>
-</span><span id="L-24"><a href="#L-24"><span class="linenos">24</span></a><span class="k">def</span> <span class="nf">codexCore</span><span class="p">(</span><span class="n">userQuery</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
-</span><span id="L-25"><a href="#L-25"><span class="linenos">25</span></a><span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
-</span><span id="L-26"><a href="#L-26"><span class="linenos">26</span></a><span class="sd">    Send a user query to the model for processing.</span>
-</span><span id="L-27"><a href="#L-27"><span class="linenos">27</span></a>
-</span><span id="L-28"><a href="#L-28"><span class="linenos">28</span></a><span class="sd">    Arguments</span>
-</span><span id="L-29"><a href="#L-29"><span class="linenos">29</span></a><span class="sd">    ---------</span>
-</span><span id="L-30"><a href="#L-30"><span class="linenos">30</span></a><span class="sd">        userQuery</span>
-</span><span id="L-31"><a href="#L-31"><span class="linenos">31</span></a><span class="sd">    A string with the user query, most often a programming question.</span>
-</span><span id="L-32"><a href="#L-32"><span class="linenos">32</span></a>
-</span><span id="L-33"><a href="#L-33"><span class="linenos">33</span></a><span class="sd">    Returns</span>
-</span><span id="L-34"><a href="#L-34"><span class="linenos">34</span></a><span class="sd">    -------</span>
-</span><span id="L-35"><a href="#L-35"><span class="linenos">35</span></a><span class="sd">    The result of the query, or `None` if the query was empty.</span>
-</span><span id="L-36"><a href="#L-36"><span class="linenos">36</span></a><span class="sd">    &quot;&quot;&quot;</span>
-</span><span id="L-37"><a href="#L-37"><span class="linenos">37</span></a>    <span class="n">result</span> <span class="o">=</span> <span class="kc">None</span>
-</span><span id="L-38"><a href="#L-38"><span class="linenos">38</span></a>    <span class="k">if</span> <span class="n">userQuery</span><span class="p">:</span>
-</span><span id="L-39"><a href="#L-39"><span class="linenos">39</span></a>        <span class="n">client</span> <span class="o">=</span> <span class="n">PerplexityClient</span><span class="p">(</span><span class="n">key</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;PERPLEXITY_API_KEY&#39;</span><span class="p">])</span>
-</span><span id="L-40"><a href="#L-40"><span class="linenos">40</span></a>        <span class="n">client</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="s1">&#39;codellama-70b-instruct&#39;</span>
-</span><span id="L-41"><a href="#L-41"><span class="linenos">41</span></a>        <span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">userQuery</span><span class="p">)</span>
-</span><span id="L-42"><a href="#L-42"><span class="linenos">42</span></a>
-</span><span id="L-43"><a href="#L-43"><span class="linenos">43</span></a>    <span class="k">return</span> <span class="n">result</span>
-</span><span id="L-44"><a href="#L-44"><span class="linenos">44</span></a>
-</span><span id="L-45"><a href="#L-45"><span class="linenos">45</span></a>
-</span><span id="L-46"><a href="#L-46"><span class="linenos">46</span></a><span class="nd">@click</span><span class="o">.</span><span class="n">command</span><span class="p">(</span><span class="s1">&#39;codex&#39;</span><span class="p">)</span>
-</span><span id="L-47"><a href="#L-47"><span class="linenos">47</span></a><span class="nd">@click</span><span class="o">.</span><span class="n">version_option</span><span class="p">(</span><span class="n">__VERSION__</span><span class="p">,</span> <span class="n">prog_name</span> <span class="o">=</span> <span class="s1">&#39;codex&#39;</span><span class="p">)</span>
-</span><span id="L-48"><a href="#L-48"><span class="linenos">48</span></a><span class="nd">@click</span><span class="o">.</span><span class="n">argument</span><span class="p">(</span><span class="s1">&#39;tokens&#39;</span><span class="p">,</span> <span class="n">nargs</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="nb">type</span> <span class="o">=</span> <span class="n">click</span><span class="o">.</span><span class="n">STRING</span><span class="p">)</span>
-</span><span id="L-49"><a href="#L-49"><span class="linenos">49</span></a><span class="k">def</span> <span class="nf">codex</span><span class="p">(</span><span class="n">tokens</span><span class="p">:</span> <span class="nb">list</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
-</span><span id="L-50"><a href="#L-50"><span class="linenos">50</span></a><span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
-</span><span id="L-51"><a href="#L-51"><span class="linenos">51</span></a><span class="sd">    Process a command line query and display the result to the console.</span>
-</span><span id="L-52"><a href="#L-52"><span class="linenos">52</span></a>
-</span><span id="L-53"><a href="#L-53"><span class="linenos">53</span></a><span class="sd">    Arguments</span>
-</span><span id="L-54"><a href="#L-54"><span class="linenos">54</span></a><span class="sd">    ---------</span>
-</span><span id="L-55"><a href="#L-55"><span class="linenos">55</span></a><span class="sd">        tokens</span>
-</span><span id="L-56"><a href="#L-56"><span class="linenos">56</span></a><span class="sd">    A list of tokens that will be assembled as a single string for</span>
-</span><span id="L-57"><a href="#L-57"><span class="linenos">57</span></a><span class="sd">    processing.</span>
-</span><span id="L-58"><a href="#L-58"><span class="linenos">58</span></a>
-</span><span id="L-59"><a href="#L-59"><span class="linenos">59</span></a><span class="sd">    Returns</span>
-</span><span id="L-60"><a href="#L-60"><span class="linenos">60</span></a><span class="sd">    -------</span>
-</span><span id="L-61"><a href="#L-61"><span class="linenos">61</span></a><span class="sd">    A string with the response to the query, after displaying it to the</span>
-</span><span id="L-62"><a href="#L-62"><span class="linenos">62</span></a><span class="sd">    console.</span>
-</span><span id="L-63"><a href="#L-63"><span class="linenos">63</span></a><span class="sd">    &quot;&quot;&quot;</span>
-</span><span id="L-64"><a href="#L-64"><span class="linenos">64</span></a>    <span class="n">result</span> <span class="o">=</span> <span class="kc">None</span>
-</span><span id="L-65"><a href="#L-65"><span class="linenos">65</span></a>    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">tokens</span><span class="p">):</span>
-</span><span id="L-66"><a href="#L-66"><span class="linenos">66</span></a>        <span class="n">userQuery</span> <span class="o">=</span> <span class="s1">&#39;Concise, code only answer to this question: &#39;</span><span class="o">+</span><span class="s1">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">tokens</span><span class="p">)</span>
-</span><span id="L-67"><a href="#L-67"><span class="linenos">67</span></a>        <span class="n">result</span> <span class="o">=</span> <span class="n">codexCore</span><span class="p">(</span><span class="n">userQuery</span><span class="p">)</span>
-</span><span id="L-68"><a href="#L-68"><span class="linenos">68</span></a>        <span class="n">click</span><span class="o">.</span><span class="n">echo</span><span class="p">(</span><span class="n">result</span><span class="p">)</span>
-</span><span id="L-69"><a href="#L-69"><span class="linenos">69</span></a>    <span class="k">else</span><span class="p">:</span>
-</span><span id="L-70"><a href="#L-70"><span class="linenos">70</span></a>        <span class="n">_die</span><span class="p">(</span><span class="n">_helpUser</span><span class="p">(),</span> <span class="mi">1</span><span class="p">)</span>
-</span><span id="L-71"><a href="#L-71"><span class="linenos">71</span></a>
-</span><span id="L-72"><a href="#L-72"><span class="linenos">72</span></a>    <span class="k">return</span> <span class="n">result</span>
-</span><span id="L-73"><a href="#L-73"><span class="linenos">73</span></a>
-</span><span id="L-74"><a href="#L-74"><span class="linenos">74</span></a>
-</span><span id="L-75"><a href="#L-75"><span class="linenos">75</span></a><span class="k">if</span> <span class="s1">&#39;__main__&#39;</span> <span class="o">==</span> <span class="vm">__name__</span><span class="p">:</span>
-</span><span id="L-76"><a href="#L-76"><span class="linenos">76</span></a>    <span class="n">codex</span><span class="p">()</span>
+                        <div class="pdoc-code codehilite"><pre><span></span><span id="L-1"><a href="#L-1"><span class="linenos">  1</span></a><span class="c1"># See: https://github.com/CIME-Software/perplexipy/blob/master/LICENSE.txt</span>
+</span><span id="L-2"><a href="#L-2"><span class="linenos">  2</span></a>
+</span><span id="L-3"><a href="#L-3"><span class="linenos">  3</span></a>
+</span><span id="L-4"><a href="#L-4"><span class="linenos">  4</span></a><span class="kn">from</span> <span class="nn">perplexipy</span> <span class="kn">import</span> <span class="n">PerplexityClient</span>
+</span><span id="L-5"><a href="#L-5"><span class="linenos">  5</span></a><span class="kn">from</span> <span class="nn">perplexipy</span> <span class="kn">import</span> <span class="n">__VERSION__</span>
+</span><span id="L-6"><a href="#L-6"><span class="linenos">  6</span></a>
+</span><span id="L-7"><a href="#L-7"><span class="linenos">  7</span></a><span class="kn">import</span> <span class="nn">os</span>
+</span><span id="L-8"><a href="#L-8"><span class="linenos">  8</span></a><span class="kn">import</span> <span class="nn">select</span>
+</span><span id="L-9"><a href="#L-9"><span class="linenos">  9</span></a><span class="kn">import</span> <span class="nn">sys</span>
+</span><span id="L-10"><a href="#L-10"><span class="linenos"> 10</span></a>
+</span><span id="L-11"><a href="#L-11"><span class="linenos"> 11</span></a><span class="kn">import</span> <span class="nn">click</span>
+</span><span id="L-12"><a href="#L-12"><span class="linenos"> 12</span></a>
+</span><span id="L-13"><a href="#L-13"><span class="linenos"> 13</span></a>
+</span><span id="L-14"><a href="#L-14"><span class="linenos"> 14</span></a><span class="c1"># *** implementation ***</span>
+</span><span id="L-15"><a href="#L-15"><span class="linenos"> 15</span></a>
+</span><span id="L-16"><a href="#L-16"><span class="linenos"> 16</span></a><span class="k">def</span> <span class="nf">_die</span><span class="p">(</span><span class="n">msg</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">exitCode</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">99</span><span class="p">):</span>
+</span><span id="L-17"><a href="#L-17"><span class="linenos"> 17</span></a>    <span class="n">click</span><span class="o">.</span><span class="n">echo</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
+</span><span id="L-18"><a href="#L-18"><span class="linenos"> 18</span></a>    <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">99</span><span class="p">)</span>
+</span><span id="L-19"><a href="#L-19"><span class="linenos"> 19</span></a>
+</span><span id="L-20"><a href="#L-20"><span class="linenos"> 20</span></a>
+</span><span id="L-21"><a href="#L-21"><span class="linenos"> 21</span></a><span class="k">def</span> <span class="nf">_helpUser</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
+</span><span id="L-22"><a href="#L-22"><span class="linenos"> 22</span></a>    <span class="k">return</span> <span class="s2">&quot;Syntax: codex &#39;your coding question here in single quotes&#39;</span><span class="se">\n</span><span class="s2">&quot;</span>
+</span><span id="L-23"><a href="#L-23"><span class="linenos"> 23</span></a>
+</span><span id="L-24"><a href="#L-24"><span class="linenos"> 24</span></a>
+</span><span id="L-25"><a href="#L-25"><span class="linenos"> 25</span></a><span class="k">def</span> <span class="nf">codexCore</span><span class="p">(</span><span class="n">userQuery</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
+</span><span id="L-26"><a href="#L-26"><span class="linenos"> 26</span></a><span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
+</span><span id="L-27"><a href="#L-27"><span class="linenos"> 27</span></a><span class="sd">    Send a user query to the model for processing.</span>
+</span><span id="L-28"><a href="#L-28"><span class="linenos"> 28</span></a>
+</span><span id="L-29"><a href="#L-29"><span class="linenos"> 29</span></a><span class="sd">    Arguments</span>
+</span><span id="L-30"><a href="#L-30"><span class="linenos"> 30</span></a><span class="sd">    ---------</span>
+</span><span id="L-31"><a href="#L-31"><span class="linenos"> 31</span></a><span class="sd">        userQuery</span>
+</span><span id="L-32"><a href="#L-32"><span class="linenos"> 32</span></a><span class="sd">    A string with the user query, most often a programming question.</span>
+</span><span id="L-33"><a href="#L-33"><span class="linenos"> 33</span></a>
+</span><span id="L-34"><a href="#L-34"><span class="linenos"> 34</span></a><span class="sd">    Returns</span>
+</span><span id="L-35"><a href="#L-35"><span class="linenos"> 35</span></a><span class="sd">    -------</span>
+</span><span id="L-36"><a href="#L-36"><span class="linenos"> 36</span></a><span class="sd">    The result of the query, or `None` if the query was empty.</span>
+</span><span id="L-37"><a href="#L-37"><span class="linenos"> 37</span></a><span class="sd">    &quot;&quot;&quot;</span>
+</span><span id="L-38"><a href="#L-38"><span class="linenos"> 38</span></a>    <span class="n">result</span> <span class="o">=</span> <span class="kc">None</span>
+</span><span id="L-39"><a href="#L-39"><span class="linenos"> 39</span></a>    <span class="k">if</span> <span class="n">userQuery</span><span class="p">:</span>
+</span><span id="L-40"><a href="#L-40"><span class="linenos"> 40</span></a>        <span class="n">client</span> <span class="o">=</span> <span class="n">PerplexityClient</span><span class="p">(</span><span class="n">key</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;PERPLEXITY_API_KEY&#39;</span><span class="p">])</span>
+</span><span id="L-41"><a href="#L-41"><span class="linenos"> 41</span></a>        <span class="n">client</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="s1">&#39;codellama-70b-instruct&#39;</span>
+</span><span id="L-42"><a href="#L-42"><span class="linenos"> 42</span></a>        <span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">userQuery</span><span class="p">)</span>
+</span><span id="L-43"><a href="#L-43"><span class="linenos"> 43</span></a>
+</span><span id="L-44"><a href="#L-44"><span class="linenos"> 44</span></a>    <span class="k">return</span> <span class="n">result</span>
+</span><span id="L-45"><a href="#L-45"><span class="linenos"> 45</span></a>
+</span><span id="L-46"><a href="#L-46"><span class="linenos"> 46</span></a>
+</span><span id="L-47"><a href="#L-47"><span class="linenos"> 47</span></a><span class="k">def</span> <span class="nf">_stdinHasData</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="nb">bool</span><span class="p">:</span>
+</span><span id="L-48"><a href="#L-48"><span class="linenos"> 48</span></a><span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
+</span><span id="L-49"><a href="#L-49"><span class="linenos"> 49</span></a><span class="sd">    Checks if there&#39;s data pending to be processed off `stdin`.  It&#39;s a</span>
+</span><span id="L-50"><a href="#L-50"><span class="linenos"> 50</span></a><span class="sd">    convinience function for readability.</span>
+</span><span id="L-51"><a href="#L-51"><span class="linenos"> 51</span></a>
+</span><span id="L-52"><a href="#L-52"><span class="linenos"> 52</span></a><span class="sd">    Returns</span>
+</span><span id="L-53"><a href="#L-53"><span class="linenos"> 53</span></a><span class="sd">    -------</span>
+</span><span id="L-54"><a href="#L-54"><span class="linenos"> 54</span></a><span class="sd">    `True` if the `stdin` stream is pending processing.</span>
+</span><span id="L-55"><a href="#L-55"><span class="linenos"> 55</span></a><span class="sd">    &quot;&quot;&quot;</span>
+</span><span id="L-56"><a href="#L-56"><span class="linenos"> 56</span></a>    <span class="k">return</span> <span class="n">select</span><span class="o">.</span><span class="n">select</span><span class="p">([</span><span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="p">],</span> <span class="p">[],</span> <span class="p">[],</span> <span class="mi">0</span><span class="p">)</span> <span class="o">==</span> <span class="p">([</span><span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="p">],</span> <span class="p">[],</span> <span class="p">[])</span>
+</span><span id="L-57"><a href="#L-57"><span class="linenos"> 57</span></a>
+</span><span id="L-58"><a href="#L-58"><span class="linenos"> 58</span></a>
+</span><span id="L-59"><a href="#L-59"><span class="linenos"> 59</span></a><span class="k">def</span> <span class="nf">_assembleInput</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
+</span><span id="L-60"><a href="#L-60"><span class="linenos"> 60</span></a>    <span class="n">result</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+</span><span id="L-61"><a href="#L-61"><span class="linenos"> 61</span></a>    <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="p">:</span>
+</span><span id="L-62"><a href="#L-62"><span class="linenos"> 62</span></a>        <span class="n">result</span> <span class="o">+=</span> <span class="n">line</span>
+</span><span id="L-63"><a href="#L-63"><span class="linenos"> 63</span></a>
+</span><span id="L-64"><a href="#L-64"><span class="linenos"> 64</span></a>    <span class="k">return</span> <span class="n">result</span>
+</span><span id="L-65"><a href="#L-65"><span class="linenos"> 65</span></a>
+</span><span id="L-66"><a href="#L-66"><span class="linenos"> 66</span></a>
+</span><span id="L-67"><a href="#L-67"><span class="linenos"> 67</span></a><span class="nd">@click</span><span class="o">.</span><span class="n">command</span><span class="p">(</span><span class="s1">&#39;codex&#39;</span><span class="p">)</span>
+</span><span id="L-68"><a href="#L-68"><span class="linenos"> 68</span></a><span class="nd">@click</span><span class="o">.</span><span class="n">version_option</span><span class="p">(</span><span class="n">__VERSION__</span><span class="p">,</span> <span class="n">prog_name</span> <span class="o">=</span> <span class="s1">&#39;codex&#39;</span><span class="p">)</span>
+</span><span id="L-69"><a href="#L-69"><span class="linenos"> 69</span></a><span class="nd">@click</span><span class="o">.</span><span class="n">argument</span><span class="p">(</span><span class="s1">&#39;tokens&#39;</span><span class="p">,</span> <span class="n">nargs</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="nb">type</span> <span class="o">=</span> <span class="n">click</span><span class="o">.</span><span class="n">STRING</span><span class="p">)</span>
+</span><span id="L-70"><a href="#L-70"><span class="linenos"> 70</span></a><span class="k">def</span> <span class="nf">codex</span><span class="p">(</span><span class="n">tokens</span><span class="p">:</span> <span class="nb">list</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
+</span><span id="L-71"><a href="#L-71"><span class="linenos"> 71</span></a><span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
+</span><span id="L-72"><a href="#L-72"><span class="linenos"> 72</span></a><span class="sd">    Process a command line query and display the result to the console.</span>
+</span><span id="L-73"><a href="#L-73"><span class="linenos"> 73</span></a>
+</span><span id="L-74"><a href="#L-74"><span class="linenos"> 74</span></a><span class="sd">    Arguments</span>
+</span><span id="L-75"><a href="#L-75"><span class="linenos"> 75</span></a><span class="sd">    ---------</span>
+</span><span id="L-76"><a href="#L-76"><span class="linenos"> 76</span></a><span class="sd">        tokens</span>
+</span><span id="L-77"><a href="#L-77"><span class="linenos"> 77</span></a><span class="sd">    A list of tokens that will be assembled as a single string for</span>
+</span><span id="L-78"><a href="#L-78"><span class="linenos"> 78</span></a><span class="sd">    processing.</span>
+</span><span id="L-79"><a href="#L-79"><span class="linenos"> 79</span></a>
+</span><span id="L-80"><a href="#L-80"><span class="linenos"> 80</span></a><span class="sd">    Returns</span>
+</span><span id="L-81"><a href="#L-81"><span class="linenos"> 81</span></a><span class="sd">    -------</span>
+</span><span id="L-82"><a href="#L-82"><span class="linenos"> 82</span></a><span class="sd">    A string with the response to the query, after displaying it to the</span>
+</span><span id="L-83"><a href="#L-83"><span class="linenos"> 83</span></a><span class="sd">    console.</span>
+</span><span id="L-84"><a href="#L-84"><span class="linenos"> 84</span></a><span class="sd">    &quot;&quot;&quot;</span>
+</span><span id="L-85"><a href="#L-85"><span class="linenos"> 85</span></a>    <span class="n">result</span> <span class="o">=</span> <span class="kc">None</span>
+</span><span id="L-86"><a href="#L-86"><span class="linenos"> 86</span></a>    <span class="n">userQuery</span> <span class="o">=</span> <span class="kc">None</span>
+</span><span id="L-87"><a href="#L-87"><span class="linenos"> 87</span></a>    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">tokens</span><span class="p">):</span>
+</span><span id="L-88"><a href="#L-88"><span class="linenos"> 88</span></a>        <span class="n">userQuery</span> <span class="o">=</span> <span class="s1">&#39;Concise, code only answer to this question: &#39;</span><span class="o">+</span><span class="s1">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">tokens</span><span class="p">)</span>
+</span><span id="L-89"><a href="#L-89"><span class="linenos"> 89</span></a>    <span class="k">elif</span> <span class="n">_stdinHasData</span><span class="p">():</span>
+</span><span id="L-90"><a href="#L-90"><span class="linenos"> 90</span></a>        <span class="n">userQuery</span> <span class="o">=</span> <span class="n">_assembleInput</span><span class="p">()</span>
+</span><span id="L-91"><a href="#L-91"><span class="linenos"> 91</span></a>        <span class="n">userQuery</span> <span class="o">=</span> <span class="s1">&#39;Give me a concise coding example to answer this question: &#39;</span><span class="o">+</span><span class="n">userQuery</span>
+</span><span id="L-92"><a href="#L-92"><span class="linenos"> 92</span></a>
+</span><span id="L-93"><a href="#L-93"><span class="linenos"> 93</span></a>    <span class="k">if</span> <span class="n">userQuery</span><span class="p">:</span>
+</span><span id="L-94"><a href="#L-94"><span class="linenos"> 94</span></a>        <span class="n">result</span> <span class="o">=</span> <span class="n">codexCore</span><span class="p">(</span><span class="n">userQuery</span><span class="p">)</span>
+</span><span id="L-95"><a href="#L-95"><span class="linenos"> 95</span></a>        <span class="n">click</span><span class="o">.</span><span class="n">echo</span><span class="p">(</span><span class="n">result</span><span class="p">)</span>
+</span><span id="L-96"><a href="#L-96"><span class="linenos"> 96</span></a>    <span class="k">else</span><span class="p">:</span>
+</span><span id="L-97"><a href="#L-97"><span class="linenos"> 97</span></a>        <span class="n">_die</span><span class="p">(</span><span class="n">_helpUser</span><span class="p">(),</span> <span class="mi">1</span><span class="p">)</span>
+</span><span id="L-98"><a href="#L-98"><span class="linenos"> 98</span></a>
+</span><span id="L-99"><a href="#L-99"><span class="linenos"> 99</span></a>    <span class="k">return</span> <span class="n">result</span>
+</span><span id="L-100"><a href="#L-100"><span class="linenos">100</span></a>
+</span><span id="L-101"><a href="#L-101"><span class="linenos">101</span></a>
+</span><span id="L-102"><a href="#L-102"><span class="linenos">102</span></a><span class="k">if</span> <span class="s1">&#39;__main__&#39;</span> <span class="o">==</span> <span class="vm">__name__</span><span class="p">:</span>
+</span><span id="L-103"><a href="#L-103"><span class="linenos">103</span></a>    <span class="n">codex</span><span class="p">()</span>
 </span></pre></div>
 
 
@@ -150,26 +177,26 @@ <h1 class="modulename">
 
     </div>
     <a class="headerlink" href="#codexCore"></a>
-            <div class="pdoc-code codehilite"><pre><span></span><span id="codexCore-25"><a href="#codexCore-25"><span class="linenos">25</span></a><span class="k">def</span> <span class="nf">codexCore</span><span class="p">(</span><span class="n">userQuery</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
-</span><span id="codexCore-26"><a href="#codexCore-26"><span class="linenos">26</span></a><span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
-</span><span id="codexCore-27"><a href="#codexCore-27"><span class="linenos">27</span></a><span class="sd">    Send a user query to the model for processing.</span>
-</span><span id="codexCore-28"><a href="#codexCore-28"><span class="linenos">28</span></a>
-</span><span id="codexCore-29"><a href="#codexCore-29"><span class="linenos">29</span></a><span class="sd">    Arguments</span>
-</span><span id="codexCore-30"><a href="#codexCore-30"><span class="linenos">30</span></a><span class="sd">    ---------</span>
-</span><span id="codexCore-31"><a href="#codexCore-31"><span class="linenos">31</span></a><span class="sd">        userQuery</span>
-</span><span id="codexCore-32"><a href="#codexCore-32"><span class="linenos">32</span></a><span class="sd">    A string with the user query, most often a programming question.</span>
-</span><span id="codexCore-33"><a href="#codexCore-33"><span class="linenos">33</span></a>
-</span><span id="codexCore-34"><a href="#codexCore-34"><span class="linenos">34</span></a><span class="sd">    Returns</span>
-</span><span id="codexCore-35"><a href="#codexCore-35"><span class="linenos">35</span></a><span class="sd">    -------</span>
-</span><span id="codexCore-36"><a href="#codexCore-36"><span class="linenos">36</span></a><span class="sd">    The result of the query, or `None` if the query was empty.</span>
-</span><span id="codexCore-37"><a href="#codexCore-37"><span class="linenos">37</span></a><span class="sd">    &quot;&quot;&quot;</span>
-</span><span id="codexCore-38"><a href="#codexCore-38"><span class="linenos">38</span></a>    <span class="n">result</span> <span class="o">=</span> <span class="kc">None</span>
-</span><span id="codexCore-39"><a href="#codexCore-39"><span class="linenos">39</span></a>    <span class="k">if</span> <span class="n">userQuery</span><span class="p">:</span>
-</span><span id="codexCore-40"><a href="#codexCore-40"><span class="linenos">40</span></a>        <span class="n">client</span> <span class="o">=</span> <span class="n">PerplexityClient</span><span class="p">(</span><span class="n">key</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;PERPLEXITY_API_KEY&#39;</span><span class="p">])</span>
-</span><span id="codexCore-41"><a href="#codexCore-41"><span class="linenos">41</span></a>        <span class="n">client</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="s1">&#39;codellama-70b-instruct&#39;</span>
-</span><span id="codexCore-42"><a href="#codexCore-42"><span class="linenos">42</span></a>        <span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">userQuery</span><span class="p">)</span>
-</span><span id="codexCore-43"><a href="#codexCore-43"><span class="linenos">43</span></a>
-</span><span id="codexCore-44"><a href="#codexCore-44"><span class="linenos">44</span></a>    <span class="k">return</span> <span class="n">result</span>
+            <div class="pdoc-code codehilite"><pre><span></span><span id="codexCore-26"><a href="#codexCore-26"><span class="linenos">26</span></a><span class="k">def</span> <span class="nf">codexCore</span><span class="p">(</span><span class="n">userQuery</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
+</span><span id="codexCore-27"><a href="#codexCore-27"><span class="linenos">27</span></a><span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
+</span><span id="codexCore-28"><a href="#codexCore-28"><span class="linenos">28</span></a><span class="sd">    Send a user query to the model for processing.</span>
+</span><span id="codexCore-29"><a href="#codexCore-29"><span class="linenos">29</span></a>
+</span><span id="codexCore-30"><a href="#codexCore-30"><span class="linenos">30</span></a><span class="sd">    Arguments</span>
+</span><span id="codexCore-31"><a href="#codexCore-31"><span class="linenos">31</span></a><span class="sd">    ---------</span>
+</span><span id="codexCore-32"><a href="#codexCore-32"><span class="linenos">32</span></a><span class="sd">        userQuery</span>
+</span><span id="codexCore-33"><a href="#codexCore-33"><span class="linenos">33</span></a><span class="sd">    A string with the user query, most often a programming question.</span>
+</span><span id="codexCore-34"><a href="#codexCore-34"><span class="linenos">34</span></a>
+</span><span id="codexCore-35"><a href="#codexCore-35"><span class="linenos">35</span></a><span class="sd">    Returns</span>
+</span><span id="codexCore-36"><a href="#codexCore-36"><span class="linenos">36</span></a><span class="sd">    -------</span>
+</span><span id="codexCore-37"><a href="#codexCore-37"><span class="linenos">37</span></a><span class="sd">    The result of the query, or `None` if the query was empty.</span>
+</span><span id="codexCore-38"><a href="#codexCore-38"><span class="linenos">38</span></a><span class="sd">    &quot;&quot;&quot;</span>
+</span><span id="codexCore-39"><a href="#codexCore-39"><span class="linenos">39</span></a>    <span class="n">result</span> <span class="o">=</span> <span class="kc">None</span>
+</span><span id="codexCore-40"><a href="#codexCore-40"><span class="linenos">40</span></a>    <span class="k">if</span> <span class="n">userQuery</span><span class="p">:</span>
+</span><span id="codexCore-41"><a href="#codexCore-41"><span class="linenos">41</span></a>        <span class="n">client</span> <span class="o">=</span> <span class="n">PerplexityClient</span><span class="p">(</span><span class="n">key</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;PERPLEXITY_API_KEY&#39;</span><span class="p">])</span>
+</span><span id="codexCore-42"><a href="#codexCore-42"><span class="linenos">42</span></a>        <span class="n">client</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="s1">&#39;codellama-70b-instruct&#39;</span>
+</span><span id="codexCore-43"><a href="#codexCore-43"><span class="linenos">43</span></a>        <span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">userQuery</span><span class="p">)</span>
+</span><span id="codexCore-44"><a href="#codexCore-44"><span class="linenos">44</span></a>
+</span><span id="codexCore-45"><a href="#codexCore-45"><span class="linenos">45</span></a>    <span class="k">return</span> <span class="n">result</span>
 </span></pre></div>
 
 
diff --git a/docs/search.js b/docs/search.js
index 67bfa84..1d65519 100644
--- a/docs/search.js
+++ b/docs/search.js
@@ -1,6 +1,6 @@
 window.pdocSearch = (function(){
 /** elasticlunr - http://weixsong.github.io * Copyright (C) 2017 Oliver Nightingale * Copyright (C) 2017 Wei Song * MIT Licensed */!function(){function e(e){if(null===e||"object"!=typeof e)return e;var t=e.constructor();for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}var t=function(e){var n=new t.Index;return n.pipeline.add(t.trimmer,t.stopWordFilter,t.stemmer),e&&e.call(n,n),n};t.version="0.9.5",lunr=t,t.utils={},t.utils.warn=function(e){return function(t){e.console&&console.warn&&console.warn(t)}}(this),t.utils.toString=function(e){return void 0===e||null===e?"":e.toString()},t.EventEmitter=function(){this.events={}},t.EventEmitter.prototype.addListener=function(){var e=Array.prototype.slice.call(arguments),t=e.pop(),n=e;if("function"!=typeof t)throw new TypeError("last argument must be a function");n.forEach(function(e){this.hasHandler(e)||(this.events[e]=[]),this.events[e].push(t)},this)},t.EventEmitter.prototype.removeListener=function(e,t){if(this.hasHandler(e)){var n=this.events[e].indexOf(t);-1!==n&&(this.events[e].splice(n,1),0==this.events[e].length&&delete this.events[e])}},t.EventEmitter.prototype.emit=function(e){if(this.hasHandler(e)){var t=Array.prototype.slice.call(arguments,1);this.events[e].forEach(function(e){e.apply(void 0,t)},this)}},t.EventEmitter.prototype.hasHandler=function(e){return e in this.events},t.tokenizer=function(e){if(!arguments.length||null===e||void 0===e)return[];if(Array.isArray(e)){var n=e.filter(function(e){return null===e||void 0===e?!1:!0});n=n.map(function(e){return t.utils.toString(e).toLowerCase()});var i=[];return n.forEach(function(e){var n=e.split(t.tokenizer.seperator);i=i.concat(n)},this),i}return e.toString().trim().toLowerCase().split(t.tokenizer.seperator)},t.tokenizer.defaultSeperator=/[\s\-]+/,t.tokenizer.seperator=t.tokenizer.defaultSeperator,t.tokenizer.setSeperator=function(e){null!==e&&void 0!==e&&"object"==typeof e&&(t.tokenizer.seperator=e)},t.tokenizer.resetSeperator=function(){t.tokenizer.seperator=t.tokenizer.defaultSeperator},t.tokenizer.getSeperator=function(){return t.tokenizer.seperator},t.Pipeline=function(){this._queue=[]},t.Pipeline.registeredFunctions={},t.Pipeline.registerFunction=function(e,n){n in t.Pipeline.registeredFunctions&&t.utils.warn("Overwriting existing registered function: "+n),e.label=n,t.Pipeline.registeredFunctions[n]=e},t.Pipeline.getRegisteredFunction=function(e){return e in t.Pipeline.registeredFunctions!=!0?null:t.Pipeline.registeredFunctions[e]},t.Pipeline.warnIfFunctionNotRegistered=function(e){var n=e.label&&e.label in this.registeredFunctions;n||t.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},t.Pipeline.load=function(e){var n=new t.Pipeline;return e.forEach(function(e){var i=t.Pipeline.getRegisteredFunction(e);if(!i)throw new Error("Cannot load un-registered function: "+e);n.add(i)}),n},t.Pipeline.prototype.add=function(){var e=Array.prototype.slice.call(arguments);e.forEach(function(e){t.Pipeline.warnIfFunctionNotRegistered(e),this._queue.push(e)},this)},t.Pipeline.prototype.after=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._queue.indexOf(e);if(-1===i)throw new Error("Cannot find existingFn");this._queue.splice(i+1,0,n)},t.Pipeline.prototype.before=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._queue.indexOf(e);if(-1===i)throw new Error("Cannot find existingFn");this._queue.splice(i,0,n)},t.Pipeline.prototype.remove=function(e){var t=this._queue.indexOf(e);-1!==t&&this._queue.splice(t,1)},t.Pipeline.prototype.run=function(e){for(var t=[],n=e.length,i=this._queue.length,o=0;n>o;o++){for(var r=e[o],s=0;i>s&&(r=this._queue[s](r,o,e),void 0!==r&&null!==r);s++);void 0!==r&&null!==r&&t.push(r)}return t},t.Pipeline.prototype.reset=function(){this._queue=[]},t.Pipeline.prototype.get=function(){return this._queue},t.Pipeline.prototype.toJSON=function(){return this._queue.map(function(e){return t.Pipeline.warnIfFunctionNotRegistered(e),e.label})},t.Index=function(){this._fields=[],this._ref="id",this.pipeline=new t.Pipeline,this.documentStore=new t.DocumentStore,this.index={},this.eventEmitter=new t.EventEmitter,this._idfCache={},this.on("add","remove","update",function(){this._idfCache={}}.bind(this))},t.Index.prototype.on=function(){var e=Array.prototype.slice.call(arguments);return this.eventEmitter.addListener.apply(this.eventEmitter,e)},t.Index.prototype.off=function(e,t){return this.eventEmitter.removeListener(e,t)},t.Index.load=function(e){e.version!==t.version&&t.utils.warn("version mismatch: current "+t.version+" importing "+e.version);var n=new this;n._fields=e.fields,n._ref=e.ref,n.documentStore=t.DocumentStore.load(e.documentStore),n.pipeline=t.Pipeline.load(e.pipeline),n.index={};for(var i in e.index)n.index[i]=t.InvertedIndex.load(e.index[i]);return n},t.Index.prototype.addField=function(e){return this._fields.push(e),this.index[e]=new t.InvertedIndex,this},t.Index.prototype.setRef=function(e){return this._ref=e,this},t.Index.prototype.saveDocument=function(e){return this.documentStore=new t.DocumentStore(e),this},t.Index.prototype.addDoc=function(e,n){if(e){var n=void 0===n?!0:n,i=e[this._ref];this.documentStore.addDoc(i,e),this._fields.forEach(function(n){var o=this.pipeline.run(t.tokenizer(e[n]));this.documentStore.addFieldLength(i,n,o.length);var r={};o.forEach(function(e){e in r?r[e]+=1:r[e]=1},this);for(var s in r){var u=r[s];u=Math.sqrt(u),this.index[n].addToken(s,{ref:i,tf:u})}},this),n&&this.eventEmitter.emit("add",e,this)}},t.Index.prototype.removeDocByRef=function(e){if(e&&this.documentStore.isDocStored()!==!1&&this.documentStore.hasDoc(e)){var t=this.documentStore.getDoc(e);this.removeDoc(t,!1)}},t.Index.prototype.removeDoc=function(e,n){if(e){var n=void 0===n?!0:n,i=e[this._ref];this.documentStore.hasDoc(i)&&(this.documentStore.removeDoc(i),this._fields.forEach(function(n){var o=this.pipeline.run(t.tokenizer(e[n]));o.forEach(function(e){this.index[n].removeToken(e,i)},this)},this),n&&this.eventEmitter.emit("remove",e,this))}},t.Index.prototype.updateDoc=function(e,t){var t=void 0===t?!0:t;this.removeDocByRef(e[this._ref],!1),this.addDoc(e,!1),t&&this.eventEmitter.emit("update",e,this)},t.Index.prototype.idf=function(e,t){var n="@"+t+"/"+e;if(Object.prototype.hasOwnProperty.call(this._idfCache,n))return this._idfCache[n];var i=this.index[t].getDocFreq(e),o=1+Math.log(this.documentStore.length/(i+1));return this._idfCache[n]=o,o},t.Index.prototype.getFields=function(){return this._fields.slice()},t.Index.prototype.search=function(e,n){if(!e)return[];e="string"==typeof e?{any:e}:JSON.parse(JSON.stringify(e));var i=null;null!=n&&(i=JSON.stringify(n));for(var o=new t.Configuration(i,this.getFields()).get(),r={},s=Object.keys(e),u=0;u<s.length;u++){var a=s[u];r[a]=this.pipeline.run(t.tokenizer(e[a]))}var l={};for(var c in o){var d=r[c]||r.any;if(d){var f=this.fieldSearch(d,c,o),h=o[c].boost;for(var p in f)f[p]=f[p]*h;for(var p in f)p in l?l[p]+=f[p]:l[p]=f[p]}}var v,g=[];for(var p in l)v={ref:p,score:l[p]},this.documentStore.hasDoc(p)&&(v.doc=this.documentStore.getDoc(p)),g.push(v);return g.sort(function(e,t){return t.score-e.score}),g},t.Index.prototype.fieldSearch=function(e,t,n){var i=n[t].bool,o=n[t].expand,r=n[t].boost,s=null,u={};return 0!==r?(e.forEach(function(e){var n=[e];1==o&&(n=this.index[t].expandToken(e));var r={};n.forEach(function(n){var o=this.index[t].getDocs(n),a=this.idf(n,t);if(s&&"AND"==i){var l={};for(var c in s)c in o&&(l[c]=o[c]);o=l}n==e&&this.fieldSearchStats(u,n,o);for(var c in o){var d=this.index[t].getTermFrequency(n,c),f=this.documentStore.getFieldLength(c,t),h=1;0!=f&&(h=1/Math.sqrt(f));var p=1;n!=e&&(p=.15*(1-(n.length-e.length)/n.length));var v=d*a*h*p;c in r?r[c]+=v:r[c]=v}},this),s=this.mergeScores(s,r,i)},this),s=this.coordNorm(s,u,e.length)):void 0},t.Index.prototype.mergeScores=function(e,t,n){if(!e)return t;if("AND"==n){var i={};for(var o in t)o in e&&(i[o]=e[o]+t[o]);return i}for(var o in t)o in e?e[o]+=t[o]:e[o]=t[o];return e},t.Index.prototype.fieldSearchStats=function(e,t,n){for(var i in n)i in e?e[i].push(t):e[i]=[t]},t.Index.prototype.coordNorm=function(e,t,n){for(var i in e)if(i in t){var o=t[i].length;e[i]=e[i]*o/n}return e},t.Index.prototype.toJSON=function(){var e={};return this._fields.forEach(function(t){e[t]=this.index[t].toJSON()},this),{version:t.version,fields:this._fields,ref:this._ref,documentStore:this.documentStore.toJSON(),index:e,pipeline:this.pipeline.toJSON()}},t.Index.prototype.use=function(e){var t=Array.prototype.slice.call(arguments,1);t.unshift(this),e.apply(this,t)},t.DocumentStore=function(e){this._save=null===e||void 0===e?!0:e,this.docs={},this.docInfo={},this.length=0},t.DocumentStore.load=function(e){var t=new this;return t.length=e.length,t.docs=e.docs,t.docInfo=e.docInfo,t._save=e.save,t},t.DocumentStore.prototype.isDocStored=function(){return this._save},t.DocumentStore.prototype.addDoc=function(t,n){this.hasDoc(t)||this.length++,this.docs[t]=this._save===!0?e(n):null},t.DocumentStore.prototype.getDoc=function(e){return this.hasDoc(e)===!1?null:this.docs[e]},t.DocumentStore.prototype.hasDoc=function(e){return e in this.docs},t.DocumentStore.prototype.removeDoc=function(e){this.hasDoc(e)&&(delete this.docs[e],delete this.docInfo[e],this.length--)},t.DocumentStore.prototype.addFieldLength=function(e,t,n){null!==e&&void 0!==e&&0!=this.hasDoc(e)&&(this.docInfo[e]||(this.docInfo[e]={}),this.docInfo[e][t]=n)},t.DocumentStore.prototype.updateFieldLength=function(e,t,n){null!==e&&void 0!==e&&0!=this.hasDoc(e)&&this.addFieldLength(e,t,n)},t.DocumentStore.prototype.getFieldLength=function(e,t){return null===e||void 0===e?0:e in this.docs&&t in this.docInfo[e]?this.docInfo[e][t]:0},t.DocumentStore.prototype.toJSON=function(){return{docs:this.docs,docInfo:this.docInfo,length:this.length,save:this._save}},t.stemmer=function(){var e={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log"},t={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},n="[^aeiou]",i="[aeiouy]",o=n+"[^aeiouy]*",r=i+"[aeiou]*",s="^("+o+")?"+r+o,u="^("+o+")?"+r+o+"("+r+")?$",a="^("+o+")?"+r+o+r+o,l="^("+o+")?"+i,c=new RegExp(s),d=new RegExp(a),f=new RegExp(u),h=new RegExp(l),p=/^(.+?)(ss|i)es$/,v=/^(.+?)([^s])s$/,g=/^(.+?)eed$/,m=/^(.+?)(ed|ing)$/,y=/.$/,S=/(at|bl|iz)$/,x=new RegExp("([^aeiouylsz])\\1$"),w=new RegExp("^"+o+i+"[^aeiouwxy]$"),I=/^(.+?[^aeiou])y$/,b=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,E=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,D=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,F=/^(.+?)(s|t)(ion)$/,_=/^(.+?)e$/,P=/ll$/,k=new RegExp("^"+o+i+"[^aeiouwxy]$"),z=function(n){var i,o,r,s,u,a,l;if(n.length<3)return n;if(r=n.substr(0,1),"y"==r&&(n=r.toUpperCase()+n.substr(1)),s=p,u=v,s.test(n)?n=n.replace(s,"$1$2"):u.test(n)&&(n=n.replace(u,"$1$2")),s=g,u=m,s.test(n)){var z=s.exec(n);s=c,s.test(z[1])&&(s=y,n=n.replace(s,""))}else if(u.test(n)){var z=u.exec(n);i=z[1],u=h,u.test(i)&&(n=i,u=S,a=x,l=w,u.test(n)?n+="e":a.test(n)?(s=y,n=n.replace(s,"")):l.test(n)&&(n+="e"))}if(s=I,s.test(n)){var z=s.exec(n);i=z[1],n=i+"i"}if(s=b,s.test(n)){var z=s.exec(n);i=z[1],o=z[2],s=c,s.test(i)&&(n=i+e[o])}if(s=E,s.test(n)){var z=s.exec(n);i=z[1],o=z[2],s=c,s.test(i)&&(n=i+t[o])}if(s=D,u=F,s.test(n)){var z=s.exec(n);i=z[1],s=d,s.test(i)&&(n=i)}else if(u.test(n)){var z=u.exec(n);i=z[1]+z[2],u=d,u.test(i)&&(n=i)}if(s=_,s.test(n)){var z=s.exec(n);i=z[1],s=d,u=f,a=k,(s.test(i)||u.test(i)&&!a.test(i))&&(n=i)}return s=P,u=d,s.test(n)&&u.test(n)&&(s=y,n=n.replace(s,"")),"y"==r&&(n=r.toLowerCase()+n.substr(1)),n};return z}(),t.Pipeline.registerFunction(t.stemmer,"stemmer"),t.stopWordFilter=function(e){return e&&t.stopWordFilter.stopWords[e]!==!0?e:void 0},t.clearStopWords=function(){t.stopWordFilter.stopWords={}},t.addStopWords=function(e){null!=e&&Array.isArray(e)!==!1&&e.forEach(function(e){t.stopWordFilter.stopWords[e]=!0},this)},t.resetStopWords=function(){t.stopWordFilter.stopWords=t.defaultStopWords},t.defaultStopWords={"":!0,a:!0,able:!0,about:!0,across:!0,after:!0,all:!0,almost:!0,also:!0,am:!0,among:!0,an:!0,and:!0,any:!0,are:!0,as:!0,at:!0,be:!0,because:!0,been:!0,but:!0,by:!0,can:!0,cannot:!0,could:!0,dear:!0,did:!0,"do":!0,does:!0,either:!0,"else":!0,ever:!0,every:!0,"for":!0,from:!0,get:!0,got:!0,had:!0,has:!0,have:!0,he:!0,her:!0,hers:!0,him:!0,his:!0,how:!0,however:!0,i:!0,"if":!0,"in":!0,into:!0,is:!0,it:!0,its:!0,just:!0,least:!0,let:!0,like:!0,likely:!0,may:!0,me:!0,might:!0,most:!0,must:!0,my:!0,neither:!0,no:!0,nor:!0,not:!0,of:!0,off:!0,often:!0,on:!0,only:!0,or:!0,other:!0,our:!0,own:!0,rather:!0,said:!0,say:!0,says:!0,she:!0,should:!0,since:!0,so:!0,some:!0,than:!0,that:!0,the:!0,their:!0,them:!0,then:!0,there:!0,these:!0,they:!0,"this":!0,tis:!0,to:!0,too:!0,twas:!0,us:!0,wants:!0,was:!0,we:!0,were:!0,what:!0,when:!0,where:!0,which:!0,"while":!0,who:!0,whom:!0,why:!0,will:!0,"with":!0,would:!0,yet:!0,you:!0,your:!0},t.stopWordFilter.stopWords=t.defaultStopWords,t.Pipeline.registerFunction(t.stopWordFilter,"stopWordFilter"),t.trimmer=function(e){if(null===e||void 0===e)throw new Error("token should not be undefined");return e.replace(/^\W+/,"").replace(/\W+$/,"")},t.Pipeline.registerFunction(t.trimmer,"trimmer"),t.InvertedIndex=function(){this.root={docs:{},df:0}},t.InvertedIndex.load=function(e){var t=new this;return t.root=e.root,t},t.InvertedIndex.prototype.addToken=function(e,t,n){for(var n=n||this.root,i=0;i<=e.length-1;){var o=e[i];o in n||(n[o]={docs:{},df:0}),i+=1,n=n[o]}var r=t.ref;n.docs[r]?n.docs[r]={tf:t.tf}:(n.docs[r]={tf:t.tf},n.df+=1)},t.InvertedIndex.prototype.hasToken=function(e){if(!e)return!1;for(var t=this.root,n=0;n<e.length;n++){if(!t[e[n]])return!1;t=t[e[n]]}return!0},t.InvertedIndex.prototype.getNode=function(e){if(!e)return null;for(var t=this.root,n=0;n<e.length;n++){if(!t[e[n]])return null;t=t[e[n]]}return t},t.InvertedIndex.prototype.getDocs=function(e){var t=this.getNode(e);return null==t?{}:t.docs},t.InvertedIndex.prototype.getTermFrequency=function(e,t){var n=this.getNode(e);return null==n?0:t in n.docs?n.docs[t].tf:0},t.InvertedIndex.prototype.getDocFreq=function(e){var t=this.getNode(e);return null==t?0:t.df},t.InvertedIndex.prototype.removeToken=function(e,t){if(e){var n=this.getNode(e);null!=n&&t in n.docs&&(delete n.docs[t],n.df-=1)}},t.InvertedIndex.prototype.expandToken=function(e,t,n){if(null==e||""==e)return[];var t=t||[];if(void 0==n&&(n=this.getNode(e),null==n))return t;n.df>0&&t.push(e);for(var i in n)"docs"!==i&&"df"!==i&&this.expandToken(e+i,t,n[i]);return t},t.InvertedIndex.prototype.toJSON=function(){return{root:this.root}},t.Configuration=function(e,n){var e=e||"";if(void 0==n||null==n)throw new Error("fields should not be null");this.config={};var i;try{i=JSON.parse(e),this.buildUserConfig(i,n)}catch(o){t.utils.warn("user configuration parse failed, will use default configuration"),this.buildDefaultConfig(n)}},t.Configuration.prototype.buildDefaultConfig=function(e){this.reset(),e.forEach(function(e){this.config[e]={boost:1,bool:"OR",expand:!1}},this)},t.Configuration.prototype.buildUserConfig=function(e,n){var i="OR",o=!1;if(this.reset(),"bool"in e&&(i=e.bool||i),"expand"in e&&(o=e.expand||o),"fields"in e)for(var r in e.fields)if(n.indexOf(r)>-1){var s=e.fields[r],u=o;void 0!=s.expand&&(u=s.expand),this.config[r]={boost:s.boost||0===s.boost?s.boost:1,bool:s.bool||i,expand:u}}else t.utils.warn("field name in user configuration not found in index instance fields");else this.addAllFields2UserConfig(i,o,n)},t.Configuration.prototype.addAllFields2UserConfig=function(e,t,n){n.forEach(function(n){this.config[n]={boost:1,bool:e,expand:t}},this)},t.Configuration.prototype.get=function(){return this.config},t.Configuration.prototype.reset=function(){this.config={}},lunr.SortedSet=function(){this.length=0,this.elements=[]},lunr.SortedSet.load=function(e){var t=new this;return t.elements=e,t.length=e.length,t},lunr.SortedSet.prototype.add=function(){var e,t;for(e=0;e<arguments.length;e++)t=arguments[e],~this.indexOf(t)||this.elements.splice(this.locationFor(t),0,t);this.length=this.elements.length},lunr.SortedSet.prototype.toArray=function(){return this.elements.slice()},lunr.SortedSet.prototype.map=function(e,t){return this.elements.map(e,t)},lunr.SortedSet.prototype.forEach=function(e,t){return this.elements.forEach(e,t)},lunr.SortedSet.prototype.indexOf=function(e){for(var t=0,n=this.elements.length,i=n-t,o=t+Math.floor(i/2),r=this.elements[o];i>1;){if(r===e)return o;e>r&&(t=o),r>e&&(n=o),i=n-t,o=t+Math.floor(i/2),r=this.elements[o]}return r===e?o:-1},lunr.SortedSet.prototype.locationFor=function(e){for(var t=0,n=this.elements.length,i=n-t,o=t+Math.floor(i/2),r=this.elements[o];i>1;)e>r&&(t=o),r>e&&(n=o),i=n-t,o=t+Math.floor(i/2),r=this.elements[o];return r>e?o:e>r?o+1:void 0},lunr.SortedSet.prototype.intersect=function(e){for(var t=new lunr.SortedSet,n=0,i=0,o=this.length,r=e.length,s=this.elements,u=e.elements;;){if(n>o-1||i>r-1)break;s[n]!==u[i]?s[n]<u[i]?n++:s[n]>u[i]&&i++:(t.add(s[n]),n++,i++)}return t},lunr.SortedSet.prototype.clone=function(){var e=new lunr.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},lunr.SortedSet.prototype.union=function(e){var t,n,i;this.length>=e.length?(t=this,n=e):(t=e,n=this),i=t.clone();for(var o=0,r=n.toArray();o<r.length;o++)i.add(r[o]);return i},lunr.SortedSet.prototype.toJSON=function(){return this.toArray()},function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t():e.elasticlunr=t()}(this,function(){return t})}();
-    /** pdoc search index */const docs = [{"fullname": "perplexipy", "modulename": "perplexipy", "kind": "module", "doc": "<p></p>\n"}, {"fullname": "perplexipy.PERPLEXITY_API_KEY", "modulename": "perplexipy", "qualname": "PERPLEXITY_API_KEY", "kind": "variable", "doc": "<p></p>\n", "default_value": "$PERPLEXITY_API_KEY"}, {"fullname": "perplexipy.PERPLEXITY_API_PREFIX", "modulename": "perplexipy", "qualname": "PERPLEXITY_API_PREFIX", "kind": "variable", "doc": "<p></p>\n", "default_value": "&#x27;pplx-&#x27;"}, {"fullname": "perplexipy.PERPLEXITY_API_URL", "modulename": "perplexipy", "qualname": "PERPLEXITY_API_URL", "kind": "variable", "doc": "<p>The default model is <strong>mistral-7b-instruct</strong> because of it's efficiency and\nperformance qualities.  Ref:  <a href=\"https://arxiv.org/abs/2310.06825\">https://arxiv.org/abs/2310.06825</a></p>\n", "default_value": "&#x27;https://api.perplexity.ai&#x27;"}, {"fullname": "perplexipy.PERPLEXITY_DEFAULT_MODEL", "modulename": "perplexipy", "qualname": "PERPLEXITY_DEFAULT_MODEL", "kind": "variable", "doc": "<p></p>\n", "default_value": "&#x27;mistral-7b-instruct&#x27;"}, {"fullname": "perplexipy.PERPLEXITY_DEFAULT_ROLE", "modulename": "perplexipy", "qualname": "PERPLEXITY_DEFAULT_ROLE", "kind": "variable", "doc": "<p></p>\n", "default_value": "&#x27;user&#x27;"}, {"fullname": "perplexipy.PERPLEXITY_TIMEOUT", "modulename": "perplexipy", "qualname": "PERPLEXITY_TIMEOUT", "kind": "variable", "doc": "<p></p>\n", "default_value": "30.0"}, {"fullname": "perplexipy.PERPLEXITY_VALID_ROLES", "modulename": "perplexipy", "qualname": "PERPLEXITY_VALID_ROLES", "kind": "variable", "doc": "<p>Immutable dictionary-like object of a model's capabilities.  Use <code>_asDict()</code> if\ndictionary manipulation is required.</p>\n", "default_value": "{&#x27;user&#x27;, &#x27;system&#x27;, &#x27;assistant&#x27;}"}, {"fullname": "perplexipy.ModelInfo", "modulename": "perplexipy", "qualname": "ModelInfo", "kind": "class", "doc": "<p>ModelInfo(parameterCount, contextLength, modelType, availability)</p>\n", "bases": "builtins.tuple"}, {"fullname": "perplexipy.ModelInfo.__init__", "modulename": "perplexipy", "qualname": "ModelInfo.__init__", "kind": "function", "doc": "<p>Create new instance of ModelInfo(parameterCount, contextLength, modelType, availability)</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">parameterCount</span>, </span><span class=\"param\"><span class=\"n\">contextLength</span>, </span><span class=\"param\"><span class=\"n\">modelType</span>, </span><span class=\"param\"><span class=\"n\">availability</span></span>)</span>"}, {"fullname": "perplexipy.ModelInfo.parameterCount", "modulename": "perplexipy", "qualname": "ModelInfo.parameterCount", "kind": "variable", "doc": "<p>Alias for field number 0</p>\n"}, {"fullname": "perplexipy.ModelInfo.contextLength", "modulename": "perplexipy", "qualname": "ModelInfo.contextLength", "kind": "variable", "doc": "<p>Alias for field number 1</p>\n"}, {"fullname": "perplexipy.ModelInfo.modelType", "modulename": "perplexipy", "qualname": "ModelInfo.modelType", "kind": "variable", "doc": "<p>Alias for field number 2</p>\n"}, {"fullname": "perplexipy.ModelInfo.availability", "modulename": "perplexipy", "qualname": "ModelInfo.availability", "kind": "variable", "doc": "<p>Alias for field number 3</p>\n"}, {"fullname": "perplexipy.PerplexityClient", "modulename": "perplexipy", "qualname": "PerplexityClient", "kind": "class", "doc": "<p>PerplexityClient objects encapsulate all the API functionality.  They can be\ninstantiated across multiple contexts, each keeping its own state.</p>\n"}, {"fullname": "perplexipy.PerplexityClient.__init__", "modulename": "perplexipy", "qualname": "PerplexityClient.__init__", "kind": "function", "doc": "<p>Create a new instance of <code>perplexipy.PerplexityClient</code> using the API\n<code>key</code> to connect to the corresponding <code>endpoint</code>.</p>\n\n<h2 id=\"arguments\">Arguments</h2>\n\n<pre><code>key\n</code></pre>\n\n<p>A valid API key string.  If not present, it defaults to <code>perplexipy.PERPLEXITY_API_KEY</code>.</p>\n\n<pre><code>endpoint\n</code></pre>\n\n<p>An string representing a URL to the Perplexity API.</p>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>An instance of <code>perplexipy.PerplexityClient</code> if successful.</p>\n\n<p>Attributes:</p>\n\n<p><code>model</code> - the current model to use in queries, user configurable.</p>\n\n<p>The role is fixed to <code>\"user\"</code> for Perplexity calls, per the API\nrecommendations.</p>\n\n<h2 id=\"raises\">Raises</h2>\n\n<pre><code>PerplexityClientError\n</code></pre>\n\n<p>If the API key is empty, or doesn't match one of the valid API prefixes\nper the documentation.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">key</span><span class=\"p\">:</span> <span class=\"nb\">str</span>, </span><span class=\"param\"><span class=\"n\">endpoint</span><span class=\"p\">:</span> <span class=\"nb\">str</span> <span class=\"o\">=</span> <span class=\"s1\">&#39;https://api.perplexity.ai&#39;</span></span>)</span>"}, {"fullname": "perplexipy.PerplexityClient.query", "modulename": "perplexipy", "qualname": "PerplexityClient.query", "kind": "function", "doc": "<p>Send a single message query to the service, receive a single response.</p>\n\n<h2 id=\"arguments\">Arguments</h2>\n\n<pre><code>query\n</code></pre>\n\n<p>A string with the query in one of the model's supported languages.</p>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>A string with a response from the Perplexity service.</p>\n\n<h2 id=\"raises\">Raises</h2>\n\n<pre><code>Exception\n</code></pre>\n\n<p>An <code>openai.BadRequestError</code> or similar if the query is malformed or has\nsomething other than text data.  The error raised passes through\nwhatever the API raised.</p>\n\n<p>In most cases, the API returns <code>openai.BadRequestError</code>.</p>\n\n<pre><code>PerplexityClientError\n</code></pre>\n\n<p>If the query is <code>None</code> or empty.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"bp\">self</span>, </span><span class=\"param\"><span class=\"n\">query</span><span class=\"p\">:</span> <span class=\"nb\">str</span></span><span class=\"return-annotation\">) -> <span class=\"nb\">str</span>:</span></span>", "funcdef": "def"}, {"fullname": "perplexipy.PerplexityClient.queryBatch", "modulename": "perplexipy", "qualname": "PerplexityClient.queryBatch", "kind": "function", "doc": "<p>Send a single message query to the service, receive a single response.</p>\n\n<h2 id=\"arguments\">Arguments</h2>\n\n<pre><code>query\n</code></pre>\n\n<p>A string with the query in one of the model's supported languages.</p>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>A tuple with a batch of 1 or more response strings.</p>\n\n<h2 id=\"raises\">Raises</h2>\n\n<pre><code>Exception\n</code></pre>\n\n<p>An <code>openai.BadRequestError</code> or similar if the query is malformed or has\nsomething other than text data.  The error raised passes through\nwhatever the API raised.</p>\n\n<p>In most cases, the API returns <code>openai.BadRequestError</code>.</p>\n\n<pre><code>PerplexityClientError\n</code></pre>\n\n<p>If the query is <code>None</code> or empty.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"bp\">self</span>, </span><span class=\"param\"><span class=\"n\">query</span><span class=\"p\">:</span> <span class=\"nb\">str</span></span><span class=\"return-annotation\">) -> <span class=\"nb\">tuple</span>:</span></span>", "funcdef": "def"}, {"fullname": "perplexipy.PerplexityClient.queryStreamable", "modulename": "perplexipy", "qualname": "PerplexityClient.queryStreamable", "kind": "function", "doc": "<p>Send a query and return a long, streamable response.</p>\n\n<h2 id=\"arguments\">Arguments</h2>\n\n<pre><code>query\n</code></pre>\n\n<p>A string with the query in one of the model's supported languages.</p>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>Returns a <code>perplexipy.Responses</code> object for streaming the textual\nresponses from the client.  The response strips all metadata and returns\nonly content strings, for simpler and easier integration.</p>\n\n<h2 id=\"raises\">Raises</h2>\n\n<pre><code>Exception\n</code></pre>\n\n<p>An <code>openai.BadRequestError</code> or similar if the query is malformed or has\nsomething other than text data.  The error raised passes through\nwhatever the API raised.</p>\n\n<p>In most cases, the API returns <code>openai.BadRequestError</code>.</p>\n\n<pre><code>PerplexityClientError\n</code></pre>\n\n<p>If the query is <code>None</code> or empty.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"bp\">self</span>, </span><span class=\"param\"><span class=\"n\">query</span><span class=\"p\">:</span> <span class=\"nb\">str</span></span><span class=\"return-annotation\">) -> <span class=\"n\">perplexipy</span><span class=\"o\">.</span><span class=\"n\">responses</span><span class=\"o\">.</span><span class=\"n\">Responses</span>:</span></span>", "funcdef": "def"}, {"fullname": "perplexipy.PerplexityClient.models", "modulename": "perplexipy", "qualname": "PerplexityClient.models", "kind": "variable", "doc": "<p>Provide a dictionary of the models supported by Perplexity listed in:</p>\n\n<p><a href=\"https://docs.perplexity.ai/docs/model-cards\">https://docs.perplexity.ai/docs/model-cards</a></p>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>A dictionary of supported models as the key, with a <code>perplexypy.ModelInfo</code>\nnamed tuple with the model capabilities description.  The model\ninformation attributes are:</p>\n\n<ul>\n<li><code>parameterCount</code></li>\n<li><code>contextLength</code></li>\n<li><code>modelType</code></li>\n<li><code>availability</code></li>\n</ul>\n"}, {"fullname": "perplexipy.PerplexityClient.model", "modulename": "perplexipy", "qualname": "PerplexityClient.model", "kind": "variable", "doc": "<p>Return the model the client uses for requesting responses from the\nservice provider.  Its default value is:  <code>PERPLEXITY_DEFAULT_MODEL</code>.</p>\n", "annotation": ": str"}, {"fullname": "perplexipy.codex", "modulename": "perplexipy.codex", "kind": "module", "doc": "<p></p>\n"}, {"fullname": "perplexipy.codex.codexCore", "modulename": "perplexipy.codex", "qualname": "codexCore", "kind": "function", "doc": "<p>Send a user query to the model for processing.</p>\n\n<h2 id=\"arguments\">Arguments</h2>\n\n<pre><code>userQuery\n</code></pre>\n\n<p>A string with the user query, most often a programming question.</p>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>The result of the query, or <code>None</code> if the query was empty.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">userQuery</span><span class=\"p\">:</span> <span class=\"nb\">str</span></span><span class=\"return-annotation\">) -> <span class=\"nb\">str</span>:</span></span>", "funcdef": "def"}, {"fullname": "perplexipy.codex.codex", "modulename": "perplexipy.codex", "qualname": "codex", "kind": "variable", "doc": "<p>Process a command line query and display the result to the console.</p>\n\n<h2 id=\"arguments\">Arguments</h2>\n\n<pre><code>tokens\n</code></pre>\n\n<p>A list of tokens that will be assembled as a single string for\nprocessing.</p>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>A string with the response to the query, after displaying it to the\nconsole.</p>\n", "default_value": "&lt;Command codex&gt;"}, {"fullname": "perplexipy.errors", "modulename": "perplexipy.errors", "kind": "module", "doc": "<p></p>\n"}, {"fullname": "perplexipy.errors.PerplexityClientError", "modulename": "perplexipy.errors", "qualname": "PerplexityClientError", "kind": "class", "doc": "<p>Perplexity client generic errors, for cleaner exception handling.</p>\n", "bases": "builtins.Exception"}, {"fullname": "perplexipy.errors.PerplexityClientError.__init__", "modulename": "perplexipy.errors", "qualname": "PerplexityClientError.__init__", "kind": "function", "doc": "<p></p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">errorMessage</span></span>)</span>"}, {"fullname": "perplexipy.responses", "modulename": "perplexipy.responses", "kind": "module", "doc": "<p></p>\n"}, {"fullname": "perplexipy.responses.Responses", "modulename": "perplexipy.responses", "qualname": "Responses", "kind": "class", "doc": "<p>Encapsulates all the streaming responses from a query and enables access to\nit using a purpose-built iterable.  Strips all the OpenAI response metadata\nand returns only the textual response.  It's a streaming iterable,\nopen-ended.</p>\n"}, {"fullname": "perplexipy.responses.Responses.__init__", "modulename": "perplexipy.responses", "qualname": "Responses.__init__", "kind": "function", "doc": "<p></p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">responsesStream</span></span>)</span>"}];
+    /** pdoc search index */const docs = [{"fullname": "perplexipy", "modulename": "perplexipy", "kind": "module", "doc": "<p></p>\n"}, {"fullname": "perplexipy.PERPLEXITY_API_KEY", "modulename": "perplexipy", "qualname": "PERPLEXITY_API_KEY", "kind": "variable", "doc": "<p></p>\n", "default_value": "$PERPLEXITY_API_KEY"}, {"fullname": "perplexipy.PERPLEXITY_API_PREFIX", "modulename": "perplexipy", "qualname": "PERPLEXITY_API_PREFIX", "kind": "variable", "doc": "<p></p>\n", "default_value": "&#x27;pplx-&#x27;"}, {"fullname": "perplexipy.PERPLEXITY_API_URL", "modulename": "perplexipy", "qualname": "PERPLEXITY_API_URL", "kind": "variable", "doc": "<p>The default model is <strong>mistral-7b-instruct</strong> because of it's efficiency and\nperformance qualities.  Ref:  <a href=\"https://arxiv.org/abs/2310.06825\">https://arxiv.org/abs/2310.06825</a></p>\n", "default_value": "&#x27;https://api.perplexity.ai&#x27;"}, {"fullname": "perplexipy.PERPLEXITY_DEFAULT_MODEL", "modulename": "perplexipy", "qualname": "PERPLEXITY_DEFAULT_MODEL", "kind": "variable", "doc": "<p></p>\n", "default_value": "&#x27;mistral-7b-instruct&#x27;"}, {"fullname": "perplexipy.PERPLEXITY_DEFAULT_ROLE", "modulename": "perplexipy", "qualname": "PERPLEXITY_DEFAULT_ROLE", "kind": "variable", "doc": "<p></p>\n", "default_value": "&#x27;user&#x27;"}, {"fullname": "perplexipy.PERPLEXITY_TIMEOUT", "modulename": "perplexipy", "qualname": "PERPLEXITY_TIMEOUT", "kind": "variable", "doc": "<p></p>\n", "default_value": "30.0"}, {"fullname": "perplexipy.PERPLEXITY_VALID_ROLES", "modulename": "perplexipy", "qualname": "PERPLEXITY_VALID_ROLES", "kind": "variable", "doc": "<p>Immutable dictionary-like object of a model's capabilities.  Use <code>_asDict()</code> if\ndictionary manipulation is required.</p>\n", "default_value": "{&#x27;system&#x27;, &#x27;assistant&#x27;, &#x27;user&#x27;}"}, {"fullname": "perplexipy.ModelInfo", "modulename": "perplexipy", "qualname": "ModelInfo", "kind": "class", "doc": "<p>ModelInfo(parameterCount, contextLength, modelType, availability)</p>\n", "bases": "builtins.tuple"}, {"fullname": "perplexipy.ModelInfo.__init__", "modulename": "perplexipy", "qualname": "ModelInfo.__init__", "kind": "function", "doc": "<p>Create new instance of ModelInfo(parameterCount, contextLength, modelType, availability)</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">parameterCount</span>, </span><span class=\"param\"><span class=\"n\">contextLength</span>, </span><span class=\"param\"><span class=\"n\">modelType</span>, </span><span class=\"param\"><span class=\"n\">availability</span></span>)</span>"}, {"fullname": "perplexipy.ModelInfo.parameterCount", "modulename": "perplexipy", "qualname": "ModelInfo.parameterCount", "kind": "variable", "doc": "<p>Alias for field number 0</p>\n"}, {"fullname": "perplexipy.ModelInfo.contextLength", "modulename": "perplexipy", "qualname": "ModelInfo.contextLength", "kind": "variable", "doc": "<p>Alias for field number 1</p>\n"}, {"fullname": "perplexipy.ModelInfo.modelType", "modulename": "perplexipy", "qualname": "ModelInfo.modelType", "kind": "variable", "doc": "<p>Alias for field number 2</p>\n"}, {"fullname": "perplexipy.ModelInfo.availability", "modulename": "perplexipy", "qualname": "ModelInfo.availability", "kind": "variable", "doc": "<p>Alias for field number 3</p>\n"}, {"fullname": "perplexipy.PerplexityClient", "modulename": "perplexipy", "qualname": "PerplexityClient", "kind": "class", "doc": "<p>PerplexityClient objects encapsulate all the API functionality.  They can be\ninstantiated across multiple contexts, each keeping its own state.</p>\n"}, {"fullname": "perplexipy.PerplexityClient.__init__", "modulename": "perplexipy", "qualname": "PerplexityClient.__init__", "kind": "function", "doc": "<p>Create a new instance of <code>perplexipy.PerplexityClient</code> using the API\n<code>key</code> to connect to the corresponding <code>endpoint</code>.</p>\n\n<h2 id=\"arguments\">Arguments</h2>\n\n<pre><code>key\n</code></pre>\n\n<p>A valid API key string.  If not present, it defaults to <code>perplexipy.PERPLEXITY_API_KEY</code>.</p>\n\n<pre><code>endpoint\n</code></pre>\n\n<p>An string representing a URL to the Perplexity API.</p>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>An instance of <code>perplexipy.PerplexityClient</code> if successful.</p>\n\n<p>Attributes:</p>\n\n<p><code>model</code> - the current model to use in queries, user configurable.</p>\n\n<p>The role is fixed to <code>\"user\"</code> for Perplexity calls, per the API\nrecommendations.</p>\n\n<h2 id=\"raises\">Raises</h2>\n\n<pre><code>PerplexityClientError\n</code></pre>\n\n<p>If the API key is empty, or doesn't match one of the valid API prefixes\nper the documentation.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">key</span><span class=\"p\">:</span> <span class=\"nb\">str</span>, </span><span class=\"param\"><span class=\"n\">endpoint</span><span class=\"p\">:</span> <span class=\"nb\">str</span> <span class=\"o\">=</span> <span class=\"s1\">&#39;https://api.perplexity.ai&#39;</span></span>)</span>"}, {"fullname": "perplexipy.PerplexityClient.query", "modulename": "perplexipy", "qualname": "PerplexityClient.query", "kind": "function", "doc": "<p>Send a single message query to the service, receive a single response.</p>\n\n<h2 id=\"arguments\">Arguments</h2>\n\n<pre><code>query\n</code></pre>\n\n<p>A string with the query in one of the model's supported languages.</p>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>A string with a response from the Perplexity service.</p>\n\n<h2 id=\"raises\">Raises</h2>\n\n<pre><code>Exception\n</code></pre>\n\n<p>An <code>openai.BadRequestError</code> or similar if the query is malformed or has\nsomething other than text data.  The error raised passes through\nwhatever the API raised.</p>\n\n<p>In most cases, the API returns <code>openai.BadRequestError</code>.</p>\n\n<pre><code>PerplexityClientError\n</code></pre>\n\n<p>If the query is <code>None</code> or empty.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"bp\">self</span>, </span><span class=\"param\"><span class=\"n\">query</span><span class=\"p\">:</span> <span class=\"nb\">str</span></span><span class=\"return-annotation\">) -> <span class=\"nb\">str</span>:</span></span>", "funcdef": "def"}, {"fullname": "perplexipy.PerplexityClient.queryBatch", "modulename": "perplexipy", "qualname": "PerplexityClient.queryBatch", "kind": "function", "doc": "<p>Send a single message query to the service, receive a single response.</p>\n\n<h2 id=\"arguments\">Arguments</h2>\n\n<pre><code>query\n</code></pre>\n\n<p>A string with the query in one of the model's supported languages.</p>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>A tuple with a batch of 1 or more response strings.</p>\n\n<h2 id=\"raises\">Raises</h2>\n\n<pre><code>Exception\n</code></pre>\n\n<p>An <code>openai.BadRequestError</code> or similar if the query is malformed or has\nsomething other than text data.  The error raised passes through\nwhatever the API raised.</p>\n\n<p>In most cases, the API returns <code>openai.BadRequestError</code>.</p>\n\n<pre><code>PerplexityClientError\n</code></pre>\n\n<p>If the query is <code>None</code> or empty.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"bp\">self</span>, </span><span class=\"param\"><span class=\"n\">query</span><span class=\"p\">:</span> <span class=\"nb\">str</span></span><span class=\"return-annotation\">) -> <span class=\"nb\">tuple</span>:</span></span>", "funcdef": "def"}, {"fullname": "perplexipy.PerplexityClient.queryStreamable", "modulename": "perplexipy", "qualname": "PerplexityClient.queryStreamable", "kind": "function", "doc": "<p>Send a query and return a long, streamable response.</p>\n\n<h2 id=\"arguments\">Arguments</h2>\n\n<pre><code>query\n</code></pre>\n\n<p>A string with the query in one of the model's supported languages.</p>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>Returns a <code>perplexipy.Responses</code> object for streaming the textual\nresponses from the client.  The response strips all metadata and returns\nonly content strings, for simpler and easier integration.</p>\n\n<h2 id=\"raises\">Raises</h2>\n\n<pre><code>Exception\n</code></pre>\n\n<p>An <code>openai.BadRequestError</code> or similar if the query is malformed or has\nsomething other than text data.  The error raised passes through\nwhatever the API raised.</p>\n\n<p>In most cases, the API returns <code>openai.BadRequestError</code>.</p>\n\n<pre><code>PerplexityClientError\n</code></pre>\n\n<p>If the query is <code>None</code> or empty.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"bp\">self</span>, </span><span class=\"param\"><span class=\"n\">query</span><span class=\"p\">:</span> <span class=\"nb\">str</span></span><span class=\"return-annotation\">) -> <span class=\"n\">perplexipy</span><span class=\"o\">.</span><span class=\"n\">responses</span><span class=\"o\">.</span><span class=\"n\">Responses</span>:</span></span>", "funcdef": "def"}, {"fullname": "perplexipy.PerplexityClient.models", "modulename": "perplexipy", "qualname": "PerplexityClient.models", "kind": "variable", "doc": "<p>Provide a dictionary of the models supported by Perplexity listed in:</p>\n\n<p><a href=\"https://docs.perplexity.ai/docs/model-cards\">https://docs.perplexity.ai/docs/model-cards</a></p>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>A dictionary of supported models as the key, with a <code>perplexypy.ModelInfo</code>\nnamed tuple with the model capabilities description.  The model\ninformation attributes are:</p>\n\n<ul>\n<li><code>parameterCount</code></li>\n<li><code>contextLength</code></li>\n<li><code>modelType</code></li>\n<li><code>availability</code></li>\n</ul>\n"}, {"fullname": "perplexipy.PerplexityClient.model", "modulename": "perplexipy", "qualname": "PerplexityClient.model", "kind": "variable", "doc": "<p>Return the model the client uses for requesting responses from the\nservice provider.  Its default value is:  <code>PERPLEXITY_DEFAULT_MODEL</code>.</p>\n", "annotation": ": str"}, {"fullname": "perplexipy.codex", "modulename": "perplexipy.codex", "kind": "module", "doc": "<p></p>\n"}, {"fullname": "perplexipy.codex.codexCore", "modulename": "perplexipy.codex", "qualname": "codexCore", "kind": "function", "doc": "<p>Send a user query to the model for processing.</p>\n\n<h2 id=\"arguments\">Arguments</h2>\n\n<pre><code>userQuery\n</code></pre>\n\n<p>A string with the user query, most often a programming question.</p>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>The result of the query, or <code>None</code> if the query was empty.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">userQuery</span><span class=\"p\">:</span> <span class=\"nb\">str</span></span><span class=\"return-annotation\">) -> <span class=\"nb\">str</span>:</span></span>", "funcdef": "def"}, {"fullname": "perplexipy.codex.codex", "modulename": "perplexipy.codex", "qualname": "codex", "kind": "variable", "doc": "<p>Process a command line query and display the result to the console.</p>\n\n<h2 id=\"arguments\">Arguments</h2>\n\n<pre><code>tokens\n</code></pre>\n\n<p>A list of tokens that will be assembled as a single string for\nprocessing.</p>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>A string with the response to the query, after displaying it to the\nconsole.</p>\n", "default_value": "&lt;Command codex&gt;"}, {"fullname": "perplexipy.errors", "modulename": "perplexipy.errors", "kind": "module", "doc": "<p></p>\n"}, {"fullname": "perplexipy.errors.PerplexityClientError", "modulename": "perplexipy.errors", "qualname": "PerplexityClientError", "kind": "class", "doc": "<p>Perplexity client generic errors, for cleaner exception handling.</p>\n", "bases": "builtins.Exception"}, {"fullname": "perplexipy.errors.PerplexityClientError.__init__", "modulename": "perplexipy.errors", "qualname": "PerplexityClientError.__init__", "kind": "function", "doc": "<p></p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">errorMessage</span></span>)</span>"}, {"fullname": "perplexipy.responses", "modulename": "perplexipy.responses", "kind": "module", "doc": "<p></p>\n"}, {"fullname": "perplexipy.responses.Responses", "modulename": "perplexipy.responses", "qualname": "Responses", "kind": "class", "doc": "<p>Encapsulates all the streaming responses from a query and enables access to\nit using a purpose-built iterable.  Strips all the OpenAI response metadata\nand returns only the textual response.  It's a streaming iterable,\nopen-ended.</p>\n"}, {"fullname": "perplexipy.responses.Responses.__init__", "modulename": "perplexipy.responses", "qualname": "Responses.__init__", "kind": "function", "doc": "<p></p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">responsesStream</span></span>)</span>"}];
 
     // mirrored in build-search-index.js (part 1)
     // Also split on html tags. this is a cheap heuristic, but good enough.
diff --git a/perplexipy/codex.py b/perplexipy/codex.py
index e1da9ed..5405ed3 100644
--- a/perplexipy/codex.py
+++ b/perplexipy/codex.py
@@ -5,6 +5,7 @@
 from perplexipy import __VERSION__
 
 import os
+import select
 import sys
 
 import click
@@ -43,6 +44,26 @@ def codexCore(userQuery: str) -> str:
     return result
 
 
+def _stdinHasData() -> bool:
+    """
+    Checks if there's data pending to be processed off `stdin`.  It's a
+    convinience function for readability.
+
+    Returns
+    -------
+    `True` if the `stdin` stream is pending processing.
+    """
+    return select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], [])
+
+
+def _assembleInput() -> str:
+    result = ''
+    for line in sys.stdin:
+        result += line
+
+    return result
+
+
 @click.command('codex')
 @click.version_option(__VERSION__, prog_name = 'codex')
 @click.argument('tokens', nargs = -1, type = click.STRING)
@@ -62,8 +83,14 @@ def codex(tokens: list) -> str:
     console.
     """
     result = None
+    userQuery = None
     if len(tokens):
         userQuery = 'Concise, code only answer to this question: '+' '.join(tokens)
+    elif _stdinHasData():
+        userQuery = _assembleInput()
+        userQuery = 'Give me a concise coding example to answer this question: '+userQuery
+
+    if userQuery:
         result = codexCore(userQuery)
         click.echo(result)
     else:
diff --git a/pyproject.toml b/pyproject.toml
index bf75904..0c125d2 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -31,7 +31,7 @@ license = { text='BSD-3' }
 name = 'PerplexiPy'
 readme = 'README.md'
 requires-python = '>=3.9'
-version = '0.2.1'
+version = '0.2.2'
 
 
 [project.scripts]


Test patch:
diff --git a/tests/codex-test.py b/tests/codex-test.py
index 9091d74..5e4aa40 100644
--- a/tests/codex-test.py
+++ b/tests/codex-test.py
@@ -1,6 +1,8 @@
 # See: https://github.com/CIME-Software/perplexipy/blob/master/LICENSE.txt
 
 
+from unittest.mock import patch
+
 from click.testing import CliRunner
 from perplexipy.codex import codexCore
 from perplexipy.codex import codex
@@ -20,10 +22,17 @@ def test_codexCore():
     assert not codexCore(None)
 
 
-def test_codex():
+@patch('sys.stdin')
+def test_codex(stdinMock):
     runner = CliRunner()
     result = runner.invoke(codex, [ TEST_QUERY, ])
     assert str(result) == '<Result okay>'
     result = runner.invoke(codex, [ ])
     assert str(result) != '<Result okay>'
 
+    # stdin input
+    stdinMock.read.return_value = TEST_QUERY
+    result = runner.invoke(codex, [ ])
+
+# test_codex()
+