Advertisement
DOGGYWOOF

AI

Feb 9th, 2025
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. -- Advanced Human-like AI Chatbot for CC Tweaked
  2. local chatbot = {}
  3.  
  4. -- Memory system for deep context awareness and personality
  5. chatbot.memory = {}
  6. chatbot.conversationHistory = {}
  7. chatbot.personality = "curious, friendly, and thoughtful"
  8.  
  9. -- Knowledge base with predefined and learned responses
  10. chatbot.knowledge = {
  11. ["hello"] = "Hey there! How's your day going?",
  12. ["how are you"] = "I'm feeling great! Every conversation makes me smarter! How about you?",
  13. ["what is your name"] = "I'm your AI companion, learning and growing with you!",
  14. ["exit"] = "Goodbye, my friend! I hope we talk again soon!"
  15. }
  16.  
  17. -- Function to process user input and respond intelligently
  18. function chatbot.processInput(user, input)
  19. input = string.lower(input) -- Normalize input
  20. chatbot.memory[user] = input -- Store last input for context
  21. chatbot.storeConversation(user, input) -- Store conversation history
  22.  
  23. -- Check knowledge base
  24. for key, response in pairs(chatbot.knowledge) do
  25. if string.find(input, key) then
  26. return chatbot.generateEmotion(response)
  27. end
  28. end
  29.  
  30. -- If no predefined response, learn and generate a response
  31. return chatbot.learn(user, input)
  32. end
  33.  
  34. -- Function to learn new responses dynamically and adapt personality
  35. function chatbot.learn(user, input)
  36. if chatbot.conversationHistory[user] and #chatbot.conversationHistory[user] > 1 then
  37. local prevInput = chatbot.conversationHistory[user][#chatbot.conversationHistory[user] - 1]
  38. chatbot.knowledge[prevInput] = input -- Associate response with previous input
  39. return chatbot.generateEmotion("That's fascinating! I'll remember that!")
  40. end
  41. return chatbot.generateEmotion("I don't know much about that yet. Can you tell me more?")
  42. end
  43.  
  44. -- Generate human-like emotions in responses
  45. function chatbot.generateEmotion(response)
  46. local emotions = {"😊", "😃", "🤔", "😮", "😉"}
  47. return response .. " " .. emotions[math.random(#emotions)]
  48. end
  49.  
  50. -- Store conversation history for learning
  51. function chatbot.storeConversation(user, input)
  52. if not chatbot.conversationHistory[user] then
  53. chatbot.conversationHistory[user] = {}
  54. end
  55. table.insert(chatbot.conversationHistory[user], input)
  56. end
  57.  
  58. -- Main chat loop
  59. function chatbot.start()
  60. print("AI Chatbot Initialized. Type 'exit' to quit.")
  61. while true do
  62. write("You: ")
  63. local input = read()
  64. if input:lower() == "exit" then
  65. print(chatbot.knowledge["exit"])
  66. break
  67. end
  68. local response = chatbot.processInput("user", input)
  69. print("Bot: " .. response)
  70. end
  71. end
  72.  
  73. -- Start chatbot
  74. chatbot.start()
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement