I applied for a pre-application for the artificial intelligence API provided by User Local, and I received an API key around June, but it's quite a hand. I couldn't put it out. I'm new to the Web API, so it's easy to post.
For now, let's hit the API from Python to see what it looks like.
It seems that I should make a GET request, so I wrote the Python code as follows. Please specify your own for ʻapikey_pram. In fact, you can play up to 10 times an hour by setting the API Key to
" sample "`.
#! /usr/bin/env python -O
# -*- encode: utf-8 -*-
import sys
import json
import urllib.request
import urllib.parse
message_param = sys.argv[1]
apikey_param = "plz set your api key"
url = "https://chatbot-api.userlocal.jp/api/chat?"
params = {
"message": message_param,
"key": apikey_param
}
url += urllib.parse.urlencode(params)
if __debug__:
print("access to {0}".format(url))
with urllib.request.urlopen(url) as res:
html = res.read().decode("utf-8")
root = json.loads(html)
print("AI: {0}".format(root["result"]))
I saved this as sample_userlocal.py
.
It's called artificial intelligence, so it's a bit mean, but I asked it like this.
~ $ ./sample_userlocal.py What is artificial intelligence?
AI:About me? Lol
~ $ ./sample_userlocal.py Seriously?
AI:seriously
~ $ ./sample_userlocal.py Wow, great!
AI:Boogie((´^ω^))
Boogie --- ((´ ^ ω ^)) !!! I feel like "I don't think it feels good". Let's play a little more.
~ $ ./sample_userlocal.py hungry
AI:Welcome back!
~ $ ./sample_userlocal.py I'm home
AI:good job
~ $ ./sample_userlocal.py thank you
AI:Umu
Well, it's not uncommon to say "Welcome back" to "I'm hungry" ... I think it's unnatural, but if you try to talk forcibly, you can have some conversation. Finally, I asked "What is artificial intelligence?" Again and ended.
~ $ ./sample_userlocal.py What is artificial intelligence?
AI:Is it artificial intelligence rather than artificial intelligence?
Yeah yeah yeah yeah lol lol Really. (The guy you can't say)
I'm saying the formula, but since it's an API I'm learning, I'll say something strange. Well, it's pretty interesting, so next time I'll make this one a bot in the laboratory Slack (small average feeling)
It's easy, but by the memorandum.
Recommended Posts