Change font size
It is currently Fri Aug 17, 2018 7:45 am

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 6 posts ]
Author Message
 Post subject: AIML Chatterbot script
PostPosted: Mon Sep 05, 2011 6:20 pm 
OSG Elite
User avatar

Joined: Thu Dec 11, 2008 7:51 am
Posts: 392
Location: England UK
Below is a chatterbot script that would work nicely with NPCs. The original script was given to me by Juicy Babii but unfortunatly didn't work properly. I kind of got it running then with the help of Roken Price fixing a major part of the script I cleaned it up and polished it a little. It is now a fairly decent bot using AIML from the A.L.I.C.E AI Foundation (see http://www.pandorabots.com).

If you do use this script in anything other than quick testing then please do register your own bot at the link above, where you will be able to train and administer it yourself.

Simply drop the script into a prim and start talking to it! :-)

NOTE: For it to work with an NPC it will require extra code. This is simply a standalone chatterbot. Attaching this to an NPC as is will result in the NPC/chatterbot talking to itself and is prohibited under the Pandorabot terms of use.

{L_CODE}:
//Chatterbot script using the Pandorabot by A.L.I.C.E. AI Foundation.
//Original script by Juicy Babii, fixed and polished by Adelle Fitzgerald with help from Roken Price by fixing up the str_replace :-)
//If you intend to use this script for anything other than a quick test then please register your own bot at www.pandorabots.com where you will be able to train it and manage it.


key requestId;
integer listening;
string custid;
string message;
string botId="f0487cf9de347543"; //Your registered bot ID (see www.pandorabots.com)
string botURL="http://www.pandorabots.com/pandora/talk-xml";

string str_replace(string src, string from, string to)  //replaces all occurrences of 'from' with 'to' in 'src'.
{
    integer len = (~-(llStringLength(from)));
    if(~len)
    {
        string  buffer = src;
        integer b_pos = -1;
        integer to_len = (~-(llStringLength(to)));
        @loop;
        integer to_pos = ~llSubStringIndex(buffer, from);
        if(to_pos)
        {
            b_pos -= to_pos;
            src = llInsertString(llDeleteSubString(src, b_pos, b_pos + len), b_pos, to);
            b_pos += to_len;
            buffer = llGetSubString(src, (-~(b_pos)), 0x8000);
            jump loop;
        }
    }
    return src;

   
default
{
   state_entry()
   {
        listening = llListen( 0, "", NULL_KEY, "" );
        custid = "";
   }

   touch_start(integer total_number)
   {
        llWhisper(0, "Talk to me in Local Chat.");
   }

   listen(integer channel, string name, key id, string msg)
   {
        custid=name;
        llListenRemove(listening);
        llSetTimerEvent(2.0); //Increase this timer if you experience errors.
        message = msg;
   }
   

   
   timer()
   {
        requestId = llHTTPRequest(botURL,[HTTP_METHOD,"POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], "input=" + message + "&botid=" + botId + "&custid=" + custid);
        llSetTimerEvent(0.0);
        listening=llListen( 0, "", NULL_KEY, "" );
    }

    http_response(key request_id, integer status, list metadata, string body)
    {
       if (request_id == requestId)
       {
           if(body == "error")
           {
                llWhisper(0, "An error occurred. Please try again later");
           }
           else
           {
                integer start = llSubStringIndex(body, "<that>");
                integer end   = llSubStringIndex(body, "</that>");
                list lines;
                if (start != -1 && end != -1)
                {
                    string msglines = llGetSubString(body, start+6, end-1);
                    msglines = str_replace(msglines, "&quot;","'");
                    msglines = str_replace(msglines, "&amp;lt;","<");
                    msglines = str_replace(msglines, "&amp;gt;",">");
                    msglines = str_replace(msglines, ", .",".");
                    lines = llParseString2List(msglines, ["&lt;br&gt; ", "&lt;br&gt;"],[""]);
                    integer i;
                    string output;
                    for (i = 0; i < llGetListLength(lines); i++)
                    {
                        output += llList2String(lines, i);
                        if (i < llGetListLength(lines) - 1) output = output + "\n";
                    }
                    llSay(0,output);
                }
            }
        }
        else
        {
            llWhisper(0, "An error occurred. Please try again later");
        }
    }     
}

_________________
"Nothing lasts forever; It's scientific"
~David Byrne (Talking Heads)


Top
 Profile  
 
 Post subject: Re: AIML Chatterbot script
PostPosted: Tue Sep 06, 2011 3:13 pm 
OSG Elite
User avatar

Joined: Thu Dec 11, 2008 7:51 am
Posts: 392
Location: England UK
I have created an NPC specific chatterbot script based on the script above.

**** Please note that you have to enable Allow_osNpcSay = true in your opensim.ini. Do this at your own risk as it opens up the potential for other users to abuse your NPC's chat! ****

Usage:
Configure Allow_osNpcSay = true in your opensim.ini. (see note above)
Drop the script into a prim and wear the prim. This is needed so your NPC will wear this prim when you create it's appearance.
Create your NPC using your current appearance.
Talk to your NPC!

As noted above in the previous post, if you use this for anything more than just a quick test, please create your own pandorabot account.

Have fun!

{L_CODE}:
//NPC Chatterbot script using the Pandorabot by A.L.I.C.E. AI Foundation.
//Original script by Juicy Babii, fixed and polished by Adelle Fitzgerald with help from Roken Price by fixing up the str_replace :-)
//If you intend to use this script for anything other than a quick test then please register your own bot at www.pandorabots.com where you will be able to train it and manage it.

//This script is specifically for use with an NPC. When you create your NPC appearance make sure you are wearing this prim, so the NPC also wears it.

//!!!!!! Please also note that you Have to enable 'Allow_osNpcSay = true' in your opensim.ini. Do this at your own risk as it does open up the potential for other users to abuse your NPC's chat. !!!!!!!

key owner;
key requestId;
integer listening;
string custid;
string message;
string botId="f0487cf9de347543"; //Your registered bot ID (see www.pandorabots.com)
string botURL="http://www.pandorabots.com/pandora/talk-xml";

string str_replace(string src, string from, string to)  //replaces all occurrences of 'from' with 'to' in 'src'.
{
    integer len = (~-(llStringLength(from)));
    if(~len)
    {
        string  buffer = src;
        integer b_pos = -1;
        integer to_len = (~-(llStringLength(to)));
        @loop;
        integer to_pos = ~llSubStringIndex(buffer, from);
        if(to_pos)
        {
            b_pos -= to_pos;
            src = llInsertString(llDeleteSubString(src, b_pos, b_pos + len), b_pos, to);
            b_pos += to_len;
            buffer = llGetSubString(src, (-~(b_pos)), 0x8000);
            jump loop;
        }
    }
    return src;
}
   
default
{
   state_entry()
   {
       owner = llGetOwner();
        listening = llListen( 0, "", NULL_KEY, "" );
        custid = "";
   }

   touch_start(integer total_number)
   {
        llWhisper(0, "Talk to me in Local Chat.");
   }

   listen(integer channel, string name, key id, string msg)
   {
       if (id != owner) //We don't want the NPC to talk to itself!
       {
            custid=name;
            llListenRemove(listening);
            llSetTimerEvent(2.0); //Increase this timer if you experience errors.
            message = msg;
        }
   }
   

   
   timer()
   {
        requestId = llHTTPRequest(botURL,[HTTP_METHOD,"POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], "input=" + message + "&botid=" + botId + "&custid=" + custid);
        llSetTimerEvent(0.0);
        listening=llListen( 0, "", NULL_KEY, "" );
    }

    http_response(key request_id, integer status, list metadata, string body)
    {
       if (request_id == requestId)
       {
           if(body == "error")
           {
                llWhisper(0, "An error occurred. Please try again later");
           }
           else
           {
                integer start = llSubStringIndex(body, "<that>");
                integer end   = llSubStringIndex(body, "</that>");
                list lines;
                if (start != -1 && end != -1)
                {
                    string msglines = llGetSubString(body, start+6, end-1);
                    msglines = str_replace(msglines, "&quot;","'");
                    msglines = str_replace(msglines, "&amp;lt;","<");
                    msglines = str_replace(msglines, "&amp;gt;",">");
                    msglines = str_replace(msglines, ", .",".");
                    lines = llParseString2List(msglines, ["&lt;br&gt; ", "&lt;br&gt;"],[""]);
                    integer i;
                    string output;
                    for (i = 0; i < llGetListLength(lines); i++)
                    {
                        output += llList2String(lines, i);
                        if (i < llGetListLength(lines) - 1) output = output + "\n";
                    }
                    osNpcSay(owner, output);
                }
            }
        }
        else
        {
            llWhisper(0, "An error occurred. Please try again later");
        }
    }
   
    on_rez(integer start_param)
    {
        llResetScript();
    }
}

_________________
"Nothing lasts forever; It's scientific"
~David Byrne (Talking Heads)


Top
 Profile  
 
 Post subject: Re: AIML Chatterbot script
PostPosted: Sun Aug 12, 2012 12:05 am 

Joined: Sun Aug 12, 2012 12:03 am
Posts: 1
Great Job.

I've been looking hours and hours to fin this very easy to use script.

THANK YOU!


Top
 Profile  
 
 Post subject: Re: AIML Chatterbot script
PostPosted: Sun May 04, 2014 12:02 pm 

Joined: Fri Mar 28, 2014 5:48 am
Posts: 10
Hello, I have tried to use these script but they don't work for me.
I use many NPC's, but the obj with the script inside just tell "talk to me in local chat".
I talk to it in local chat, but no answer. :?
Any idea, where I wrong?
tnx. Nadine


Top
 Profile  
 
 Post subject: Re: AIML Chatterbot script
PostPosted: Mon May 05, 2014 6:23 am 
Site Admin

Joined: Sun Jul 04, 2010 8:20 pm
Posts: 474
Nadine, It appears that the botId that is used in the script is no longer valid. You will have to sign up at http://www.pandorabots.com and create a bot, publish it and use your own botid in the script.

Also, you will need to make sure you set the ExternalHostNameForLSL (in [Network] section) to the correct IP or domain name for your simulator and add the Allow_osNpcSay = true (in the [XEngine] section) in your OpenSim.ini

dan


Top
 Profile  
 
 Post subject: Re: AIML Chatterbot script
PostPosted: Thu May 08, 2014 11:41 am 

Joined: Fri Mar 28, 2014 5:48 am
Posts: 10
Thank you Dan! ;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 6 posts ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net