赞
踩
由于data和预训练参数过大,未上传至github
视频:
国内bilibili:https://www.bilibili.com/video/BV1Re411W7LX/
国外YouTube:https://www.youtube.com/watch?v=Vjo8qHwGIAg&feature=youtu.be
前端 script.js
//发送 addMessage: function() { let msg = this.$textarea.val() let that = this $.ajax({ url: 'http://localhost:5000/api', method: "post", dataType: 'json', type:"post", data: {question:msg}, headers:{ "Access-Control-Allow-Origin":true, }, success: function(res) { that.messageToSend = that.$textarea.val() that.render(res.answer); }, error: function(e){ console.log(e) }
接口用flask实现,这里给一个简单的demo:
from flask import Flask, request from flask_cors import CORS app = Flask(__name__) CORS(app, supports_credentials=True) @app.route('/api', methods=['GET', 'POST']) def indextest(): if request.method == 'GET': question = request.args question = question['question'] answer = GetQuestionAns(question) #这里是自己定义的根据问题给出回答的函数 return {'answer': answer} elif request.method == 'POST': question = request.form["question"] answer = GetQuestionAns(question) return {'answer': answer} @app.route('/', methods=['GET', 'POST']) def a(): return request.form['question'] if __name__ == '__main__': app.run(host='0.0.0.0',port=5000,debug=True)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。