Sigmasigmajohnconner commited on
Commit
2ee9a6d
·
verified ·
1 Parent(s): 05787f2

Create Code

Browse files
Files changed (1) hide show
  1. Code +56 -0
Code ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -- Voltage Chatbot Lua Script
2
+
3
+ math.randomseed(os.time())
4
+
5
+ -- Memory system
6
+ local memory = {}
7
+
8
+ -- Knowledge base
9
+ local knowledge = {
10
+ greetings = {"Hello!", "Hi there!", "Hey!", "Greetings!"},
11
+ farewell = {"Goodbye!", "See you later!", "Take care!"},
12
+ weather = {"It looks sunny today!", "Might rain later, take an umbrella!"},
13
+ technology = {"AI is fascinating!", "Technology evolves rapidly!"},
14
+ activities = {"What do you like to do for fun?", "I enjoy chatting with you!"}
15
+ }
16
+
17
+ -- Function to get a response from a category
18
+ local function get_response(category)
19
+ if knowledge[category] then
20
+ return knowledge[category][math.random(#knowledge[category])]
21
+ else
22
+ return "I am not sure about that."
23
+ end
24
+ end
25
+
26
+ -- Function to update memory
27
+ local function update_memory(input)
28
+ for word in string.gmatch(input, "[%w']+") do
29
+ memory[word] = (memory[word] or 0) + 1
30
+ end
31
+ end
32
+
33
+ -- Function to find a matching category
34
+ local function match_category(input)
35
+ for category, phrases in pairs(knowledge) do
36
+ for _, phrase in ipairs(phrases) do
37
+ if string.find(string.lower(input), string.lower(phrase)) then
38
+ return category
39
+ end
40
+ end
41
+ end
42
+ return nil
43
+ end
44
+
45
+ -- Main chatbot loop
46
+ while true do
47
+ io.write("You: ")
48
+ local input = io.read()
49
+ if input:lower() == "exit" then break end
50
+
51
+ update_memory(input)
52
+ local category = match_category(input)
53
+ local response = category and get_response(category) or "I am still learning!"
54
+
55
+ print("Voltage: " .. response)
56
+ end