AI Zone Admin Forum Add your forum

NEWS: survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

How to use program AB

Hi all,

I have downloaded program-ab-, so that I can make use of AIML 2.0 features.

I want to make a API call based on users input. Any guidance on how do i do it ?

I read about oob tags and sraix, there are some oob tag examples in aiml folder in program-ab-,  but when i run it to understand how it works, it just outputs the tag as a result

Ex: Human: what is the weather like?
Robot: I used my lifeline to ask another robot, but he didn’t know.
Perhaps we should try a web search.
<oob><search>what is the weather like</search></oob>

Please help me to know how do i call any API based on user input and give customized output to user based on API response



  [ # 1 ]

Hi, Amita.

I’m certainly no expert on Program AB, so my advice may or may not help, but I’m pretty sure that there is some configuring that will need to be done in order for the <sraix> tag to be able to work properly, as it calls a remote service, so has to “know” what that service is, and how to find and access it. the same thing goes for the <oob> tags, as well. I’m certain that (somewhere) some settings will need to be applied in order for Program AB to “understand” what to do when these tags are parsed. As to what that is, I have no clue at present. I’m still learning the ins and outs of Program AB, myself (though probably for a different reason). Steve may know, or perhaps Dr. Wallace may need to be contacted, to see if he can point you in the right direction. I’ll look into it when I get some time this weekend, but that’s all I can offer right now.


  [ # 2 ]

Yeah thanks for this guidance. For now I will put in efforts to use this approach of understanding.
Actually I need to deliver something end of this month which needs remote API call.
I hope Dr. Wallace or Steve will guide me too on this.


  [ # 3 ]

SRAIX is used to call another bot who can answer the question better. So for example in your weather question, you would sraix out to another bot who specialised in weather. Are you running your bot online or locally on your PC?

The oob tags are used for the device you are running the bot on, so for example, if you ran it on an Android phone, it would calls the phones search capabilities. You need to be running this on an actual device for this to work. It doesn’t work on a local PC.

I personally don’t use sraix and instead code my bot to handle any queries thrown at it rather than relying on other bots which may or may not be available when I need them. For “what is the weather”, I would pass the user’s location to something like:

pattern>SEARCH WEATHER *</pattern>
think><set name="weburl"><star/>/forecasts/latest</set></think>
I hope it's sunny in <star/> today.

This sets up a variable called weburl which I then display to the user using another category called XOPENWEBURL. To me this is easier than hoping the bot I SRAIXed to is online and working.


  [ # 4 ]

Thanks for the info Steve.

Weather example was just for me to understand how it works.

I actually want to call my own API.

Lets say I have exposed an API which and accepts score and outputs grade.
Ex: url = http://www.exampledomain/calcgrade?score=10

Consider if score entered by user is 10, grade is C
            score = 20, grade = B
            score = 30, grade = A
This is what the API does.

If reponse from API is A, I want my chatbot to repond “Excellent”
Similarly, repsonse = B, chatbot response = “You can improve”
          response = C, chatbot response = “Sorry you are not eligible”

I want to do something like mentioned in the above example.
My interpretation of features I should be using from AIML 2.0 are

local variables - New <var> attribute for variables scoped to a category to store users input
remote requests to make API call
condition statements for conditional response

I dont know how to make a API call. Is it possible at all with just program AB? Or do i need to write my own wrapper to call API and parse the response?



  [ # 5 ]

Accessing the API will depend greatly on a few factors. the first is knowing what the API “expects” to get in the way of data. this will vary, depending on the platform the API uses. If it’s web-based, it will be accessible from a URL, as in your example, so the only thing you need to work out is how to get Program AB to send the required data to the API’s URL. It’s entirely possible that this can be done via an <sraix> tag, but as I mentioned earlier, that’s probably going to take some configuration (and possibly re-coding) of Program AB in order to get it to do what you want. I’m still playing with other parts of Program AB, so I haven’t yet gotten into how it “knows” where/how to access “another bot”. I may have time to do so on Sunday (I work each day till then), but that’s a ways off.


  [ # 6 ]

Okay thanks Dave. I will try to figure that out too.

Another doubt is can I make this chatbot using program-ab work like a API like the way its possible in program-O(like it gives Json response) ?

Because I don’t want to run it on the device directly.


  [ # 7 ]

Unless you use some sort of server interface for Program AB (I know it’s possible, but again, I have no clue how), getting Program AB to work as an API itself would prove difficult. I’m not sure if you’re aware, but I’m the lead developer for Program O, and I’ve been working on a new version for it quite actively to not only allow for AIML 2.0 support, but also to improve performance and streamline the code. I’m still a very long way off, but I’m making better progress in the past month than I have the past 3 years, so things are looking up! One of the things I’m doing is working closely with a friend of mine who is both a Java programmer and a web developer, and we’re working on porting some of the Java code from Program AB into PHP, in order to take advantage of the Graphmaster algorithms that Program AB uses, and the early results are very promising. there are still some performance/memory issues to deal with, but once those are out of the way, I should have something to show.


  [ # 8 ]

Wow that’s interesting smile

And yes my gut feeling also says getting Program AB to work as an API itself would be difficult. smile

I will wait for program O to come with AIML 2.0 spec. Till then will find a hack to get things working. If not anything, a nodejs wrapper to call APIs and parse the response like the way I want.


  [ # 9 ]

I’m not certain if waiting for the next version will be a good idea, really. Bear in mind that I started on version 3 back in 2011, but a motorcycle accident in 2012 forced me to stop working on it for several years. I only just got back to it a month ago, and it’s like having to start from scratch. there won’t be a single bit of code in version 3 that is originally in the current version, so this is going to take me a while to complete. I WILL get it done, but it’s going to take some time.


  [ # 10 ]

Sure Dave I did not mean that i will rely the next version smile I know it will take time. smile


  [ # 11 ]

You don’t need the extra overhead of an API call to perform the function you are after (or even AIML 2.0). Here is some AIML that will do what you ask:

pattern>CALCGRADE *</pattern>
think><set name="inp"><star/></set></think>
condition name="inp">
li value="30">
think><set name="grade">A</set></think>
li value="20">
think><set name="grade">B</set></think>
You can improve.
li value="10">
think><set name="grade">C</set></think>
Sorry you are not eligible.
li>That was not a valid score.</li>

You call it by saying CALCGRADE x. Where x is the score you are evaluating. It will set the grade to A, B or C and provide the responses. It also has a catchall in case the input is not 10,20 or 30. A sample conversation:

Human: calcgrade 10
Bot: Sorry you are not eligible.
Human: calcgrade 20
Bot: You can improve.
Human: calcgrade 30
Bot: Excellent.
Human: calcgrade 24
Bot: That was not a valid score.

Any questions, let me know.


  [ # 12 ]

Thanks Steve.

The grade thing is just an example.

There are some APIs which are already developed (like API to place an order for food). I need to call those APIs based on user input.

Human: order pizza
      Bot: Order placed successfully

Bot should call food ordering API, address will already be there, other parameters will be collected through chat.

I think it will be complex to handle requests and responses of various APIs in chatbot interpreter even if it supports API call.

And that’s when I thought of using a wrapper (probably nodejs) to handle API calls and their responses.

Like “order food”  is the input for chatbot, it can return a keyword something like call_order_food_api along with the parameters collected from the user to the wrapper. Then the wrapper will make necessary API call and return response to the user interface.



  [ # 13 ]

  Hai Sir i am new to Aiml and Bot technology, how do i call my own webservice through aiml and how to display response in chatbot please help me sir


  login or register to react