summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornavanchauhan <navanchauhan@gmail.com>2021-06-28 00:50:36 +0530
committernavanchauhan <navanchauhan@gmail.com>2021-06-28 00:50:36 +0530
commit9a29c1d4f33dfb7d9b1f91ab629a701bab5b8016 (patch)
tree9f878ddcc2892b529443fd94dff5c00ab9ed2b9e
parentb5c4bdce27ca7bc75c91dc28223e12ec1be2ea47 (diff)
fixed code snippet
-rw-r--r--Content/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.md24
-rw-r--r--docs/feed.rss28
-rw-r--r--docs/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html24
3 files changed, 56 insertions, 20 deletions
diff --git a/Content/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.md b/Content/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.md
index 0dcabec..804ad97 100644
--- a/Content/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.md
+++ b/Content/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.md
@@ -105,14 +105,26 @@ Otherwise, it calls the custom action.
![Screenshot](/assets/posts/swift-chatbot/carbon-4.png)
```swift
-let defaultResponses = [
- "greetings": "Hello",
- "banter": "no, plix no"
+let sampleMessages = [
+ "Hey there, how is it going",
+ "hello, there",
+ "Who let the dogs out",
+ "can you tell me about the compound Geraniin",
+ "what do you know about the compound Ibuprofen",
+ "please, tell me more about the compound",
+ "please, tell me more about the molecule dihydrogen-monoxide"
]
-let customActions = [
- "deez-drug": customAction
-]
+for sampleMessage in sampleMessages {
+ User.message = sampleMessage
+ let prediction = intentPredictor.predictedLabel(for: sampleMessage)
+
+ if (defaultResponses[prediction!] != nil) {
+ print(defaultResponses[prediction!]!)
+ } else if (customActions[prediction!] != nil) {
+ print(customActions[prediction!]!())
+ }
+}
```
![Output](/assets/posts/swift-chatbot/output.png)
diff --git a/docs/feed.rss b/docs/feed.rss
index 9a44450..7056029 100644
--- a/docs/feed.rss
+++ b/docs/feed.rss
@@ -4,8 +4,8 @@
<title>Navan's Archive</title>
<description>Rare Tips, Tricks and Posts</description>
<link>https://web.navan.dev/</link><language>en</language>
- <lastBuildDate>Mon, 28 Jun 2021 00:47:49 -0000</lastBuildDate>
- <pubDate>Mon, 28 Jun 2021 00:47:49 -0000</pubDate>
+ <lastBuildDate>Mon, 28 Jun 2021 00:50:20 -0000</lastBuildDate>
+ <pubDate>Mon, 28 Jun 2021 00:50:20 -0000</pubDate>
<ttl>250</ttl>
<atom:link href="https://web.navan.dev/feed.rss" rel="self" type="application/rss+xml"/>
@@ -2130,14 +2130,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">&quot;greetings&quot;</span><span class="p">:</span> <span class="s">&quot;Hello&quot;</span><span class="p">,</span>
- <span class="s">&quot;banter&quot;</span><span class="p">:</span> <span class="s">&quot;no, plix no&quot;</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">&quot;Hey there, how is it going&quot;</span><span class="p">,</span>
+ <span class="s">&quot;hello, there&quot;</span><span class="p">,</span>
+ <span class="s">&quot;Who let the dogs out&quot;</span><span class="p">,</span>
+ <span class="s">&quot;can you tell me about the compound Geraniin&quot;</span><span class="p">,</span>
+ <span class="s">&quot;what do you know about the compound Ibuprofen&quot;</span><span class="p">,</span>
+ <span class="s">&quot;please, tell me more about the compound&quot;</span><span class="p">,</span>
+ <span class="s">&quot;please, tell me more about the molecule dihydrogen-monoxide&quot;</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">&quot;deez-drug&quot;</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>
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">&quot;greetings&quot;</span><span class="p">:</span> <span class="s">&quot;Hello&quot;</span><span class="p">,</span>
- <span class="s">&quot;banter&quot;</span><span class="p">:</span> <span class="s">&quot;no, plix no&quot;</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">&quot;Hey there, how is it going&quot;</span><span class="p">,</span>
+ <span class="s">&quot;hello, there&quot;</span><span class="p">,</span>
+ <span class="s">&quot;Who let the dogs out&quot;</span><span class="p">,</span>
+ <span class="s">&quot;can you tell me about the compound Geraniin&quot;</span><span class="p">,</span>
+ <span class="s">&quot;what do you know about the compound Ibuprofen&quot;</span><span class="p">,</span>
+ <span class="s">&quot;please, tell me more about the compound&quot;</span><span class="p">,</span>
+ <span class="s">&quot;please, tell me more about the molecule dihydrogen-monoxide&quot;</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">&quot;deez-drug&quot;</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>