async def classifier_learn_intent(request): req_data = request.json if "label" not in req_data \ or "examples" not in req_data \ or not (type(req_data["examples"]) == list): return s_json({"code": 400, "msg": "invalid request"}) label = req_data["label"] examples = req_data["examples"] classifier.learn_intent(label, examples) return s_json({"code": 0, "msg": "success"})
async def classifier_learn(request): req_data = request.json if "label" not in req_data \ or not req_data["label"] \ or "sentence" not in req_data \ or not req_data["sentence"]: return s_json({"code": 400, "msg": "invalid request"}) label = req_data["label"] sentence = req_data["sentence"] classifier.learn(label, sentence) return s_json({"code": 0, "msg": "success"})
async def chat_reply(request): req_data = request.json if "index" not in req_data \ or type(req_data["index"]) != str \ or "say" not in req_data \ or type(req_data["say"]) != str \ or "threshold" not in req_data \ or type(req_data["threshold"]) != float: return s_json({"code": 400, "msg": "invalid request"}) chat_index = req_data["index"] threshold = req_data["threshold"] say = req_data["say"] r = chat.reply(say, threshold, chat_index) return s_json({"code": 0, "msg": "success", "proto": r})
async def classifier_predict(request): req_data = request.json if "sentence" not in req_data \ or type(req_data["sentence"]) != str \ or "possibles" not in req_data \ or type(req_data["possibles"]) != list \ or "threshold" not in req_data \ or type(req_data["threshold"]) != float \ or "limit" not in req_data \ or type(req_data["limit"]) != int: return s_json({"code": 400, "msg": "invalid request"}) sentence = req_data["sentence"] possibles = req_data["possibles"] threshold = req_data["threshold"] limit = req_data["limit"] sentence_doc = classifier.nlp(sentence) prediction = classifier.predict(sentence_doc, possibles, threshold, limit) return s_json({"code": 0, "msg": "success", "proto": prediction})
async def chat_learn(request): req_data = request.json if "cid" not in req_data \ or type(req_data["cid"]) != str \ or "say" not in req_data \ or type(req_data["say"]) != str \ or "reply" not in req_data \ or type(req_data["reply"]) != str \ or "index" not in req_data \ or type(req_data["index"]) != str: return s_json({"code": 400, "msg": "invalid request"}) cid = req_data["cid"] say = req_data["say"] reply = req_data["reply"] chat_index = req_data["index"] if not cid or not say or not reply: return s_json({"code": 400, "msg": "invalid request"}) chat.learn(cid, say, reply, chat_index) return s_json({"code": 0, "msg": "success"})
async def index(request): sentence_doc = classifier.nlp("hello world") prediction = classifier.predict(sentence_doc, [], 0.75, 5) return s_json({"test": prediction})