You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
2.0 KiB
59 lines
2.0 KiB
from django.http import JsonResponse
|
|
from django.template import loader
|
|
import json
|
|
from prodae import knn_ae as knn_ae
|
|
from time import gmtime, strftime
|
|
from chatbot.models import Question, Responce, Question_Responce
|
|
|
|
from importlib import import_module
|
|
from django.conf import settings
|
|
SessionStore = import_module(settings.SESSION_ENGINE).SessionStore
|
|
|
|
|
|
def ae(request):
|
|
if request.method == 'POST':
|
|
jsonData = json.loads(request.body.decode('utf-8'))
|
|
msg = jsonData["msg"]
|
|
userId = jsonData["userId"]
|
|
klass1 = knn_ae.klassifizieren(msg)
|
|
klass = klass1[0:2]
|
|
intent1 = klass1[0][0]
|
|
accurancy1 = klass1[0][1]
|
|
if len(klass1)>1:
|
|
intent2 = klass1[1][0]
|
|
accurancy2 = klass1[1][1]
|
|
else:
|
|
intent2 = 'Null'
|
|
accurancy2 = 'Null'
|
|
klass = str(klass)
|
|
intent1 = str(intent1)
|
|
accurancy1 = str(accurancy1)
|
|
intent2 = str(intent2)
|
|
accurancy2 = str(accurancy2)
|
|
res = knn_ae.antwort(msg, jsonData["userId"])
|
|
time = strftime("%Y-%m-%d %H:%M:%S", gmtime())
|
|
#s = request.session
|
|
s = SessionStore()
|
|
s.save()
|
|
sess_id = s.session_key
|
|
print(request.session.session_key)
|
|
quest = Question(session_id=userId, question_text=msg, publi_date=time)
|
|
quest.save()
|
|
resp = Responce(session_id=userId, responce_text=res, publi_date=time)
|
|
resp.save()
|
|
qr = Question_Responce(session_id=userId, question_text=msg, intent1=intent1, accurancy1=accurancy1, intent2=intent2, accurancy2=accurancy2, responce_text=res, publi_date=time)
|
|
qr.save()
|
|
return JsonResponse({
|
|
"desc": "Success",
|
|
"klass": klass,
|
|
"intent1": intent1,
|
|
"accurancy1": accurancy1,
|
|
"intent2": intent2,
|
|
"accurancy2": accurancy2,
|
|
"ques": msg,
|
|
"res": res,
|
|
"user": userId,
|
|
"time": time
|
|
})
|
|
else:
|
|
return JsonResponse({"desc": "Bad request"}, status=400)
|