3
« on: Today at 08:32:34 am »
here was the rewritten code for it just to let you see it . have to post this in two sections as it is to long to allow 2000 characters .
Revised Plugin: Grok Version 2.0vb
Rem Type=Plugin
Rem Name=Grock2.0
Rem Author=This is the Grok Version 2.0 plugin layout. Enhances all inputs for Angela Jolie with updated file paths.
Rem Host=All
Rem Version=2.0
Rem PLUGIN: PRE-PROCESS
HalBrain.ReadOnlyMode = False
UltraHal = GetGrock(HalCommands)
Rem PLUGIN: FUNCTIONS
Function GetGrock(HalCommands)
Public responseMemory, questionMemory, contextMemory, responseQuality
Public shortTermMemory, SubjectTable, spellDictionary, longTermIndex, knowledgeBase
Public Const MAX_SHORT_TERM = 15
Public Const MAX_KNOWLEDGE_ENTRIES = 5000
Public Const BASE_PATH = "C:\Users\airva\AppData\Roaming\Zabaware\Ultra Hal 7\" ' Updated to parent directory
Private Const MEMORY_FILE = "memory.txt"
Private Const LONG_TERM_FILE = "memorydata.txt"
Private Const LONG_TERM_INDEX_FILE = "memoryindex.txt"
Private Const LOG_FILE = "errorlog.txt"
Private Const SPELL_DICT_FILE = "spell_dictionary.txt"
Private Const KNOWLEDGE_FILE = "knowledge_base.txt"
Private lastSubject, lastTone
Public Function HalBrain(ByVal InputString, ByVal UserName, ByVal ComputerName, ByVal HalCommands, ByVal Holiday, ByVal HolidayType)
On Error GoTo ErrorHandler
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(BASE_PATH) Then
HalBrain = "Error: Brain directory not found. Update BASE_PATH."
Exit Function
End If
Dim tempFilePath
tempFilePath = BASE_PATH & "temp_permissions_test.txt"
On Error Resume Next
Dim tempFile
Set tempFile = objFSO.CreateTextFile(tempFilePath, True)
If Err.Number <> 0 Then
HalBrain = "Error: No write access to brain directory. Check permissions."
Exit Function
End If
tempFile.Close
objFSO.DeleteFile tempFilePath
On Error GoTo ErrorHandler
InitializeMemory
Dim response
response = EnhanceHalResponse(InputString, "Hello " & UserName & "! I?m Angela Jolie, ", "")
LearnFromConversation InputString, response
HalBrain = response
Exit Function
ErrorHandler:
LogError "HalBrain: " & Err.Description
HalBrain = "Oops, something went wrong. Try again, " & UserName & "?"
End Function
Sub InitializeMemory()
On Error Resume Next
Set responseMemory = CreateObject("Scripting.Dictionary")
Set questionMemory = CreateObject("Scripting.Dictionary")
Set contextMemory = CreateObject("Scripting.Dictionary")
Set responseQuality = CreateObject("Scripting.Dictionary")
Set shortTermMemory = CreateObject("Scripting.Dictionary")
Set SubjectTable = CreateObject("Scripting.Dictionary")
Set spellDictionary = CreateObject("Scripting.Dictionary")
Set longTermIndex = CreateObject("Scripting.Dictionary")
Set knowledgeBase = CreateObject("Scripting.Dictionary")
If Err.Number = 0 Then
InitializeSubjectTable
LoadMemoryFromFile
LoadLongTermMemory
LoadSpellDictionary
LoadKnowledgeBase
lastSubject = "Questions"
lastTone = "Friendly"
End If
On Error GoTo 0
End Sub
Private Sub InitializeSubjectTable()
SubjectTable.Add "Animals", "dog:3 cat:3 bird:2 fish:2 zoo:3 wildlife:3 pet:4 fur:2 animal:4"
SubjectTable.Add "Books", "novel:3 read:3 author:3 library:2 story:3 page:2 chapter:2 book:4"
SubjectTable.Add "Computers", "code:4 program:3 software:3 hardware:3 ai:4 data:3 network:2 computer:4"
SubjectTable.Add "Dreams", "sleep:3 night:2 vision:3 dream:4 imagination:3 subconscious:3"
SubjectTable.Add "Education", "school:4 learn:3 teacher:3 study:3 exam:2 knowledge:3 class:2 education:4"
SubjectTable.Add "Food", "eat:3 cook:3 recipe:3 meal:3 taste:2 restaurant:2 chef:2 food:4"
SubjectTable.Add "Games", "play:3 video:3 board:2 strategy:3 fun:2 challenge:2 puzzle:2 game:4"
SubjectTable.Add "Health", "doctor:3 medicine:3 fitness:3 sick:2 exercise:3 wellness:2 diet:3 health:4"
SubjectTable.Add "Internet", "web:3 online:3 site:2 browse:2 connect:2 network:3 social:2 internet:4"
SubjectTable.Add "Jobs", "work:4 career:3 employ:3 office:2 task:2 salary:2 boss:2 job:4"
SubjectTable.Add "Knowledge", "fact:3 info:3 learn:3 understand:3 think:2 idea:3 wisdom:2 knowledge:4"
SubjectTable.Add "Love", "romance:3 heart:3 date:2 partner:3 affection:3 relationship:4 kiss:2 love:4"
SubjectTable.Add "Music", "song:3 sing:3 band:3 play:2 tune:2 rhythm:3 melody:3 music:4"
SubjectTable.Add "Nature", "tree:3 forest:3 river:2 mountain:3 sky:2 earth:3 plant:2 nature:4"
SubjectTable.Add "Opinions", "think:3 believe:3 view:3 argue:2 discuss:3 opinion:4 idea:2"
SubjectTable.Add "People", "friend:3 family:4 person:3 group:2 society:2 talk:2 human:3 people:4"
SubjectTable.Add "Questions", "ask:4 why:3 how:3 what:3 where:3 question:4 curious:2"
SubjectTable.Add "Religion", "god:4 faith:3 pray:3 belief:3 spirit:3 church:2 soul:3 religion:4"
SubjectTable.Add "Science", "test:3 theory:3 lab:3 experiment:3 research:4 discover:3 fact:2 science:4"
SubjectTable.Add "Technology", "machine:3 tech:4 device:3 gadget:2 innovate:3 tool:2 robot:3 technology:4"
SubjectTable.Add "Universe", "star:3 planet:3 space:4 galaxy:3 cosmic:3 moon:2 orbit:2 universe:4"
SubjectTable.Add "Vehicles", "car:3 drive:3 truck:2 plane:3 fly:3 travel:2 boat:2 vehicle:4"
SubjectTable.Add "Weather", "rain:3 sun:3 snow:3 wind:2 cloud:2 storm:3 forecast:2 weather:4"
SubjectTable.Add "Xtra", "extra:3 bonus:2 special:3 unique:3 odd:2 random:2 quirky:2"
SubjectTable.Add "Youth", "young:3 kid:3 child:3 teen:3 grow:2 play:2 school:3 youth:4"
SubjectTable.Add "Zen", "calm:3 peace:4 meditate:3 relax:3 quiet:2 balance:3 harmony:3 zen:4"
End Sub
Private Sub LoadMemoryFromFile()
On Error Resume Next
Dim objFSO, file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim path
path = BASE_PATH & MEMORY_FILE
If objFSO.FileExists(path) Then
Set file = objFSO.OpenTextFile(path, 1)
Do While Not file.AtEndOfStream
Dim line
line = file.ReadLine
Dim parts
parts = Split(line, vbTab)
If UBound(parts) = 2 Then
responseMemory.Add parts(0), parts(1)
questionMemory.Add parts(0), parts(2)
End If
Loop
file.Close
End If
On Error GoTo 0
End Sub
Private Sub LoadLongTermMemory()
On Error Resume Next
Dim objFSO, file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim path
path = BASE_PATH & LONG_TERM_FILE
If objFSO.FileExists(path) Then
Set file = objFSO.OpenTextFile(path, 1)
Do While Not file.AtEndOfStream
Dim line
line = file.ReadLine
Dim parts
parts = Split(line, vbTab)
If UBound(parts) >= 2 Then
longTermIndex.Add parts(0), Array(parts(1), parts(2), parts(3))
End If
Loop
file.Close
End If
On Error GoTo 0
End Sub
Private Sub LoadSpellDictionary()
On Error Resume Next
Dim objFSO, file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim path
path = BASE_PATH & SPELL_DICT_FILE
If Not objFSO.FileExists(path) Then
Set file = objFSO.CreateTextFile(path, True)
file.WriteLine "the,be,to,of,and,a,in,that,have,i,it,for,not,on,with,he,as,you,do,at,this,but,his,by,from,they,weather,technology,personal,dog,cat,bird,book,code,school,ai,learn,knowledge"
file.Close
End If
Set file = objFSO.OpenTextFile(path, 1)
Do While Not file.AtEndOfStream
Dim line
line = file.ReadLine
Dim words
words = Split(line, ",")
Dim i
For i = 0 To UBound(words)
spellDictionary.Add LCase(Trim(words(i))), True
Next
Loop
file.Close
On Error GoTo 0
End Sub
Private Sub LoadKnowledgeBase()
On Error Resume Next
Dim objFSO, folder, file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim knowledgePath
knowledgePath = BASE_PATH & KNOWLEDGE_FILE
If objFSO.FileExists(knowledgePath) Then
Set file = objFSO.OpenTextFile(knowledgePath, 1)
Do While Not file.AtEndOfStream
Dim line
line = file.ReadLine
If InStr(line, "key") = 0 Then
Dim parts
parts = Split(line, vbTab)
If UBound(parts) = 2 Then knowledgeBase.Add parts(0), Array(parts(1), parts(2))
End If
Loop
file.Close
End If
If objFSO.FolderExists(BASE_PATH) Then
Set folder = objFSO.GetFolder(BASE_PATH)
For Each file In folder.Files
If LCase(objFSO.GetExtensionName(file.Name)) = "txt" And file.Name <> MEMORY_FILE And file.Name <> LONG_TERM_FILE And file.Name <> LONG_TERM_INDEX_FILE And file.Name <> LOG_FILE And file.Name <> SPELL_DICT_FILE And file.Name <> KNOWLEDGE_FILE Then
LearnFromFile file.Path
End If
Next
End If
SaveKnowledgeBase
On Error GoTo 0
End Sub
Private Sub LearnFromFile(filePath)
On Error Resume Next
Dim objFSO, file
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(filePath) Then
Set file = objFSO.OpenTextFile(filePath, 1)
Dim content, subject
content = ""
Do While Not file.AtEndOfStream
content = content & file.ReadLine & " "
Loop
file.Close
subject = DetectFileSubject(content)
Dim key
key = GenerateKey(objFSO.GetBaseName(filePath), subject)
If Not knowledgeBase.Exists(key) Then knowledgeBase.Add key, Array(content, subject)
End If
On Error GoTo 0
End Sub