Skip to content

Commit b677f2e

Browse files
committed
Added QA DATABASE
1 parent afa5bdb commit b677f2e

5 files changed

Lines changed: 104 additions & 2 deletions

File tree

AI_AgentModel.vb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ Public Class AI_AgentModel
1919
''' <param name="UserInput"></param>
2020
''' <returns></returns>
2121
Public Function GET_RESPONSE(ByRef UserInput As String) As String
22+
'Get External Responses
2223
GET_RESPONSE = GetPluginResponse(UserInput, PreviousUserInput, PreviousResponse)
24+
'IF NO RESPONSE TRY - Question Answer Database
25+
If GET_RESPONSE = "" Then GetQAResponse(UserInput, GET_RESPONSE)
26+
'IF No Response Fallback Response
2327
If GET_RESPONSE = "" Then GET_RESPONSE = "Excuse me? Please, Rephrase?"
2428
End Function
2529
Private Function GetPluginResponse(ByRef UserInput As String, ByRef PrevUSerInput As String, ByRef PrevResponse As String) As String

Chatbot_2020_Tutorial.vbproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
<DependentUpon>Settings.settings</DependentUpon>
107107
<DesignTimeSharedInput>True</DesignTimeSharedInput>
108108
</Compile>
109+
<Compile Include="QuestionAnswer.vb" />
109110
<Compile Include="SplashScreen.Designer.vb">
110111
<DependentUpon>SplashScreen.vb</DependentUpon>
111112
</Compile>

Plugins/SamplePlugin.dll

0 Bytes
Binary file not shown.

QuestionAnswer.vb

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
2+
3+
Module QuestionAnswer
4+
Public Function GetQAResponse(ByRef UserInput As String, ByRef Response As String) As Boolean
5+
GetQAResponse = False
6+
If DetectAnswerMindQA(UCase(UserInput), Response) = True Then
7+
Return True
8+
Else
9+
End If
10+
11+
If DetectAnswerQAMind(UCase(UserInput), Response) = True Then
12+
Return True
13+
Else
14+
End If
15+
16+
End Function
17+
18+
Public Function DetectAnswerMindQA(ByRef Question As String, ByRef Answer As String) As Boolean
19+
Dim Knowledge As List(Of TopicQuestion) = GetMindQA()
20+
DetectAnswerMindQA = False
21+
For Each item In Knowledge
22+
If UCase(item.Question) Like UCase(Question) = True Then
23+
Answer = item.Topic
24+
Return True
25+
Else
26+
End If
27+
Next
28+
End Function
29+
Public Function DetectAnswerQAMind(ByRef Question As String, ByRef Answer As String) As Boolean
30+
Dim Knowledge As List(Of TopicQuestion) = GetQAMind()
31+
DetectAnswerQAMind = False
32+
For Each item In Knowledge
33+
If UCase(item.Question) Like UCase(Question) = True Then
34+
Answer = item.Topic
35+
Return True
36+
Else
37+
End If
38+
Next
39+
End Function
40+
Private Function GetMindQA() As List(Of TopicQuestion)
41+
Dim DbSubjectLst As New List(Of TopicQuestion)
42+
Const SQL As String = "SELECT * FROM MINDQA"
43+
Using conn = New System.Data.OleDb.OleDbConnection(My.Settings.MindQAConnectionString)
44+
Using cmd = New OleDb.OleDbCommand(SQL, conn)
45+
conn.Open()
46+
Try
47+
Dim dr = cmd.ExecuteReader()
48+
While dr.Read()
49+
Dim NewKnowledge As TopicQuestion
50+
NewKnowledge.Question = dr("QUESTION").ToString()
51+
NewKnowledge.Topic = dr("Answer").ToString()
52+
DbSubjectLst.Add(NewKnowledge)
53+
End While
54+
Catch e As Exception
55+
' Do some logging or something.
56+
MessageBox.Show("There was an error accessing your data. MINDQA: " & e.ToString())
57+
End Try
58+
End Using
59+
End Using
60+
Return DbSubjectLst
61+
End Function
62+
Private Structure TopicQuestion
63+
''' <summary>
64+
''' Question Associated with topic (can be used as a Flat response) or Can be used to
65+
''' learn new information from multiple sources
66+
''' </summary>
67+
''' <remarks></remarks>
68+
Public Question As String
69+
''' <summary>
70+
''' Topic of Associated Question
71+
''' </summary>
72+
''' <remarks></remarks>
73+
Public Topic As String
74+
End Structure
75+
Private Function GetQAMind() As List(Of TopicQuestion)
76+
Dim DbSubjectLst As New List(Of TopicQuestion)
77+
Const SQL As String = "SELECT * FROM QAMIND"
78+
Using conn = New System.Data.OleDb.OleDbConnection(My.Settings.MindQAConnectionString)
79+
Using cmd = New System.Data.OleDb.OleDbCommand(SQL, conn)
80+
conn.Open()
81+
Try
82+
Dim dr = cmd.ExecuteReader()
83+
While dr.Read()
84+
Dim NewKnowledge As TopicQuestion
85+
NewKnowledge.Question = dr("QUESTION").ToString()
86+
NewKnowledge.Topic = dr("ANSWER").ToString()
87+
DbSubjectLst.Add(NewKnowledge)
88+
End While
89+
Catch e As Exception
90+
' Do some logging or something.
91+
MessageBox.Show("There was an error accessing your data. QA-MIND: " & e.ToString())
92+
End Try
93+
End Using
94+
End Using
95+
Return DbSubjectLst
96+
End Function
97+
End Module

SamplePlugin/Sample_Plugin_Chatbot_Tutorial.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ Public Class Sample_Plugin_Chatbot_Tutorial
4444
End Property
4545

4646
Public Function GetResponse(UserInput As String) As Boolean Implements IPlugin.GetResponse
47-
Dim NewResponse As String = "HI - Here we will Design its brain function"
48-
47+
Dim NewResponse As String = ""
48+
If UCase(UserInput) = "HI" Then NewResponse = "YO BRO"
4949
If NewResponse IsNot Nothing Then
5050
Response = NewResponse
5151
Return True

0 commit comments

Comments
 (0)