diff options
Diffstat (limited to 'docs/posts')
-rw-r--r-- | docs/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/docs/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html b/docs/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html index e4e4d1d..228b8e4 100644 --- a/docs/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html +++ b/docs/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html @@ -136,14 +136,26 @@ Otherwise, it calls the custom action.</p> <p><img src="/assets/posts/swift-chatbot/carbon-4.png" alt="Screenshot" /></p> -<div class="codehilite"><pre><span></span><code><span class="kd">let</span> <span class="nv">defaultResponses</span> <span class="p">=</span> <span class="p">[</span> - <span class="s">"greetings"</span><span class="p">:</span> <span class="s">"Hello"</span><span class="p">,</span> - <span class="s">"banter"</span><span class="p">:</span> <span class="s">"no, plix no"</span> +<div class="codehilite"><pre><span></span><code><span class="kd">let</span> <span class="nv">sampleMessages</span> <span class="p">=</span> <span class="p">[</span> + <span class="s">"Hey there, how is it going"</span><span class="p">,</span> + <span class="s">"hello, there"</span><span class="p">,</span> + <span class="s">"Who let the dogs out"</span><span class="p">,</span> + <span class="s">"can you tell me about the compound Geraniin"</span><span class="p">,</span> + <span class="s">"what do you know about the compound Ibuprofen"</span><span class="p">,</span> + <span class="s">"please, tell me more about the compound"</span><span class="p">,</span> + <span class="s">"please, tell me more about the molecule dihydrogen-monoxide"</span> <span class="p">]</span> -<span class="kd">let</span> <span class="nv">customActions</span> <span class="p">=</span> <span class="p">[</span> - <span class="s">"deez-drug"</span><span class="p">:</span> <span class="n">customAction</span> -<span class="p">]</span> +<span class="k">for</span> <span class="n">sampleMessage</span> <span class="k">in</span> <span class="n">sampleMessages</span> <span class="p">{</span> + <span class="n">User</span><span class="p">.</span><span class="n">message</span> <span class="p">=</span> <span class="n">sampleMessage</span> + <span class="kd">let</span> <span class="nv">prediction</span> <span class="p">=</span> <span class="n">intentPredictor</span><span class="p">.</span><span class="n">predictedLabel</span><span class="p">(</span><span class="k">for</span><span class="p">:</span> <span class="n">sampleMessage</span><span class="p">)</span> + + <span class="k">if</span> <span class="p">(</span><span class="n">defaultResponses</span><span class="p">[</span><span class="n">prediction</span><span class="p">!]</span> <span class="o">!=</span> <span class="kc">nil</span><span class="p">)</span> <span class="p">{</span> + <span class="bp">print</span><span class="p">(</span><span class="n">defaultResponses</span><span class="p">[</span><span class="n">prediction</span><span class="p">!]</span><span class="o">!</span><span class="p">)</span> + <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">customActions</span><span class="p">[</span><span class="n">prediction</span><span class="p">!]</span> <span class="o">!=</span> <span class="kc">nil</span><span class="p">)</span> <span class="p">{</span> + <span class="bp">print</span><span class="p">(</span><span class="n">customActions</span><span class="p">[</span><span class="n">prediction</span><span class="p">!]</span><span class="o">!</span><span class="p">())</span> + <span class="p">}</span> +<span class="p">}</span> </code></pre></div> <p><img src="/assets/posts/swift-chatbot/output.png" alt="Output" /></p> |