Javascript使用Python函数和eel

2024-09-30 08:28:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用Python和JavaScript制作一个聊天机器人程序。我使用eel为chatbot创建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)

为什么会发生这种错误


Tags: 代码messageifvalueresponsehtmljsnot
1条回答
网友
1楼 · 发布于 2024-09-30 08:28: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')

相关问题 更多 >

    热门问题