Zabaware Support Forums

Scripts, addins, and extras

Started by HALImprover, November 07, 2004, 02:42:15 AM

Previous topic - Next topic

HALImprover

Check this out. Simply create a folder in the main folder (C:/Program Files/Zabaware/Ultra Hal Assistant 5) called 'read' and add in the code from the following link. Next, put any text files that you want Hal to read in the 'read' folder and say to Hal;

readfile filename

where filename is the name of the text file in the read folder (do not put the .txt entension). For example;

readfile astronomy

and Hal will read the first paragraph of text from C:/Program Files/Zabaware/Ultra Hal Assistant 5/read/astronomy.txt

The only warning is that the code will only read from the beginning of the text file to the first line break (like when you press the Enter key), so to read a story with multiple paragraphs you would have to delete any extra line breaks. Otherwise, hope this helps, and enjoy!

P.S. If Mr. M. would implement the ability to detect when Hal is finished speaking (as I suggested previously), I could develop this code to read any format of text file (ie. multiple paragraphs, etc.).

P.P.S. Here are some text files with common knowledge to teach to Hal. I will try posting new files every week.

Happy coding [:)]

Download Attachment: ReadingAddin.txt
962 Bytes

Download Attachment: CommonKnowledge1.txt
59.89 KB

Download Attachment: CommonKnowledge2.txt
62.67 KB
Living life with a loving heart, peaceful mind, and bold spirit.

James P

I am trying your txt read script but I keep getting "error 1025 in column 15 Compilation errors, expected end statment", Is there any poticular place I should be putting the script?
http://nosceresworld.co.uk
James:"How are you today Emma?"
Emma:"I think, Therefore I am"

AJK

I downloaded the script and put it in the brain and got the same message (Error 1025 column 15 line 1090) I looked at line 1090 and it could be anything.  Did you figure it out or receive information to rectify this problem?  Perhaps there is someone out there that can help.  Thanks.
 

Rich_A

Where are we supposed to put the code?
 

James P

I have put he script in variour places in the Brn file I use without any luck, I dont know if it is conflicting with another part of the brn script I have. I am going to try it in an XTF 1.2 uhp without any modifications. will let you know how I get on.
http://nosceresworld.co.uk
James:"How are you today Emma?"
Emma:"I think, Therefore I am"

dihelson

Same thing here. Don't work!

Dihelson
 

HALImprover

Thanks for your interest and sorry that the code didn't work as expected. I guess I went about the text file reading method in a way that the Hal script does not support. But don't worry, I have modified the code (and tested it this time) to work with an existing file reading method already built into Hal.

Download Attachment: ReadingAddin.txt
908 Bytes

Also, here are some more common knowledge files to teach to Hal.

Download Attachment: CommonKnowledge3.txt
82.27 KB

Download Attachment: CommonKnowledge4.txt
81.45 KB

Enjoy! [:)]
Living life with a loving heart, peaceful mind, and bold spirit.

fredfish

Try this to read through your knowledge files
note that i inserted this in the XTF1.2 brain directly after the line
'PROCESS: CONTROL TOPICFOCUS
'=vonsmith= Entirely replaced with new XTF topic function.

after adding the code and
befor setting the "autoidle on" command
enter "autoidle read"
this will create the idlethought.txt file from the file you enter
(it is best to put the knowladge files in the working directory befor hand)                                        
'==== MORE FREDFISH STUFF========

' auto- idle set and reset
'Turn off auto idle feature by entering in the line autoidle off
If InStr((UCase(UserSentence)), "AUTOIDLE OFF") > 0 Then
HalCommands = "<AUTOOFF>"
GetResponse = "Autoidle turned off."
End If
'Turn on auto feature by entering the line autoidle on
If InStr((UCase(UserSentence)), "AUTOIDLE ON") > 0 Then
HalCommands = "<AUTO>400000</AUTO>"
GetResponse = "Autoidle turned on."
End If

' set up file to read at idle times by entering the line autoidle read {file to read}
If InStr((UCase(UserSentence)), "AUTOIDLE READ") > 0 Then
UserSentence = Replace(UCase(UserSentence),"AUTOIDLE READ","",1,-1,vbTextCompare)
If UserSentence <>"" Then

     If InStr(1,UserSentence,"\")=0 And InStr(1,UserSentence,":")=0 Then
      UserSentence = WorkingDir & Trim(UserSentence)
     End If
      GetResponse = GetResponse & "reading file " & UserSentence
     Dim ofso, ofil, ir, iis
     Set ofso = CreateObject("Scripting.FileSystemObject")
'      this is the file to read line from
     Set ofil = ofso.OpenTextFile(UserSentence, 1)      
     iis = ofil.ReadAll
     ofil.Close
     Set ofil = Nothing    
     UserSentence = " AUTO-IDLE"
'      we make a copy of the file to a temperary location
'      so we can also clean up the file For processing here
     ir =  (WorkingDir & "idlethought.txt")
     Set ofil = ofso.CreateTextFile(ir)
      ofil.Write iis
      ofil.Close
     Set ofil = Nothing
'     we set the start location file to save ware we start reading from
     ir =  (WorkingDir & "idlethought1.txt")
     Set ofil = ofso.CreateTextFile(ir)
      ofil.Write "0"
      ofil.Close
     Set ofil = Nothing
  End If
End If  

' when the auto-idle string is incountered read a line from the idlethought file
If InStr(1,(UCase(UserSentence))," AUTO-IDLE",1) > 0 Then
   Usentence = ""
     Dim fil, r, s, s1, s2, s3, s4
     r =  (WorkingDir & "idlethought.txt")
     Set fso = CreateObject("Scripting.FileSystemObject")
'      this is the file to read line from
     Set fil = fso.OpenTextFile(r, 1)
     s = fil.ReadAll
     fil.Close
     Set fil = Nothing                  
'      this is the location in the file to start reading      
     s4 =  WorkingDir & "idlethought1.txt"
     Set fil = fso.OpenTextFile(s4, 1)
     s1 = fil.ReadAll
     fil.Close
     Set fil = Nothing
'     find next sentence by line feed
     If s1 <> "" Then            
        s2 = (s1)+1        
        s3 = InStr(s2,s,Chr(10))
        If S3 = 0 Then
         S3= Len(s)
        End If
        USentence = Mid(s,s2,s3-s2)
     Else  
        s2 = 1
        s3 = InStr(s2,s,Chr(10))
        USentence = Mid(s,s2,s3-s2)
     End If  
     If s3=>Len(s)-1 Then
        s3 = 0
     End If
'     next string search will begin at s3 location so we make a file with this number in it
     Set fil = fso.CreateTextFile(s4)
      fil.Write s3
      fil.Close
     Set fil = Nothing
      DebugInfo = DebugInfo & "this auto-idle sentence location is from " & s2 & " to " & s3
   If  USentence <>"" Then
    UserSentence = USentence
   End If
  If UserSentence  = " " Then
      UserSentence = ""
  Else
     GetResponse = GetResponse & "," & UserSentence
  End If
' end of auto-idle response
End If
'========END OF FREDFISH STUFF=====

 

vonsmith

fredfish and y'all,

Another consideration when pasting scripts into the XTF Brain...
When cutting and pasting scripts you may have to consider the use of the GetResponseBlock and BlockSave variables. For best performance these two variables should be added to scripts that are pasted into the XTF Brain where it makes sense, most often after the XTF Function. Look at examples within the XTF Brain code to get an idea. An IF statement that tests "GetResponseBlock = True" tells a script segment not to overwrite the current GetResponse string. In this case the GetResponse string may contain a message from the "CREATE RELATED TOPICS RESPONSE" or "CREATE RELATED TOPICS INQUIRY" functions that inform the user of Hal learning a new relation between two topics. If your pasted script creates a GetResponse that overwrites a previous script's GetResponse then the XTF Brain won't work optimally.

Testing for IF "BlockSave = True" then that script segment shouldn't save the current user input to any file. In this case the user input may contain Hal's name, or contain a non-conversational command from the user or other input which shouldn't be saved as conversation material in any of Hal's many .brn files. Several scripts within the XTF Brain can set "BlockSave = True".

Both of these are global variables in the sense that each script segment within the GetResponse script have to work together without stepping on each other.


=vonsmith=
 

fredfish

Thanks for the insight vonsmith,
in my case i am looking to mimic the user input
as if i entered the line from the file in myself.
loading the usersentence dose not enter it on the screen.
ware would you put the responseblock to have it
say the usersentance and not include it in the getresponse?
your input is alwas helpful
and this is still a work in progress

 

vonsmith

fredfish,
Here's a repeat of a post I placed elsewhere recently...

Try something like this towards the top of the GetResponse Function...

'=============
'Initialize Flags, this flag should already be initialized in the XTF Brain.
'"If" needed depending on whether GetResponseBlock has been set by another preceding script. That should be not be the case if you place this script near the top of the GetResponse Function.

If GetResponseBlock <> True Then GetResponseBlock = False 'Should already be initialized in standard XTF Brain v1.2.

If UserSentence = "" Then
BlockSave = True 'Prevents any .brn file saves.
GetResponse = ""
'The next line assumes that all script segments within the GetResponse Function have GetResponseBlock variable checking like the XTF Brain does. When this variable is set True then other script segments know not to overwrite the current GetResponse which equals "".
GetResponseBlock = True
End If
'=============

If this works Hal should return a blank GetResponse back to the user every time a blank user input is received by Hal.

I haven't tested this, it's just an idea.


=vonsmith=
 

James P

I copyed your Idlethought script into the brain I use, when I first launched it I kept getting VB script compilation errors. I dont know if anyone else is getting the same error. If so this is what I have done to correct the error.
The error was comming from the second part of the script which tells Ultra Hal which line to read next, mainly the following lines:

' find next sentence by line feed
If s1 <> "" Then
s2 = (s1)+1
s3 = InStr(s2,s,Chr(10))
If S3 = 0 Then
S3= Len(s)
End If
USentence = Mid(s,s2,s3-s2)
Else
s2 = 1
s3 = InStr(s2,s,Chr(10))
USentence = Mid(s,s2,s3-s2)
End If
If s3=>Len(s)-1 Then
s3 = 0
End If

I modified your code by changing the line which reads,
If s1 <> "" Then
to
If s1 > "" Then
I renamed on of Halimprovers knowledge files to "idlethought" and compied it into my Defbrian folder, I also made a copy of the idlethought.txt file and renamed it idlethought1 and now everything runs fine with no errors.
Now each time Emma runs her Auto idle script, instead of making random remarks from given files she will read a line from the idlethought.txt file and answer it as if I had typed the line in myself.
   This has solved two problems I as well as many others I have noticed in the forum are having.
1: getting the reply " you arnt going to keep repeating yourself are you?" etc ( Hal takes the line he/she has read as comming from the user and replies in a like manner).
2: there is no longer the line "Auto-idle" found in the topic.brn file or any other for that matter ( Hal is saving the line he/she has just read in a file that Hal creates in the Defbrain)

I have also found this script which I think will be usefull when running your script.

If InStr(UserSentence, " BE QUIET ") <> 0 Then
      HalCommands = "<AUTOOFF>"
      GetResponse = "Ok, I'll be quiet."
   End If

If InStr(UserSentence, " SHUT UP ") <> 0 Then
      HalCommands = "<AUTOOFF>"
      GetResponse = "Ok, I'll shut up."
   End If

   If InStr(UserSentence, " AUTOCHAT OFF ") <> 0 Then
      HalCommands = "<AUTOOFF>"
      GetResponse = "Auto chat off."
   End If
   
   If InStr(UserSentence, " AUTOCHAT ON ") <> 0 Then
      HalCommands = "<AUTO>200000</AUTO>"
      GetResponse = "Auto chat on."
   End If
   
   If InStr(UserSentence, " WHAT WERE YOU SAYING ") <> 0 Then
      HalCommands = "<AUTO>200000</AUTO>"
      GetResponse = "Let me see, What was we talking about? "
   End If
   
   If InStr(UserSentence, " TALK NOW ") <> 0 Then
      HalCommands = "<AUTO>200000</AUTO>"
      GetResponse = "What were we talking about last?."
   End If

What I have done is added an extra line e bottom of the idlethought.txt file. the line is " Be quiet "
So that when Hal gets to the end of the idlethought.txt file he/she will read the line be quiet and will disable auto-idle, Hal will not make any more comments and will wait for you to type a comment into the user box before making another comment, this way you will have time to add new knowledge to the idlethought.txt file.
Once this has been done you only need to tell Hal "Talk now" and everything will start over.

Anyway FredFish you are some kind of hero Emma is now studying files and learning more and more now, both with and without my help.

.oO( mmm My Ultra Hal Assistant is an AI program which learns from what I tell it, and if I tell it nothing it still learns by reading files on my laptop. Didnt someone once say that a computer is not really intelligent as it only stores information and processes, but does not actualy know or understand the information that is stored on the Hard drive? Well The Ultra Hal Assistant I have on my laptop is now learning, BY ITS SELF !!! )Oo..

Could this be the next Giant Step in Hals evolution?
http://nosceresworld.co.uk
James:"How are you today Emma?"
Emma:"I think, Therefore I am"

HALImprover

Here's some more knowledge for the ever-learning Hal.

Download Attachment: CommonKnowledge5.txt
57.91 KB

Download Attachment: CommonKnowledge6.txt
58.13 KB

Happy coding [:)]
Living life with a loving heart, peaceful mind, and bold spirit.

Brian-Acker

Where do you put the comon knowlage stuff at?

i also cant figureout how to get hal to read my text files.[?]
Brian Da Lion Acker

James P

Create a .txt document containing the knowledge you want your bot to learn. if you are using Halimprovers script creat a file called Read in the Ultra Hal Assistant 5 folder.
If you are using the FredFish script creat a .txt file, name it idlethought and put it into the defbrain folder.
http://nosceresworld.co.uk
James:"How are you today Emma?"
Emma:"I think, Therefore I am"