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

Issue:
BUG: /activate N doesn't set the active model to N



Discussion / hints:

Fix patch:
diff --git a/README.md b/README.md
index 795b345..359050a 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-% perplexipy(3) Version 1.0.1 | Perplexity AI high level API documentation
+% perplexipy(3) Version 1.0.3 | Perplexity AI high level API documentation
 
 Name
 ====
diff --git a/codex-README.md b/codex-README.md
index fde8369..ecbd26d 100644
--- a/codex-README.md
+++ b/codex-README.md
@@ -1,4 +1,4 @@
-% Codex(3) Version 1.0.1 | PerplexiPy command line code explainer
+% Codex(3) Version 1.0.3 | PerplexiPy command line code explainer
 
 Name
 ====
diff --git a/docs/perplexipy.html b/docs/perplexipy.html
index 35cb217..fb2c55b 100644
--- a/docs/perplexipy.html
+++ b/docs/perplexipy.html
@@ -504,7 +504,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;assistant&#39;, &#39;system&#39;, &#39;user&#39;}</span>
+<span class="default_value">{&#39;user&#39;, &#39;assistant&#39;, &#39;system&#39;}</span>
 
         
     </div>
diff --git a/docs/perplexipy/codex.html b/docs/perplexipy/codex.html
index 79e7e92..0d52224 100644
--- a/docs/perplexipy/codex.html
+++ b/docs/perplexipy/codex.html
@@ -187,7 +187,7 @@ <h1 class="modulename">
 </span><span id="L-123"><a href="#L-123"><span class="linenos">123</span></a>        <span class="k">except</span><span class="p">:</span>
 </span><span id="L-124"><a href="#L-124"><span class="linenos">124</span></a>            <span class="n">click</span><span class="o">.</span><span class="n">secho</span><span class="p">(</span><span class="s1">&#39;Invalid model ID = </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">modelID</span><span class="p">,</span> <span class="n">bg</span> <span class="o">=</span> <span class="s1">&#39;red&#39;</span><span class="p">,</span> <span class="n">fg</span> <span class="o">=</span> <span class="s1">&#39;white&#39;</span><span class="p">)</span>
 </span><span id="L-125"><a href="#L-125"><span class="linenos">125</span></a>    <span class="n">click</span><span class="o">.</span><span class="n">secho</span><span class="p">(</span><span class="s1">&#39;Active model: </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">_client</span><span class="o">.</span><span class="n">model</span><span class="p">,</span> <span class="n">fg</span> <span class="o">=</span> <span class="s1">&#39;green&#39;</span><span class="p">,</span> <span class="n">bold</span> <span class="o">=</span> <span class="kc">True</span><span class="p">)</span>
-</span><span id="L-126"><a href="#L-126"><span class="linenos">126</span></a>    <span class="k">return</span> <span class="n">modelID</span>
+</span><span id="L-126"><a href="#L-126"><span class="linenos">126</span></a>    <span class="k">return</span> <span class="n">_client</span><span class="o">.</span><span class="n">model</span>
 </span><span id="L-127"><a href="#L-127"><span class="linenos">127</span></a>
 </span><span id="L-128"><a href="#L-128"><span class="linenos">128</span></a>
 </span><span id="L-129"><a href="#L-129"><span class="linenos">129</span></a><span class="k">def</span> <span class="nf">_REPLHello</span><span class="p">():</span>
@@ -214,185 +214,196 @@ <h1 class="modulename">
 </span><span id="L-150"><a href="#L-150"><span class="linenos">150</span></a><span class="s2">&quot;&quot;&quot;</span><span class="p">)</span>
 </span><span id="L-151"><a href="#L-151"><span class="linenos">151</span></a>
 </span><span id="L-152"><a href="#L-152"><span class="linenos">152</span></a>
-</span><span id="L-153"><a href="#L-153"><span class="linenos">153</span></a><span class="k">def</span> <span class="nf">_displayModels</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
-</span><span id="L-154"><a href="#L-154"><span class="linenos">154</span></a>    <span class="n">_activeModel</span><span class="p">()</span>
-</span><span id="L-155"><a href="#L-155"><span class="linenos">155</span></a>    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Available models:</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
-</span><span id="L-156"><a href="#L-156"><span class="linenos">156</span></a>    <span class="n">n</span> <span class="o">=</span> <span class="mi">1</span>
-</span><span id="L-157"><a href="#L-157"><span class="linenos">157</span></a>    <span class="k">for</span> <span class="n">model</span> <span class="ow">in</span> <span class="n">_client</span><span class="o">.</span><span class="n">models</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
-</span><span id="L-158"><a href="#L-158"><span class="linenos">158</span></a>        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%2d</span><span class="s1"> - </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">model</span><span class="p">))</span>
-</span><span id="L-159"><a href="#L-159"><span class="linenos">159</span></a>        <span class="n">n</span> <span class="o">+=</span> <span class="mi">1</span>
-</span><span id="L-160"><a href="#L-160"><span class="linenos">160</span></a>    <span class="nb">print</span><span class="p">()</span>
-</span><span id="L-161"><a href="#L-161"><span class="linenos">161</span></a>
-</span><span id="L-162"><a href="#L-162"><span class="linenos">162</span></a>
-</span><span id="L-163"><a href="#L-163"><span class="linenos">163</span></a><span class="k">def</span> <span class="nf">_editingMode</span><span class="p">(</span><span class="n">session</span><span class="p">:</span> <span class="n">PromptSession</span><span class="p">,</span> <span class="n">mode</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span>
-</span><span id="L-164"><a href="#L-164"><span class="linenos">164</span></a>    <span class="k">if</span> <span class="n">mode</span><span class="p">:</span>
-</span><span id="L-165"><a href="#L-165"><span class="linenos">165</span></a>        <span class="n">mode</span> <span class="o">=</span> <span class="n">mode</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
-</span><span id="L-166"><a href="#L-166"><span class="linenos">166</span></a>        <span class="n">newEditingMode</span> <span class="o">=</span> <span class="n">EditingMode</span><span class="o">.</span><span class="n">EMACS</span> <span class="k">if</span> <span class="n">mode</span> <span class="o">==</span> <span class="s1">&#39;emacs&#39;</span> <span class="k">else</span> <span class="n">EditingMode</span><span class="o">.</span><span class="n">VI</span>
-</span><span id="L-167"><a href="#L-167"><span class="linenos">167</span></a>        <span class="n">session</span> <span class="o">=</span> <span class="n">PromptSession</span><span class="p">(</span><span class="n">editing_mode</span> <span class="o">=</span> <span class="n">newEditingMode</span><span class="p">)</span>
+</span><span id="L-153"><a href="#L-153"><span class="linenos">153</span></a><span class="k">def</span> <span class="nf">_displayModels</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="nb">list</span><span class="p">:</span>
+</span><span id="L-154"><a href="#L-154"><span class="linenos">154</span></a><span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
+</span><span id="L-155"><a href="#L-155"><span class="linenos">155</span></a><span class="sd">    Display the list of models supported by the API.</span>
+</span><span id="L-156"><a href="#L-156"><span class="linenos">156</span></a>
+</span><span id="L-157"><a href="#L-157"><span class="linenos">157</span></a><span class="sd">    Returns</span>
+</span><span id="L-158"><a href="#L-158"><span class="linenos">158</span></a><span class="sd">    =======</span>
+</span><span id="L-159"><a href="#L-159"><span class="linenos">159</span></a><span class="sd">    A list of strings, each corresponding to a model name.</span>
+</span><span id="L-160"><a href="#L-160"><span class="linenos">160</span></a><span class="sd">    &quot;&quot;&quot;</span>
+</span><span id="L-161"><a href="#L-161"><span class="linenos">161</span></a>    <span class="n">_activeModel</span><span class="p">()</span>
+</span><span id="L-162"><a href="#L-162"><span class="linenos">162</span></a>    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Available models:</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
+</span><span id="L-163"><a href="#L-163"><span class="linenos">163</span></a>    <span class="n">n</span> <span class="o">=</span> <span class="mi">1</span>
+</span><span id="L-164"><a href="#L-164"><span class="linenos">164</span></a>    <span class="k">for</span> <span class="n">model</span> <span class="ow">in</span> <span class="n">_client</span><span class="o">.</span><span class="n">models</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
+</span><span id="L-165"><a href="#L-165"><span class="linenos">165</span></a>        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%2d</span><span class="s1"> - </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">model</span><span class="p">))</span>
+</span><span id="L-166"><a href="#L-166"><span class="linenos">166</span></a>        <span class="n">n</span> <span class="o">+=</span> <span class="mi">1</span>
+</span><span id="L-167"><a href="#L-167"><span class="linenos">167</span></a>    <span class="nb">print</span><span class="p">()</span>
 </span><span id="L-168"><a href="#L-168"><span class="linenos">168</span></a>
-</span><span id="L-169"><a href="#L-169"><span class="linenos">169</span></a>    <span class="n">editingMode</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">session</span><span class="o">.</span><span class="n">editing_mode</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;EditingMode.&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
-</span><span id="L-170"><a href="#L-170"><span class="linenos">170</span></a>    <span class="n">click</span><span class="o">.</span><span class="n">secho</span><span class="p">(</span><span class="s1">&#39;Editing mode = </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">editingMode</span><span class="p">,</span> <span class="n">fg</span> <span class="o">=</span> <span class="s1">&#39;bright_blue&#39;</span><span class="p">)</span>
+</span><span id="L-169"><a href="#L-169"><span class="linenos">169</span></a>    <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="n">_client</span><span class="o">.</span><span class="n">models</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
+</span><span id="L-170"><a href="#L-170"><span class="linenos">170</span></a>
 </span><span id="L-171"><a href="#L-171"><span class="linenos">171</span></a>
-</span><span id="L-172"><a href="#L-172"><span class="linenos">172</span></a>    <span class="k">return</span> <span class="n">session</span>
-</span><span id="L-173"><a href="#L-173"><span class="linenos">173</span></a>
-</span><span id="L-174"><a href="#L-174"><span class="linenos">174</span></a>
-</span><span id="L-175"><a href="#L-175"><span class="linenos">175</span></a><span class="k">def</span> <span class="nf">_queryStyle</span><span class="p">(</span><span class="n">newStyle</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span>
-</span><span id="L-176"><a href="#L-176"><span class="linenos">176</span></a>    <span class="k">global</span> <span class="n">_queryCodeStyle</span>
+</span><span id="L-172"><a href="#L-172"><span class="linenos">172</span></a><span class="k">def</span> <span class="nf">_editingMode</span><span class="p">(</span><span class="n">session</span><span class="p">:</span> <span class="n">PromptSession</span><span class="p">,</span> <span class="n">mode</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span>
+</span><span id="L-173"><a href="#L-173"><span class="linenos">173</span></a>    <span class="k">if</span> <span class="n">mode</span><span class="p">:</span>
+</span><span id="L-174"><a href="#L-174"><span class="linenos">174</span></a>        <span class="n">mode</span> <span class="o">=</span> <span class="n">mode</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
+</span><span id="L-175"><a href="#L-175"><span class="linenos">175</span></a>        <span class="n">newEditingMode</span> <span class="o">=</span> <span class="n">EditingMode</span><span class="o">.</span><span class="n">EMACS</span> <span class="k">if</span> <span class="n">mode</span> <span class="o">==</span> <span class="s1">&#39;emacs&#39;</span> <span class="k">else</span> <span class="n">EditingMode</span><span class="o">.</span><span class="n">VI</span>
+</span><span id="L-176"><a href="#L-176"><span class="linenos">176</span></a>        <span class="n">session</span> <span class="o">=</span> <span class="n">PromptSession</span><span class="p">(</span><span class="n">editing_mode</span> <span class="o">=</span> <span class="n">newEditingMode</span><span class="p">)</span>
 </span><span id="L-177"><a href="#L-177"><span class="linenos">177</span></a>
-</span><span id="L-178"><a href="#L-178"><span class="linenos">178</span></a>    <span class="k">if</span> <span class="n">newStyle</span><span class="p">:</span>
-</span><span id="L-179"><a href="#L-179"><span class="linenos">179</span></a>        <span class="n">_queryCodeStyle</span> <span class="o">=</span> <span class="n">newStyle</span> <span class="o">!=</span> <span class="s1">&#39;human&#39;</span>
-</span><span id="L-180"><a href="#L-180"><span class="linenos">180</span></a>    <span class="n">click</span><span class="o">.</span><span class="n">secho</span><span class="p">(</span><span class="s1">&#39;Coding query style = </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">_queryCodeStyle</span><span class="p">,</span> <span class="n">fg</span> <span class="o">=</span> <span class="s1">&#39;bright_blue&#39;</span><span class="p">)</span>
-</span><span id="L-181"><a href="#L-181"><span class="linenos">181</span></a>    <span class="k">return</span> <span class="n">_queryCodeStyle</span>
+</span><span id="L-178"><a href="#L-178"><span class="linenos">178</span></a>    <span class="n">editingMode</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">session</span><span class="o">.</span><span class="n">editing_mode</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;EditingMode.&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
+</span><span id="L-179"><a href="#L-179"><span class="linenos">179</span></a>    <span class="n">click</span><span class="o">.</span><span class="n">secho</span><span class="p">(</span><span class="s1">&#39;Editing mode = </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">editingMode</span><span class="p">,</span> <span class="n">fg</span> <span class="o">=</span> <span class="s1">&#39;bright_blue&#39;</span><span class="p">)</span>
+</span><span id="L-180"><a href="#L-180"><span class="linenos">180</span></a>
+</span><span id="L-181"><a href="#L-181"><span class="linenos">181</span></a>    <span class="k">return</span> <span class="n">session</span>
 </span><span id="L-182"><a href="#L-182"><span class="linenos">182</span></a>
 </span><span id="L-183"><a href="#L-183"><span class="linenos">183</span></a>
-</span><span id="L-184"><a href="#L-184"><span class="linenos">184</span></a><span class="k">def</span> <span class="nf">_makeQuery</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-185"><a href="#L-185"><span class="linenos">185</span></a>    <span class="k">if</span> <span class="n">_queryCodeStyle</span><span class="p">:</span>
-</span><span id="L-186"><a href="#L-186"><span class="linenos">186</span></a>        <span class="n">userQuery</span> <span class="o">=</span> <span class="n">QUERY_DETAILED</span><span class="o">+</span><span class="n">userQuery</span>
-</span><span id="L-187"><a href="#L-187"><span class="linenos">187</span></a>
-</span><span id="L-188"><a href="#L-188"><span class="linenos">188</span></a>    <span class="k">return</span> <span class="n">codexCore</span><span class="p">(</span><span class="n">userQuery</span><span class="p">)</span>
-</span><span id="L-189"><a href="#L-189"><span class="linenos">189</span></a>
-</span><span id="L-190"><a href="#L-190"><span class="linenos">190</span></a>
-</span><span id="L-191"><a href="#L-191"><span class="linenos">191</span></a><span class="k">def</span> <span class="nf">_displayVersion</span><span class="p">():</span>
-</span><span id="L-192"><a href="#L-192"><span class="linenos">192</span></a>    <span class="n">click</span><span class="o">.</span><span class="n">secho</span><span class="p">(</span><span class="s1">&#39;PerplexiPy Codex version </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">__VERSION__</span><span class="p">,</span> <span class="n">fg</span> <span class="o">=</span> <span class="s1">&#39;bright_green&#39;</span><span class="p">)</span>
-</span><span id="L-193"><a href="#L-193"><span class="linenos">193</span></a>
-</span><span id="L-194"><a href="#L-194"><span class="linenos">194</span></a>
-</span><span id="L-195"><a href="#L-195"><span class="linenos">195</span></a><span class="k">def</span> <span class="nf">_saveConfigTo</span><span class="p">(</span><span class="n">config</span><span class="p">:</span> <span class="nb">dict</span><span class="p">,</span> <span class="n">fileName</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="n">CONFIG_FILE_NAME</span><span class="p">,</span> <span class="n">pathName</span> <span class="o">=</span> <span class="n">CONFIG_PATH</span><span class="p">):</span>
-</span><span id="L-196"><a href="#L-196"><span class="linenos">196</span></a>    <span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">pathName</span><span class="p">):</span>
-</span><span id="L-197"><a href="#L-197"><span class="linenos">197</span></a>        <span class="n">os</span><span class="o">.</span><span class="n">makedirs</span><span class="p">(</span><span class="n">pathName</span><span class="p">)</span>
-</span><span id="L-198"><a href="#L-198"><span class="linenos">198</span></a>    <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">fileName</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">outputFile</span><span class="p">:</span>
-</span><span id="L-199"><a href="#L-199"><span class="linenos">199</span></a>        <span class="n">yaml</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">config</span><span class="p">,</span> <span class="n">outputFile</span><span class="p">)</span>
-</span><span id="L-200"><a href="#L-200"><span class="linenos">200</span></a>
-</span><span id="L-201"><a href="#L-201"><span class="linenos">201</span></a>
-</span><span id="L-202"><a href="#L-202"><span class="linenos">202</span></a><span class="k">def</span> <span class="nf">_loadConfigFrom</span><span class="p">(</span><span class="n">fileName</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="n">CONFIG_FILE_NAME</span><span class="p">,</span> <span class="n">pathName</span> <span class="o">=</span> <span class="n">CONFIG_PATH</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
-</span><span id="L-203"><a href="#L-203"><span class="linenos">203</span></a>    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">fileName</span><span class="p">):</span>
-</span><span id="L-204"><a href="#L-204"><span class="linenos">204</span></a>        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">fileName</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">inputFile</span><span class="p">:</span>
-</span><span id="L-205"><a href="#L-205"><span class="linenos">205</span></a>            <span class="n">config</span> <span class="o">=</span> <span class="n">yaml</span><span class="o">.</span><span class="n">safe_load</span><span class="p">(</span><span class="n">inputFile</span><span class="p">)</span>
-</span><span id="L-206"><a href="#L-206"><span class="linenos">206</span></a>    <span class="k">else</span><span class="p">:</span>
-</span><span id="L-207"><a href="#L-207"><span class="linenos">207</span></a>        <span class="n">config</span> <span class="o">=</span> <span class="p">{</span>
-</span><span id="L-208"><a href="#L-208"><span class="linenos">208</span></a>            <span class="s1">&#39;activeModel&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span>
-</span><span id="L-209"><a href="#L-209"><span class="linenos">209</span></a>            <span class="s1">&#39;editingMode&#39;</span><span class="p">:</span> <span class="s1">&#39;vi&#39;</span><span class="p">,</span>
-</span><span id="L-210"><a href="#L-210"><span class="linenos">210</span></a>            <span class="s1">&#39;queryCodeStyle&#39;</span><span class="p">:</span> <span class="n">_queryCodeStyle</span><span class="p">,</span>
-</span><span id="L-211"><a href="#L-211"><span class="linenos">211</span></a>        <span class="p">}</span>
-</span><span id="L-212"><a href="#L-212"><span class="linenos">212</span></a>        <span class="n">_saveConfigTo</span><span class="p">(</span><span class="n">config</span><span class="p">,</span> <span class="n">fileName</span><span class="p">,</span> <span class="n">pathName</span><span class="p">)</span>
-</span><span id="L-213"><a href="#L-213"><span class="linenos">213</span></a>    <span class="k">return</span> <span class="n">config</span>
-</span><span id="L-214"><a href="#L-214"><span class="linenos">214</span></a>
-</span><span id="L-215"><a href="#L-215"><span class="linenos">215</span></a>
-</span><span id="L-216"><a href="#L-216"><span class="linenos">216</span></a><span class="k">def</span> <span class="nf">_displayConfigInfo</span><span class="p">():</span>
-</span><span id="L-217"><a href="#L-217"><span class="linenos">217</span></a>    <span class="k">pass</span>
-</span><span id="L-218"><a href="#L-218"><span class="linenos">218</span></a>    <span class="n">click</span><span class="o">.</span><span class="n">secho</span><span class="p">(</span><span class="s1">&#39;Config file: </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">CONFIG_FILE_NAME</span><span class="p">)</span>
-</span><span id="L-219"><a href="#L-219"><span class="linenos">219</span></a>    <span class="n">click</span><span class="o">.</span><span class="n">secho</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">_loadConfigFrom</span><span class="p">())</span><span class="o">+</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
-</span><span id="L-220"><a href="#L-220"><span class="linenos">220</span></a>
-</span><span id="L-221"><a href="#L-221"><span class="linenos">221</span></a>
-</span><span id="L-222"><a href="#L-222"><span class="linenos">222</span></a><span class="c1"># TODO: Refactor REPL - https://github.com/CIME-Software/perplexipy/issues/46</span>
-</span><span id="L-223"><a href="#L-223"><span class="linenos">223</span></a><span class="k">def</span> <span class="nf">_runREPL</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
-</span><span id="L-224"><a href="#L-224"><span class="linenos">224</span></a><span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
-</span><span id="L-225"><a href="#L-225"><span class="linenos">225</span></a><span class="sd">    Run a REPL loop for sending queries to the AI provider.</span>
-</span><span id="L-226"><a href="#L-226"><span class="linenos">226</span></a>
-</span><span id="L-227"><a href="#L-227"><span class="linenos">227</span></a><span class="sd">    Returns</span>
-</span><span id="L-228"><a href="#L-228"><span class="linenos">228</span></a><span class="sd">    -------</span>
-</span><span id="L-229"><a href="#L-229"><span class="linenos">229</span></a><span class="sd">    The word &quot;REPL&quot; to signal to the `codex` command that it received valid</span>
-</span><span id="L-230"><a href="#L-230"><span class="linenos">230</span></a><span class="sd">    input.</span>
-</span><span id="L-231"><a href="#L-231"><span class="linenos">231</span></a><span class="sd">    &quot;&quot;&quot;</span>
-</span><span id="L-232"><a href="#L-232"><span class="linenos">232</span></a>    <span class="n">_REPLHello</span><span class="p">()</span>
-</span><span id="L-233"><a href="#L-233"><span class="linenos">233</span></a>    <span class="n">config</span> <span class="o">=</span> <span class="n">_loadConfigFrom</span><span class="p">()</span>
-</span><span id="L-234"><a href="#L-234"><span class="linenos">234</span></a>    <span class="n">session</span> <span class="o">=</span> <span class="n">PromptSession</span><span class="p">()</span>
-</span><span id="L-235"><a href="#L-235"><span class="linenos">235</span></a>    <span class="n">_activeModel</span><span class="p">(</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;activeModel&#39;</span><span class="p">])</span>
-</span><span id="L-236"><a href="#L-236"><span class="linenos">236</span></a>    <span class="n">session</span> <span class="o">=</span> <span class="n">_editingMode</span><span class="p">(</span><span class="n">session</span><span class="p">,</span> <span class="n">config</span><span class="p">[</span><span class="s1">&#39;editingMode&#39;</span><span class="p">])</span>
-</span><span id="L-237"><a href="#L-237"><span class="linenos">237</span></a>    <span class="n">_queryStyle</span><span class="p">(</span><span class="s1">&#39;code&#39;</span> <span class="k">if</span> <span class="n">config</span><span class="p">[</span><span class="s1">&#39;queryCodeStyle&#39;</span><span class="p">]</span> <span class="k">else</span> <span class="s1">&#39;human&#39;</span><span class="p">)</span>
-</span><span id="L-238"><a href="#L-238"><span class="linenos">238</span></a>    <span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
-</span><span id="L-239"><a href="#L-239"><span class="linenos">239</span></a>        <span class="n">userQuery</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="n">prompt</span><span class="p">(</span><span class="s1">&#39;Ask anything (/exit to end): &#39;</span><span class="p">)</span>
-</span><span id="L-240"><a href="#L-240"><span class="linenos">240</span></a>        <span class="k">if</span> <span class="n">userQuery</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">,</span> <span class="s1">&#39;?&#39;</span><span class="p">,</span> <span class="s1">&#39;:&#39;</span><span class="p">):</span>
-</span><span id="L-241"><a href="#L-241"><span class="linenos">241</span></a>            <span class="n">parts</span> <span class="o">=</span> <span class="n">userQuery</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">)</span>
-</span><span id="L-242"><a href="#L-242"><span class="linenos">242</span></a>            <span class="n">command</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
-</span><span id="L-243"><a href="#L-243"><span class="linenos">243</span></a>            <span class="k">if</span> <span class="n">command</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">&#39;/exit&#39;</span><span class="p">,</span> <span class="s1">&#39;/quit&#39;</span><span class="p">,</span> <span class="s1">&#39;:q&#39;</span><span class="p">,</span> <span class="s1">&#39;/q&#39;</span><span class="p">):</span>
-</span><span id="L-244"><a href="#L-244"><span class="linenos">244</span></a>                <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
-</span><span id="L-245"><a href="#L-245"><span class="linenos">245</span></a>            <span class="k">elif</span> <span class="n">command</span> <span class="o">==</span> <span class="s1">&#39;/active&#39;</span><span class="p">:</span>
-</span><span id="L-246"><a href="#L-246"><span class="linenos">246</span></a>                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">parts</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
-</span><span id="L-247"><a href="#L-247"><span class="linenos">247</span></a>                    <span class="k">try</span><span class="p">:</span>
-</span><span id="L-248"><a href="#L-248"><span class="linenos">248</span></a>                        <span class="n">model</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">parts</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
-</span><span id="L-249"><a href="#L-249"><span class="linenos">249</span></a>                        <span class="n">config</span><span class="p">[</span><span class="s1">&#39;activeModel&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">_activeModel</span><span class="p">(</span><span class="n">model</span><span class="p">)</span>
-</span><span id="L-250"><a href="#L-250"><span class="linenos">250</span></a>                        <span class="n">_saveConfigTo</span><span class="p">(</span><span class="n">config</span><span class="p">)</span>
-</span><span id="L-251"><a href="#L-251"><span class="linenos">251</span></a>                    <span class="k">except</span><span class="p">:</span>
-</span><span id="L-252"><a href="#L-252"><span class="linenos">252</span></a>                        <span class="n">_activeModel</span><span class="p">()</span>
-</span><span id="L-253"><a href="#L-253"><span class="linenos">253</span></a>                <span class="k">else</span><span class="p">:</span>
-</span><span id="L-254"><a href="#L-254"><span class="linenos">254</span></a>                    <span class="n">_activeModel</span><span class="p">()</span>
-</span><span id="L-255"><a href="#L-255"><span class="linenos">255</span></a>            <span class="k">elif</span> <span class="n">command</span> <span class="o">==</span> <span class="s1">&#39;/cinfo&#39;</span><span class="p">:</span>
-</span><span id="L-256"><a href="#L-256"><span class="linenos">256</span></a>                <span class="n">_displayConfigInfo</span><span class="p">()</span>
-</span><span id="L-257"><a href="#L-257"><span class="linenos">257</span></a>            <span class="k">elif</span> <span class="n">command</span> <span class="o">==</span> <span class="s1">&#39;/clear&#39;</span><span class="p">:</span>
-</span><span id="L-258"><a href="#L-258"><span class="linenos">258</span></a>                <span class="n">click</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
-</span><span id="L-259"><a href="#L-259"><span class="linenos">259</span></a>                <span class="n">_editingMode</span><span class="p">(</span><span class="n">session</span><span class="p">)</span>
-</span><span id="L-260"><a href="#L-260"><span class="linenos">260</span></a>            <span class="k">elif</span> <span class="n">command</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">&#39;/help&#39;</span><span class="p">,</span> <span class="s1">&#39;?&#39;</span><span class="p">):</span>
-</span><span id="L-261"><a href="#L-261"><span class="linenos">261</span></a>                <span class="n">_helpREPL</span><span class="p">()</span>
-</span><span id="L-262"><a href="#L-262"><span class="linenos">262</span></a>            <span class="k">elif</span> <span class="n">command</span> <span class="o">==</span> <span class="s1">&#39;/mode&#39;</span><span class="p">:</span>
-</span><span id="L-263"><a href="#L-263"><span class="linenos">263</span></a>                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">parts</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
-</span><span id="L-264"><a href="#L-264"><span class="linenos">264</span></a>                    <span class="k">try</span><span class="p">:</span>
-</span><span id="L-265"><a href="#L-265"><span class="linenos">265</span></a>                        <span class="n">session</span> <span class="o">=</span> <span class="n">_editingMode</span><span class="p">(</span><span class="n">session</span><span class="p">,</span> <span class="n">parts</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
-</span><span id="L-266"><a href="#L-266"><span class="linenos">266</span></a>                        <span class="n">config</span><span class="p">[</span><span class="s1">&#39;editingMode&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
-</span><span id="L-267"><a href="#L-267"><span class="linenos">267</span></a>                        <span class="n">_saveConfigTo</span><span class="p">(</span><span class="n">config</span><span class="p">)</span>
-</span><span id="L-268"><a href="#L-268"><span class="linenos">268</span></a>                    <span class="k">except</span><span class="p">:</span>
-</span><span id="L-269"><a href="#L-269"><span class="linenos">269</span></a>                        <span class="k">pass</span>
-</span><span id="L-270"><a href="#L-270"><span class="linenos">270</span></a>                <span class="k">else</span><span class="p">:</span>
-</span><span id="L-271"><a href="#L-271"><span class="linenos">271</span></a>                    <span class="n">_editingMode</span><span class="p">(</span><span class="n">session</span><span class="p">)</span>
-</span><span id="L-272"><a href="#L-272"><span class="linenos">272</span></a>            <span class="k">elif</span> <span class="n">command</span> <span class="o">==</span> <span class="s1">&#39;/models&#39;</span><span class="p">:</span>
-</span><span id="L-273"><a href="#L-273"><span class="linenos">273</span></a>                <span class="n">_displayModels</span><span class="p">()</span>
-</span><span id="L-274"><a href="#L-274"><span class="linenos">274</span></a>            <span class="k">elif</span> <span class="n">command</span> <span class="o">==</span> <span class="s1">&#39;/style&#39;</span><span class="p">:</span>
-</span><span id="L-275"><a href="#L-275"><span class="linenos">275</span></a>                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">parts</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
-</span><span id="L-276"><a href="#L-276"><span class="linenos">276</span></a>                    <span class="n">queryStyleType</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
-</span><span id="L-277"><a href="#L-277"><span class="linenos">277</span></a>                    <span class="n">config</span><span class="p">[</span><span class="s1">&#39;queryCodeStyle&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">_queryStyle</span><span class="p">(</span><span class="n">queryStyleType</span><span class="p">)</span>
-</span><span id="L-278"><a href="#L-278"><span class="linenos">278</span></a>                    <span class="n">_saveConfigTo</span><span class="p">(</span><span class="n">config</span><span class="p">)</span>
-</span><span id="L-279"><a href="#L-279"><span class="linenos">279</span></a>                <span class="k">else</span><span class="p">:</span>
-</span><span id="L-280"><a href="#L-280"><span class="linenos">280</span></a>                    <span class="n">_queryStyle</span><span class="p">()</span>
-</span><span id="L-281"><a href="#L-281"><span class="linenos">281</span></a>            <span class="k">elif</span> <span class="n">command</span> <span class="o">==</span> <span class="s1">&#39;/version&#39;</span><span class="p">:</span>
-</span><span id="L-282"><a href="#L-282"><span class="linenos">282</span></a>                <span class="n">_displayVersion</span><span class="p">()</span>
-</span><span id="L-283"><a href="#L-283"><span class="linenos">283</span></a>            <span class="k">continue</span>
-</span><span id="L-284"><a href="#L-284"><span class="linenos">284</span></a>        <span class="n">result</span> <span class="o">=</span> <span class="n">_makeQuery</span><span class="p">(</span><span class="n">userQuery</span><span class="p">)</span>
-</span><span id="L-285"><a href="#L-285"><span class="linenos">285</span></a>        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">result</span><span class="p">)</span>
-</span><span id="L-286"><a href="#L-286"><span class="linenos">286</span></a>        <span class="n">click</span><span class="o">.</span><span class="n">secho</span><span class="p">(</span><span class="s1">&#39;--------------------------------------------------&#39;</span><span class="p">,</span> <span class="n">fg</span> <span class="o">=</span> <span class="s1">&#39;green&#39;</span><span class="p">)</span>
-</span><span id="L-287"><a href="#L-287"><span class="linenos">287</span></a>        <span class="nb">print</span><span class="p">()</span>
-</span><span id="L-288"><a href="#L-288"><span class="linenos">288</span></a>
-</span><span id="L-289"><a href="#L-289"><span class="linenos">289</span></a>    <span class="k">return</span> <span class="s1">&#39;REPL&#39;</span>
-</span><span id="L-290"><a href="#L-290"><span class="linenos">290</span></a>
-</span><span id="L-291"><a href="#L-291"><span class="linenos">291</span></a>
-</span><span id="L-292"><a href="#L-292"><span class="linenos">292</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-293"><a href="#L-293"><span class="linenos">293</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-294"><a href="#L-294"><span class="linenos">294</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-295"><a href="#L-295"><span class="linenos">295</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-296"><a href="#L-296"><span class="linenos">296</span></a><span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
-</span><span id="L-297"><a href="#L-297"><span class="linenos">297</span></a><span class="sd">    Process a command line query and display the result to the console.</span>
-</span><span id="L-298"><a href="#L-298"><span class="linenos">298</span></a>
-</span><span id="L-299"><a href="#L-299"><span class="linenos">299</span></a><span class="sd">    Arguments</span>
-</span><span id="L-300"><a href="#L-300"><span class="linenos">300</span></a><span class="sd">    ---------</span>
-</span><span id="L-301"><a href="#L-301"><span class="linenos">301</span></a><span class="sd">        tokens</span>
-</span><span id="L-302"><a href="#L-302"><span class="linenos">302</span></a><span class="sd">    A list of tokens that will be assembled as a single string for</span>
-</span><span id="L-303"><a href="#L-303"><span class="linenos">303</span></a><span class="sd">    processing.</span>
-</span><span id="L-304"><a href="#L-304"><span class="linenos">304</span></a>
-</span><span id="L-305"><a href="#L-305"><span class="linenos">305</span></a><span class="sd">    Returns</span>
-</span><span id="L-306"><a href="#L-306"><span class="linenos">306</span></a><span class="sd">    -------</span>
-</span><span id="L-307"><a href="#L-307"><span class="linenos">307</span></a><span class="sd">    A string with the response to the query, after displaying it to the</span>
-</span><span id="L-308"><a href="#L-308"><span class="linenos">308</span></a><span class="sd">    console.</span>
-</span><span id="L-309"><a href="#L-309"><span class="linenos">309</span></a><span class="sd">    &quot;&quot;&quot;</span>
-</span><span id="L-310"><a href="#L-310"><span class="linenos">310</span></a>    <span class="n">result</span> <span class="o">=</span> <span class="kc">None</span>
-</span><span id="L-311"><a href="#L-311"><span class="linenos">311</span></a>    <span class="n">userQuery</span> <span class="o">=</span> <span class="kc">None</span>
-</span><span id="L-312"><a href="#L-312"><span class="linenos">312</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-313"><a href="#L-313"><span class="linenos">313</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 class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">tokens</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="n">ARG_REPL</span><span class="p">:</span>
-</span><span id="L-314"><a href="#L-314"><span class="linenos">314</span></a>            <span class="n">userQuery</span> <span class="o">=</span> <span class="n">_runREPL</span><span class="p">()</span>
-</span><span id="L-315"><a href="#L-315"><span class="linenos">315</span></a>        <span class="k">else</span><span class="p">:</span>
-</span><span id="L-316"><a href="#L-316"><span class="linenos">316</span></a>            <span class="n">userQuery</span> <span class="o">=</span> <span class="n">QUERY_CRISP</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-317"><a href="#L-317"><span class="linenos">317</span></a>    <span class="k">elif</span> <span class="n">_stdinHasData</span><span class="p">():</span>
-</span><span id="L-318"><a href="#L-318"><span class="linenos">318</span></a>        <span class="n">userQuery</span> <span class="o">=</span> <span class="n">_assembleInput</span><span class="p">()</span>
-</span><span id="L-319"><a href="#L-319"><span class="linenos">319</span></a>        <span class="n">userQuery</span> <span class="o">=</span> <span class="n">QUERY_DETAILED</span><span class="o">+</span><span class="n">userQuery</span>
-</span><span id="L-320"><a href="#L-320"><span class="linenos">320</span></a>
-</span><span id="L-321"><a href="#L-321"><span class="linenos">321</span></a>    <span class="k">if</span> <span class="n">userQuery</span><span class="p">:</span>
-</span><span id="L-322"><a href="#L-322"><span class="linenos">322</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-323"><a href="#L-323"><span class="linenos">323</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-324"><a href="#L-324"><span class="linenos">324</span></a>    <span class="k">else</span><span class="p">:</span>
-</span><span id="L-325"><a href="#L-325"><span class="linenos">325</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-326"><a href="#L-326"><span class="linenos">326</span></a>
-</span><span id="L-327"><a href="#L-327"><span class="linenos">327</span></a>    <span class="k">return</span> <span class="n">result</span>
-</span><span id="L-328"><a href="#L-328"><span class="linenos">328</span></a>
-</span><span id="L-329"><a href="#L-329"><span class="linenos">329</span></a>
-</span><span id="L-330"><a href="#L-330"><span class="linenos">330</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-331"><a href="#L-331"><span class="linenos">331</span></a>    <span class="n">codex</span><span class="p">()</span>
+</span><span id="L-184"><a href="#L-184"><span class="linenos">184</span></a><span class="k">def</span> <span class="nf">_queryStyle</span><span class="p">(</span><span class="n">newStyle</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span>
+</span><span id="L-185"><a href="#L-185"><span class="linenos">185</span></a>    <span class="k">global</span> <span class="n">_queryCodeStyle</span>
+</span><span id="L-186"><a href="#L-186"><span class="linenos">186</span></a>
+</span><span id="L-187"><a href="#L-187"><span class="linenos">187</span></a>    <span class="k">if</span> <span class="n">newStyle</span><span class="p">:</span>
+</span><span id="L-188"><a href="#L-188"><span class="linenos">188</span></a>        <span class="n">_queryCodeStyle</span> <span class="o">=</span> <span class="n">newStyle</span> <span class="o">!=</span> <span class="s1">&#39;human&#39;</span>
+</span><span id="L-189"><a href="#L-189"><span class="linenos">189</span></a>    <span class="n">click</span><span class="o">.</span><span class="n">secho</span><span class="p">(</span><span class="s1">&#39;Coding query style = </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">_queryCodeStyle</span><span class="p">,</span> <span class="n">fg</span> <span class="o">=</span> <span class="s1">&#39;bright_blue&#39;</span><span class="p">)</span>
+</span><span id="L-190"><a href="#L-190"><span class="linenos">190</span></a>    <span class="k">return</span> <span class="n">_queryCodeStyle</span>
+</span><span id="L-191"><a href="#L-191"><span class="linenos">191</span></a>
+</span><span id="L-192"><a href="#L-192"><span class="linenos">192</span></a>
+</span><span id="L-193"><a href="#L-193"><span class="linenos">193</span></a><span class="k">def</span> <span class="nf">_makeQuery</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-194"><a href="#L-194"><span class="linenos">194</span></a>    <span class="k">if</span> <span class="n">_queryCodeStyle</span><span class="p">:</span>
+</span><span id="L-195"><a href="#L-195"><span class="linenos">195</span></a>        <span class="n">userQuery</span> <span class="o">=</span> <span class="n">QUERY_DETAILED</span><span class="o">+</span><span class="n">userQuery</span>
+</span><span id="L-196"><a href="#L-196"><span class="linenos">196</span></a>
+</span><span id="L-197"><a href="#L-197"><span class="linenos">197</span></a>    <span class="k">return</span> <span class="n">codexCore</span><span class="p">(</span><span class="n">userQuery</span><span class="p">)</span>
+</span><span id="L-198"><a href="#L-198"><span class="linenos">198</span></a>
+</span><span id="L-199"><a href="#L-199"><span class="linenos">199</span></a>
+</span><span id="L-200"><a href="#L-200"><span class="linenos">200</span></a><span class="k">def</span> <span class="nf">_displayVersion</span><span class="p">():</span>
+</span><span id="L-201"><a href="#L-201"><span class="linenos">201</span></a>    <span class="n">click</span><span class="o">.</span><span class="n">secho</span><span class="p">(</span><span class="s1">&#39;PerplexiPy Codex version </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">__VERSION__</span><span class="p">,</span> <span class="n">fg</span> <span class="o">=</span> <span class="s1">&#39;bright_green&#39;</span><span class="p">)</span>
+</span><span id="L-202"><a href="#L-202"><span class="linenos">202</span></a>
+</span><span id="L-203"><a href="#L-203"><span class="linenos">203</span></a>
+</span><span id="L-204"><a href="#L-204"><span class="linenos">204</span></a><span class="k">def</span> <span class="nf">_saveConfigTo</span><span class="p">(</span><span class="n">config</span><span class="p">:</span> <span class="nb">dict</span><span class="p">,</span> <span class="n">fileName</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="n">CONFIG_FILE_NAME</span><span class="p">,</span> <span class="n">pathName</span> <span class="o">=</span> <span class="n">CONFIG_PATH</span><span class="p">):</span>
+</span><span id="L-205"><a href="#L-205"><span class="linenos">205</span></a>    <span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">pathName</span><span class="p">):</span>
+</span><span id="L-206"><a href="#L-206"><span class="linenos">206</span></a>        <span class="n">os</span><span class="o">.</span><span class="n">makedirs</span><span class="p">(</span><span class="n">pathName</span><span class="p">)</span>
+</span><span id="L-207"><a href="#L-207"><span class="linenos">207</span></a>    <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">fileName</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">outputFile</span><span class="p">:</span>
+</span><span id="L-208"><a href="#L-208"><span class="linenos">208</span></a>        <span class="n">yaml</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">config</span><span class="p">,</span> <span class="n">outputFile</span><span class="p">)</span>
+</span><span id="L-209"><a href="#L-209"><span class="linenos">209</span></a>
+</span><span id="L-210"><a href="#L-210"><span class="linenos">210</span></a>
+</span><span id="L-211"><a href="#L-211"><span class="linenos">211</span></a><span class="k">def</span> <span class="nf">_loadConfigFrom</span><span class="p">(</span><span class="n">fileName</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="n">CONFIG_FILE_NAME</span><span class="p">,</span> <span class="n">pathName</span> <span class="o">=</span> <span class="n">CONFIG_PATH</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
+</span><span id="L-212"><a href="#L-212"><span class="linenos">212</span></a>    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">fileName</span><span class="p">):</span>
+</span><span id="L-213"><a href="#L-213"><span class="linenos">213</span></a>        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">fileName</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">inputFile</span><span class="p">:</span>
+</span><span id="L-214"><a href="#L-214"><span class="linenos">214</span></a>            <span class="n">config</span> <span class="o">=</span> <span class="n">yaml</span><span class="o">.</span><span class="n">safe_load</span><span class="p">(</span><span class="n">inputFile</span><span class="p">)</span>
+</span><span id="L-215"><a href="#L-215"><span class="linenos">215</span></a>    <span class="k">else</span><span class="p">:</span>
+</span><span id="L-216"><a href="#L-216"><span class="linenos">216</span></a>        <span class="n">config</span> <span class="o">=</span> <span class="p">{</span>
+</span><span id="L-217"><a href="#L-217"><span class="linenos">217</span></a>            <span class="s1">&#39;activeModel&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span>
+</span><span id="L-218"><a href="#L-218"><span class="linenos">218</span></a>            <span class="s1">&#39;editingMode&#39;</span><span class="p">:</span> <span class="s1">&#39;vi&#39;</span><span class="p">,</span>
+</span><span id="L-219"><a href="#L-219"><span class="linenos">219</span></a>            <span class="s1">&#39;queryCodeStyle&#39;</span><span class="p">:</span> <span class="n">_queryCodeStyle</span><span class="p">,</span>
+</span><span id="L-220"><a href="#L-220"><span class="linenos">220</span></a>        <span class="p">}</span>
+</span><span id="L-221"><a href="#L-221"><span class="linenos">221</span></a>        <span class="n">_saveConfigTo</span><span class="p">(</span><span class="n">config</span><span class="p">,</span> <span class="n">fileName</span><span class="p">,</span> <span class="n">pathName</span><span class="p">)</span>
+</span><span id="L-222"><a href="#L-222"><span class="linenos">222</span></a>    <span class="k">return</span> <span class="n">config</span>
+</span><span id="L-223"><a href="#L-223"><span class="linenos">223</span></a>
+</span><span id="L-224"><a href="#L-224"><span class="linenos">224</span></a>
+</span><span id="L-225"><a href="#L-225"><span class="linenos">225</span></a><span class="k">def</span> <span class="nf">_displayConfigInfo</span><span class="p">():</span>
+</span><span id="L-226"><a href="#L-226"><span class="linenos">226</span></a>    <span class="k">pass</span>
+</span><span id="L-227"><a href="#L-227"><span class="linenos">227</span></a>    <span class="n">click</span><span class="o">.</span><span class="n">secho</span><span class="p">(</span><span class="s1">&#39;Config file: </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">CONFIG_FILE_NAME</span><span class="p">)</span>
+</span><span id="L-228"><a href="#L-228"><span class="linenos">228</span></a>    <span class="n">click</span><span class="o">.</span><span class="n">secho</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">_loadConfigFrom</span><span class="p">())</span><span class="o">+</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
+</span><span id="L-229"><a href="#L-229"><span class="linenos">229</span></a>
+</span><span id="L-230"><a href="#L-230"><span class="linenos">230</span></a>
+</span><span id="L-231"><a href="#L-231"><span class="linenos">231</span></a><span class="c1"># TODO: Refactor REPL - https://github.com/CIME-Software/perplexipy/issues/46</span>
+</span><span id="L-232"><a href="#L-232"><span class="linenos">232</span></a><span class="k">def</span> <span class="nf">_runREPL</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
+</span><span id="L-233"><a href="#L-233"><span class="linenos">233</span></a><span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
+</span><span id="L-234"><a href="#L-234"><span class="linenos">234</span></a><span class="sd">    Run a REPL loop for sending queries to the AI provider.</span>
+</span><span id="L-235"><a href="#L-235"><span class="linenos">235</span></a>
+</span><span id="L-236"><a href="#L-236"><span class="linenos">236</span></a><span class="sd">    Returns</span>
+</span><span id="L-237"><a href="#L-237"><span class="linenos">237</span></a><span class="sd">    -------</span>
+</span><span id="L-238"><a href="#L-238"><span class="linenos">238</span></a><span class="sd">    The word &quot;REPL&quot; to signal to the `codex` command that it received valid</span>
+</span><span id="L-239"><a href="#L-239"><span class="linenos">239</span></a><span class="sd">    input.</span>
+</span><span id="L-240"><a href="#L-240"><span class="linenos">240</span></a><span class="sd">    &quot;&quot;&quot;</span>
+</span><span id="L-241"><a href="#L-241"><span class="linenos">241</span></a>    <span class="n">config</span> <span class="o">=</span> <span class="n">_loadConfigFrom</span><span class="p">()</span>
+</span><span id="L-242"><a href="#L-242"><span class="linenos">242</span></a>    <span class="n">session</span> <span class="o">=</span> <span class="n">PromptSession</span><span class="p">()</span>
+</span><span id="L-243"><a href="#L-243"><span class="linenos">243</span></a>    <span class="n">_activeModel</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">_client</span><span class="o">.</span><span class="n">models</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;activeModel&#39;</span><span class="p">])</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
+</span><span id="L-244"><a href="#L-244"><span class="linenos">244</span></a>    <span class="n">_REPLHello</span><span class="p">()</span>
+</span><span id="L-245"><a href="#L-245"><span class="linenos">245</span></a>    <span class="n">session</span> <span class="o">=</span> <span class="n">_editingMode</span><span class="p">(</span><span class="n">session</span><span class="p">,</span> <span class="n">config</span><span class="p">[</span><span class="s1">&#39;editingMode&#39;</span><span class="p">])</span>
+</span><span id="L-246"><a href="#L-246"><span class="linenos">246</span></a>    <span class="n">_queryStyle</span><span class="p">(</span><span class="s1">&#39;code&#39;</span> <span class="k">if</span> <span class="n">config</span><span class="p">[</span><span class="s1">&#39;queryCodeStyle&#39;</span><span class="p">]</span> <span class="k">else</span> <span class="s1">&#39;human&#39;</span><span class="p">)</span>
+</span><span id="L-247"><a href="#L-247"><span class="linenos">247</span></a>    <span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
+</span><span id="L-248"><a href="#L-248"><span class="linenos">248</span></a>        <span class="n">userQuery</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="n">prompt</span><span class="p">(</span><span class="s1">&#39;Ask anything (/exit to end): &#39;</span><span class="p">)</span>
+</span><span id="L-249"><a href="#L-249"><span class="linenos">249</span></a>        <span class="k">if</span> <span class="n">userQuery</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">,</span> <span class="s1">&#39;?&#39;</span><span class="p">,</span> <span class="s1">&#39;:&#39;</span><span class="p">):</span>
+</span><span id="L-250"><a href="#L-250"><span class="linenos">250</span></a>            <span class="n">parts</span> <span class="o">=</span> <span class="n">userQuery</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">)</span>
+</span><span id="L-251"><a href="#L-251"><span class="linenos">251</span></a>            <span class="n">command</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
+</span><span id="L-252"><a href="#L-252"><span class="linenos">252</span></a>            <span class="k">if</span> <span class="n">command</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">&#39;/exit&#39;</span><span class="p">,</span> <span class="s1">&#39;/quit&#39;</span><span class="p">,</span> <span class="s1">&#39;:q&#39;</span><span class="p">,</span> <span class="s1">&#39;/q&#39;</span><span class="p">):</span>
+</span><span id="L-253"><a href="#L-253"><span class="linenos">253</span></a>                <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
+</span><span id="L-254"><a href="#L-254"><span class="linenos">254</span></a>            <span class="k">elif</span> <span class="n">command</span> <span class="o">==</span> <span class="s1">&#39;/active&#39;</span><span class="p">:</span>
+</span><span id="L-255"><a href="#L-255"><span class="linenos">255</span></a>                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">parts</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
+</span><span id="L-256"><a href="#L-256"><span class="linenos">256</span></a>                    <span class="k">try</span><span class="p">:</span>
+</span><span id="L-257"><a href="#L-257"><span class="linenos">257</span></a>                        <span class="n">model</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">parts</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
+</span><span id="L-258"><a href="#L-258"><span class="linenos">258</span></a>                        <span class="n">config</span><span class="p">[</span><span class="s1">&#39;activeModel&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">_activeModel</span><span class="p">(</span><span class="n">model</span><span class="p">)</span>
+</span><span id="L-259"><a href="#L-259"><span class="linenos">259</span></a>                        <span class="n">_saveConfigTo</span><span class="p">(</span><span class="n">config</span><span class="p">)</span>
+</span><span id="L-260"><a href="#L-260"><span class="linenos">260</span></a>                    <span class="k">except</span><span class="p">:</span>
+</span><span id="L-261"><a href="#L-261"><span class="linenos">261</span></a>                        <span class="c1"># Invalid input, ignore and leave the current model</span>
+</span><span id="L-262"><a href="#L-262"><span class="linenos">262</span></a>                        <span class="c1"># active.</span>
+</span><span id="L-263"><a href="#L-263"><span class="linenos">263</span></a>                        <span class="k">pass</span>
+</span><span id="L-264"><a href="#L-264"><span class="linenos">264</span></a>                <span class="k">else</span><span class="p">:</span>
+</span><span id="L-265"><a href="#L-265"><span class="linenos">265</span></a>                    <span class="n">_activeModel</span><span class="p">()</span>
+</span><span id="L-266"><a href="#L-266"><span class="linenos">266</span></a>            <span class="k">elif</span> <span class="n">command</span> <span class="o">==</span> <span class="s1">&#39;/cinfo&#39;</span><span class="p">:</span>
+</span><span id="L-267"><a href="#L-267"><span class="linenos">267</span></a>                <span class="n">_displayConfigInfo</span><span class="p">()</span>
+</span><span id="L-268"><a href="#L-268"><span class="linenos">268</span></a>            <span class="k">elif</span> <span class="n">command</span> <span class="o">==</span> <span class="s1">&#39;/clear&#39;</span><span class="p">:</span>
+</span><span id="L-269"><a href="#L-269"><span class="linenos">269</span></a>                <span class="n">click</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
+</span><span id="L-270"><a href="#L-270"><span class="linenos">270</span></a>                <span class="n">_editingMode</span><span class="p">(</span><span class="n">session</span><span class="p">)</span>
+</span><span id="L-271"><a href="#L-271"><span class="linenos">271</span></a>            <span class="k">elif</span> <span class="n">command</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">&#39;/help&#39;</span><span class="p">,</span> <span class="s1">&#39;?&#39;</span><span class="p">):</span>
+</span><span id="L-272"><a href="#L-272"><span class="linenos">272</span></a>                <span class="n">_helpREPL</span><span class="p">()</span>
+</span><span id="L-273"><a href="#L-273"><span class="linenos">273</span></a>            <span class="k">elif</span> <span class="n">command</span> <span class="o">==</span> <span class="s1">&#39;/mode&#39;</span><span class="p">:</span>
+</span><span id="L-274"><a href="#L-274"><span class="linenos">274</span></a>                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">parts</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
+</span><span id="L-275"><a href="#L-275"><span class="linenos">275</span></a>                    <span class="k">try</span><span class="p">:</span>
+</span><span id="L-276"><a href="#L-276"><span class="linenos">276</span></a>                        <span class="n">session</span> <span class="o">=</span> <span class="n">_editingMode</span><span class="p">(</span><span class="n">session</span><span class="p">,</span> <span class="n">parts</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
+</span><span id="L-277"><a href="#L-277"><span class="linenos">277</span></a>                        <span class="n">config</span><span class="p">[</span><span class="s1">&#39;editingMode&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
+</span><span id="L-278"><a href="#L-278"><span class="linenos">278</span></a>                        <span class="n">_saveConfigTo</span><span class="p">(</span><span class="n">config</span><span class="p">)</span>
+</span><span id="L-279"><a href="#L-279"><span class="linenos">279</span></a>                    <span class="k">except</span><span class="p">:</span>
+</span><span id="L-280"><a href="#L-280"><span class="linenos">280</span></a>                        <span class="k">pass</span>
+</span><span id="L-281"><a href="#L-281"><span class="linenos">281</span></a>                <span class="k">else</span><span class="p">:</span>
+</span><span id="L-282"><a href="#L-282"><span class="linenos">282</span></a>                    <span class="n">_editingMode</span><span class="p">(</span><span class="n">session</span><span class="p">)</span>
+</span><span id="L-283"><a href="#L-283"><span class="linenos">283</span></a>            <span class="k">elif</span> <span class="n">command</span> <span class="o">==</span> <span class="s1">&#39;/models&#39;</span><span class="p">:</span>
+</span><span id="L-284"><a href="#L-284"><span class="linenos">284</span></a>                <span class="n">_displayModels</span><span class="p">()</span>
+</span><span id="L-285"><a href="#L-285"><span class="linenos">285</span></a>            <span class="k">elif</span> <span class="n">command</span> <span class="o">==</span> <span class="s1">&#39;/style&#39;</span><span class="p">:</span>
+</span><span id="L-286"><a href="#L-286"><span class="linenos">286</span></a>                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">parts</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
+</span><span id="L-287"><a href="#L-287"><span class="linenos">287</span></a>                    <span class="n">queryStyleType</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
+</span><span id="L-288"><a href="#L-288"><span class="linenos">288</span></a>                    <span class="n">config</span><span class="p">[</span><span class="s1">&#39;queryCodeStyle&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">_queryStyle</span><span class="p">(</span><span class="n">queryStyleType</span><span class="p">)</span>
+</span><span id="L-289"><a href="#L-289"><span class="linenos">289</span></a>                    <span class="n">_saveConfigTo</span><span class="p">(</span><span class="n">config</span><span class="p">)</span>
+</span><span id="L-290"><a href="#L-290"><span class="linenos">290</span></a>                <span class="k">else</span><span class="p">:</span>
+</span><span id="L-291"><a href="#L-291"><span class="linenos">291</span></a>                    <span class="n">_queryStyle</span><span class="p">()</span>
+</span><span id="L-292"><a href="#L-292"><span class="linenos">292</span></a>            <span class="k">elif</span> <span class="n">command</span> <span class="o">==</span> <span class="s1">&#39;/version&#39;</span><span class="p">:</span>
+</span><span id="L-293"><a href="#L-293"><span class="linenos">293</span></a>                <span class="n">_displayVersion</span><span class="p">()</span>
+</span><span id="L-294"><a href="#L-294"><span class="linenos">294</span></a>            <span class="k">continue</span>
+</span><span id="L-295"><a href="#L-295"><span class="linenos">295</span></a>        <span class="n">result</span> <span class="o">=</span> <span class="n">_makeQuery</span><span class="p">(</span><span class="n">userQuery</span><span class="p">)</span>
+</span><span id="L-296"><a href="#L-296"><span class="linenos">296</span></a>        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">result</span><span class="p">)</span>
+</span><span id="L-297"><a href="#L-297"><span class="linenos">297</span></a>        <span class="n">click</span><span class="o">.</span><span class="n">secho</span><span class="p">(</span><span class="s1">&#39;--------------------------------------------------&#39;</span><span class="p">,</span> <span class="n">fg</span> <span class="o">=</span> <span class="s1">&#39;green&#39;</span><span class="p">)</span>
+</span><span id="L-298"><a href="#L-298"><span class="linenos">298</span></a>        <span class="nb">print</span><span class="p">()</span>
+</span><span id="L-299"><a href="#L-299"><span class="linenos">299</span></a>
+</span><span id="L-300"><a href="#L-300"><span class="linenos">300</span></a>    <span class="k">return</span> <span class="s1">&#39;REPL&#39;</span>
+</span><span id="L-301"><a href="#L-301"><span class="linenos">301</span></a>
+</span><span id="L-302"><a href="#L-302"><span class="linenos">302</span></a>
+</span><span id="L-303"><a href="#L-303"><span class="linenos">303</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-304"><a href="#L-304"><span class="linenos">304</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-305"><a href="#L-305"><span class="linenos">305</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-306"><a href="#L-306"><span class="linenos">306</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-307"><a href="#L-307"><span class="linenos">307</span></a><span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
+</span><span id="L-308"><a href="#L-308"><span class="linenos">308</span></a><span class="sd">    Process a command line query and display the result to the console.</span>
+</span><span id="L-309"><a href="#L-309"><span class="linenos">309</span></a>
+</span><span id="L-310"><a href="#L-310"><span class="linenos">310</span></a><span class="sd">    Arguments</span>
+</span><span id="L-311"><a href="#L-311"><span class="linenos">311</span></a><span class="sd">    ---------</span>
+</span><span id="L-312"><a href="#L-312"><span class="linenos">312</span></a><span class="sd">        tokens</span>
+</span><span id="L-313"><a href="#L-313"><span class="linenos">313</span></a><span class="sd">    A list of tokens that will be assembled as a single string for</span>
+</span><span id="L-314"><a href="#L-314"><span class="linenos">314</span></a><span class="sd">    processing.</span>
+</span><span id="L-315"><a href="#L-315"><span class="linenos">315</span></a>
+</span><span id="L-316"><a href="#L-316"><span class="linenos">316</span></a><span class="sd">    Returns</span>
+</span><span id="L-317"><a href="#L-317"><span class="linenos">317</span></a><span class="sd">    -------</span>
+</span><span id="L-318"><a href="#L-318"><span class="linenos">318</span></a><span class="sd">    A string with the response to the query, after displaying it to the</span>
+</span><span id="L-319"><a href="#L-319"><span class="linenos">319</span></a><span class="sd">    console.</span>
+</span><span id="L-320"><a href="#L-320"><span class="linenos">320</span></a><span class="sd">    &quot;&quot;&quot;</span>
+</span><span id="L-321"><a href="#L-321"><span class="linenos">321</span></a>    <span class="n">result</span> <span class="o">=</span> <span class="kc">None</span>
+</span><span id="L-322"><a href="#L-322"><span class="linenos">322</span></a>    <span class="n">userQuery</span> <span class="o">=</span> <span class="kc">None</span>
+</span><span id="L-323"><a href="#L-323"><span class="linenos">323</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-324"><a href="#L-324"><span class="linenos">324</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 class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">tokens</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="n">ARG_REPL</span><span class="p">:</span>
+</span><span id="L-325"><a href="#L-325"><span class="linenos">325</span></a>            <span class="n">userQuery</span> <span class="o">=</span> <span class="n">_runREPL</span><span class="p">()</span>
+</span><span id="L-326"><a href="#L-326"><span class="linenos">326</span></a>        <span class="k">else</span><span class="p">:</span>
+</span><span id="L-327"><a href="#L-327"><span class="linenos">327</span></a>            <span class="n">userQuery</span> <span class="o">=</span> <span class="n">QUERY_CRISP</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-328"><a href="#L-328"><span class="linenos">328</span></a>    <span class="k">elif</span> <span class="n">_stdinHasData</span><span class="p">():</span>
+</span><span id="L-329"><a href="#L-329"><span class="linenos">329</span></a>        <span class="n">userQuery</span> <span class="o">=</span> <span class="n">_assembleInput</span><span class="p">()</span>
+</span><span id="L-330"><a href="#L-330"><span class="linenos">330</span></a>        <span class="n">userQuery</span> <span class="o">=</span> <span class="n">QUERY_DETAILED</span><span class="o">+</span><span class="n">userQuery</span>
+</span><span id="L-331"><a href="#L-331"><span class="linenos">331</span></a>
+</span><span id="L-332"><a href="#L-332"><span class="linenos">332</span></a>    <span class="k">if</span> <span class="n">userQuery</span><span class="p">:</span>
+</span><span id="L-333"><a href="#L-333"><span class="linenos">333</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-334"><a href="#L-334"><span class="linenos">334</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-335"><a href="#L-335"><span class="linenos">335</span></a>    <span class="k">else</span><span class="p">:</span>
+</span><span id="L-336"><a href="#L-336"><span class="linenos">336</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-337"><a href="#L-337"><span class="linenos">337</span></a>
+</span><span id="L-338"><a href="#L-338"><span class="linenos">338</span></a>    <span class="k">return</span> <span class="n">result</span>
+</span><span id="L-339"><a href="#L-339"><span class="linenos">339</span></a>
+</span><span id="L-340"><a href="#L-340"><span class="linenos">340</span></a>
+</span><span id="L-341"><a href="#L-341"><span class="linenos">341</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-342"><a href="#L-342"><span class="linenos">342</span></a>    <span class="n">codex</span><span class="p">()</span>
 </span></pre></div>
 
 
diff --git a/docs/search.js b/docs/search.js
index eb18f83..a08dc2b 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;assistant&#x27;, &#x27;system&#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.DEFAULT_LLM", "modulename": "perplexipy.codex", "qualname": "DEFAULT_LLM", "kind": "variable", "doc": "<p></p>\n", "default_value": "&#x27;mixtral-8x7b-instruct&#x27;"}, {"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;user&#x27;, &#x27;assistant&#x27;, &#x27;system&#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.DEFAULT_LLM", "modulename": "perplexipy.codex", "qualname": "DEFAULT_LLM", "kind": "variable", "doc": "<p></p>\n", "default_value": "&#x27;mixtral-8x7b-instruct&#x27;"}, {"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 8220596..1590980 100644
--- a/perplexipy/codex.py
+++ b/perplexipy/codex.py
@@ -123,7 +123,7 @@ def _activeModel(modelID: int = 0) -> str:
         except:
             click.secho('Invalid model ID = %s' % modelID, bg = 'red', fg = 'white')
     click.secho('Active model: %s\n' % _client.model, fg = 'green', bold = True)
-    return modelID
+    return _client.model
 
 
 def _REPLHello():
@@ -150,7 +150,14 @@ def _helpREPL():
 """)
 
 
-def _displayModels() -> str:
+def _displayModels() -> list:
+    """
+    Display the list of models supported by the API.
+
+    Returns
+    =======
+    A list of strings, each corresponding to a model name.
+    """
     _activeModel()
     print('Available models:\n')
     n = 1
@@ -159,6 +166,8 @@ def _displayModels() -> str:
         n += 1
     print()
 
+    return list(_client.models.keys())
+
 
 def _editingMode(session: PromptSession, mode = None):
     if mode:
@@ -229,10 +238,10 @@ def _runREPL() -> str:
     The word "REPL" to signal to the `codex` command that it received valid
     input.
     """
-    _REPLHello()
     config = _loadConfigFrom()
     session = PromptSession()
-    _activeModel(config['activeModel'])
+    _activeModel(list(_client.models.keys()).index(config['activeModel'])+1)
+    _REPLHello()
     session = _editingMode(session, config['editingMode'])
     _queryStyle('code' if config['queryCodeStyle'] else 'human')
     while True:
@@ -249,7 +258,9 @@ def _runREPL() -> str:
                         config['activeModel'] = _activeModel(model)
                         _saveConfigTo(config)
                     except:
-                        _activeModel()
+                        # Invalid input, ignore and leave the current model
+                        # active.
+                        pass
                 else:
                     _activeModel()
             elif command == '/cinfo':
diff --git a/pyproject.toml b/pyproject.toml
index 0c83ec5..c3f3473 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 = '1.0.1'
+version = '1.0.3'
 
 
 [project.scripts]


Test patch:
diff --git a/tests/codex-test.py b/tests/codex-test.py
index dc84087..9ae4bf4 100644
--- a/tests/codex-test.py
+++ b/tests/codex-test.py
@@ -4,9 +4,12 @@
 from unittest.mock import patch
 
 from click.testing import CliRunner
-from perplexipy.codex import codexCore
-from perplexipy.codex import codex
+from perplexipy.codex import DEFAULT_LLM
+from perplexipy.codex import _activeModel
+from perplexipy.codex import _displayModels
 from perplexipy.codex import _loadConfigFrom
+from perplexipy.codex import codex
+from perplexipy.codex import codexCore
 
 import os
 import pytest
@@ -30,6 +33,11 @@ def _configPath():
     return TEST_CONFIG_PATH
 
 
+@pytest.fixture(autouse = True)
+def stdoutHide(monkeypatch):
+    monkeypatch.setattr('sys.stdout', open('/dev/null', 'w'))
+
+
 # *** tests ***
 
 def test_codexCore():
@@ -67,5 +75,24 @@ def test__loadConfigFrom(_configFileName, _configPath):
     assert isinstance(config, dict)
 
 
-# test__loadConfigFrom(TEST_CONFIG_FILE_NAME, TEST_CONFIG_PATH)
+def test__displayModels():
+    models = _displayModels()
+    assert models
+    assert isinstance(models, list)
+    assert DEFAULT_LLM in models
+
+
+def test__activateModel():
+    model = _activeModel()
+    assert model
+    assert isinstance(model, str)
+
+    models = _displayModels()
+
+    modelID = len(models)
+    model = _activeModel(modelID)
+    assert models[modelID-1] == model
+    modelID = 2
+    model = _activeModel(modelID)
+    assert models[modelID-1] == model