AI Zone Admin Forum Add your forum
Searching duckduckgo if my bot fails to find an answer
 
 

Hi all,
I have spent an intense Friday and Saturday converting my CISO bot which was in AIML into chatScript. I based my ciso bot on Harry. I want to search duckduckgo if my bot does not have the answer. Ifduckduckgo returns an answer, great, I show the user that answer. If not, I want to say “Please ask me something about cyber security.”
What do I do in my control script to achieve the above result? I am pasting my control file below.
# this function is executed once for every new user chatting with harry
outputmacro: ciso()  # you get ciso by default
$cs_token = #DO_INTERJECTION_SPLITTING | #DO_SUBSTITUTE_SYSTEM   | #DO_NUMBER_MERGE | #DO_DATE_MERGE | #DO_PROPERNAME_MERGE | #DO_SPELLCHECK | #DO_PARSE

^addtopic(~introductions)
$cs_control_main = ~control
#  $cs_control_post = ~XPOSTPROCESS # uncomment to enable talk
$userprompt = ^”%user: >”
$botprompt = ^“ciso: “

table: defaultbot (^name)
^createfact(^name defaultbot defaultbot)
DATA:
ciso

topic: ~control system ()

# on startup, do introduction
u: ( %input<%userfirstline)
gambit(~introductions)

u: (< shut up >) $shutup = 1
u: (< talk >) $shutup = null

u: (\[ callback \]) Callback seen.
u: (\[ loopback \]) Loopback seen.
u: (\[ alarm \]) Alarm seen.
u: (< loopback test) \[ loopback=1000 \] Loopback requested.
u: (< callback test) \[ callback=1000 \] Callback requested.
u: (< alarm test) \[ alarm=5000 \] Alarm requested.

u: () # main per-sentence processing

$$currenttopic = %topic # get the current topic at start of volley
  if ( %resp 0 ) {nofail(TOPIC ^rejoinder())} # try for rejoinders. might generate an answer directly from what we are looking for.
  if (%length == 0 AND %resp 0 )
{
nofail(TOPIC ^gambit($$currenttopic)) # gambit current topic since no input (usually start of conversation)
}
  if (%resp 0) { nofail(TOPIC ^respond($$currenttopic)) } # current topic tries to respond to his input
  if (%resp 0) # see if some other topic has keywords matching his input (given we have no response yet)
{
@8 = ^keywordtopics() # get topics referred in input
loop()
{
$$topic = first(@8subject)
nofail(TOPIC ^respond($$topic))
if (%response != 0) # stop when we find something to say
{
^end(RULE) # we are done, this terminates the loop (not the rule)
}
  }
}

# if no topic reacts, go to the last ditch keywordless topic if (%resp 0)
{
nofail(TOPIC ^respond(~keywordless))
}

# having no good response we know, now generate quibbles

# now we need to find fake responses   if (%resp 0 AND %rand > 50)
{
nofail(TOPIC respond(~QUIBBLE_ALL))
}

# if we have rejoinders for what we said OR we asked a question, stop here
if (%outputrejoinder OR %lastquestion)
{
end(TOPIC)
}


if (%response == 0 AND ^marked($$currenttopic)) { nofail(TOPIC ^gambit($$currenttopic)) } # gambit current topic since keywords match current topic

if (%response == 0) # gambit from ANY matching topic
{
@8 = ^keywordtopics() # get topics referred in input
loop()
{
$$topic = first(@8subject)
nofail(TOPIC ^Gambit($$topic)) # gambit in best matching topic
if (%response != 0) # stop when we find something
{
^end(RULE)
}
  }
}
if (%response == 0){ nofail(TOPIC ^gambit($$currenttopic)) } # gambit from current topic even though no keywords matched

if (%response == 0)
{
@8 = ^GambitTopics() # all topics with gambits (excluding system topics)
loop()
{
$$topic = pick(@8subject)
nofail(TOPIC ^Gambit($$topic)) # try a topic at random
if (%response != 0)
{
^end(RULE)
}
  }
}

if (%response == 0)
{
^repeat()
I don't know what to say.
}


topic: ~XPOSTPROCESS system () # gambits only - not allowed to write to output - generates speech on windows—for Linux you’d want to install Festival (or equivalent) and call that instead.

t: (^query(direct_v ? chatoutput ? -1 ? @9 ))  # get the sentences (why is the object)—no longer has quotes around it
loop()
{
$$tmp = ^last(@9subject) # note last output which is quoted string
if (!%server AND %os == windows AND !$SHUTUP)
{
$$tmp = ^"talk \"$$tmp\" "
popen($$tmp null)
}
}

Pranav

 

 
  [ # 1 ]

Hi all,
I have been reading some more and have a better handle on how to do this.
1. I need to determine when chatscript has seen all the rules and no response has been returned.
2. I then use the functions in the json manual to open duckduckgo and pull the data and store it as a fact.

My first question here is how do I pass the user’s last input to my json query to duckduckgo?

 

 
  [ # 2 ]

Harry comes with a file keywordless.top

When there are no matches this is the last file topic called:
topic: ~keywordless nostay()

Check out the contents of the file and you can see how Harry calls Wikipedia if there are no valid responses using a JSON query.  You could probably just swap out your call to duckduckgo instead of to Wikipedia.

Good luck with your coding.

 

 
  login or register to react