繁体   English   中英

使用带有鳗鱼的 Python 函数的 Javascript

[英]Javascript using Python function with eel

我正在使用 Python 和 JavaScript 制作聊天机器人程序。 我使用 eel 为聊天机器人制作 UI,但 Python 代码中公开的函数不能在 JavaScript 代码中使用。

Python代码

@eel.expose
def responsedMessage(message):
    word = tokenize(message)
    if not word == '@':
        reply = load_w2v(word)
    else:
        reply = ''
    response = make_sentence(reply)
    return response

JavaScript

async function btnFunc(){
    if(!inputText.value) return false;
    output(inputText.value,'me');
    const response = await eel.responsedMessage(inputText.value);
    output(response,'robot');
}

错误

chatbot_js.html:60 Uncaught (in promise) TypeError: eel.responsedMessage is not a function
at btnFunc (chatbot_js.html:60)
at HTMLInputElement.onclick (chatbot_js.html:16)

为什么会发生这个错误?

你应该把eel.start('main.html')放在你的 python 脚本的末尾

@eel.expose
def responsedMessage(message):
    word = tokenize(message)
    if not word == '@':
        reply = load_w2v(word)
    else:
        reply = ''
    response = make_sentence(reply)
    return response

eel.start('main.html')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM