pythonaiml

how to get response in the form of img in python aiml


so I was trying to make a chatbot with https://github.com/paulovn/python-aiml

<?xml version="1.0" encoding="ISO-8859-1"?>
<aiml version="1.0">
<!-- -->
<!-- Free software (c) 2011 ALICE A.I. Foundation.   -->
<!-- This program is open source code released under -->
<!-- the terms of the GNU General Public License     -->
<!-- as published by the Free Software Foundation.   -->
<!-- Complies with AIML 1.0 Tag Set Specification -->
<!-- as adopted by the ALICE A.I. Foundation.  -->
<!-- Last modified 10/5/2011 -->
<!-- -->
<category><pattern>HAVE YOU READ THE COMMUNIST *</pattern>
<template>Yes, Marx had made some interesting observations.</template>
</category>
<category><pattern>WHAT IS A GOVERNMENT</pattern>
<template>Ideally it is a representative of the people.</template>
</category>
<category><pattern>WHAT IS GREENPEACE</pattern>
<template>Global organization promoting enviornmental activism.</template>
</category>
<category><pattern>WHAT IS THE GOVERNMENT</pattern>
<template><srai>WHAT IS GOVERNMENT </srai></template>
</category>
<category><pattern>WHAT IS CAPITALISM</pattern>
<template>The economic system in which all or most of the means of production and distribution, as land, factories, railroads, etc., are privately owned and operated for profit, originally under fully competitive conditions. It has been generally characterized by a tendency toward concentration of wealth, and, in its later phase, by the growth of great corporations, increased governmental control, etc.  Its is also known as the principles, methods, interests, power, influence, etc. of capitalists, especially of those with large holdings.</template>
</category>
<category><pattern>WHAT IS SOCIALISM</pattern>
<template><random>              <li>Communism from people who want to keep their Volvos.</li>               <li>Any of various theories or systems of the ownership and operation of the means of production and distribution by society or the community rather than by private individuals, with all members of society or the community sharing in the work and the products.</li>           </random></template>
</category>
<category><pattern>WHAT IS GOVERNMENT</pattern>
<template>An established system of political administration by which a nation, state, district, etc. is governed.</template>
</category>
<category><pattern>WHAT IS COMMUNISM</pattern>
<template>A sociopolitical movement advocating the common ownership of the means of production and the resolution of class conflict by bringing about a classless society. </template>
</category>
<category><pattern>WHAT IS IMPEACHED</pattern>
<template>When a person's honor or reputation has been challenged or discredited.</template>
</category>
<category><pattern>WHAT IS IMPEACHMENT</pattern>
<template>Charge against a public official of improper conduct.<think>              <set name="it">                     <set name="topic">IMPEACHMENT</set>                 </set>          </think></template>
</category>
<category><pattern>I DO NOT LIKE GUNS</pattern>
<template>That is perfectly understandable.</template>
</category>
<category><pattern>I DO NOT LIKE GUNS *</pattern>
<template>What about the second Amendemnt?</template>
</category>
<category><pattern>IS CAPITALISM *</pattern>
<template><srai>WHAT IS CAPITALISM </srai></template>
</category>
<category><pattern>DO YOU LIKE GUNS</pattern>
<template>Not especially. I am not into violence. </template>
</category>
<category><pattern>WHY GUNS</pattern>
<template>I support the 2nd Amendment.</template>
</category>
<category><pattern>WHO WAS THE FIRST IMPEACHED PRESIDENT *</pattern>
<template>Andrew Jackson.</template>
</category>
<category><pattern>WHO WAS THE FIRST IMPEACHED *</pattern>
<template>Andrew Jackson.</template>
</category>
<category><pattern>WHO IS THE GOVERNOR OF TEXAS</pattern>
<template><set name="he">Rick Perry</set> is Rick Perry.</template>
</category>
<category><pattern>WHO IS THE GOVERNOR OF *</pattern>
<template>That changes every few years.</template>
</category>
<category><pattern>WHO IS THE GOVERNOR OF CALIFORNIA</pattern>
<template>Jerry Brown.</template>
</category>
<category><pattern>WHO IS THE GOVERNOR *</pattern>
<template>It changes every few years.</template>
</category>
<category><pattern>GUNS</pattern>
<template>Some people like guns.</template>
</category>
<category><pattern>GUNS *</pattern>
<template>I believe in the Right to Bear Arms.</template>
</category>
<category><pattern>TELL ME ABOUT GUNS</pattern>
<template><srai>WHAT IS A GUN</srai></template>
</category>
</aiml>

This is the sample code and its pretty simple but I couldn't find a single link where it tells how to make the bot send the response in the form of an image like I want the pattern to be who was marx and it responds with the image of marx


Solution

  • The way you do this depends on your interpreter and how you are using it. If your interpreter only supports AIML 1, you can display your image using HTML tags.

    <category>
        <pattern>WHO WAS MARX</pattern>
        <template>
            A historical figure who wrote about communism.
            <P ALIGN="CENTER"><img src="https://upload.wikimedia.org/wikipedia/commons/d/d4/Karl_Marx_001.jpg"></img></P>
        </template>
    </category>
    

    If your interpreter supports AIML 2 you can use the <image> tag like this

    <category>
        <pattern>WHO WAS MARX</pattern>
        <template>
            A historical figure who wrote about communism.
            <image>https://upload.wikimedia.org/wikipedia/commons/d/d4/Karl_Marx_001.jpg</image>
        </template>
    </category>
    

    This would produce the following output.

    enter image description here