gpt4 book ai didi

javascript - 创建 "fake AI"聊天程序

转载 作者:行者123 更新时间:2023-12-02 20:33:19 25 4
gpt4 key购买 nike

大家好,我一直在创建一个小聊天机器人(为了娱乐和练习)。

我有以下功能无法正常工作( FULL CODE HERE ):

function runAI() {
if (i.val().length > 0) {
if ($.inArray(i.val(), helloInputArray)) {
r = Math.floor(Math.random()*4);
o.html(o.html()+helloOutputArray[r]);
i.val('');
i.focus();
} else if ($.inArray(i.val(), byeInputArray)) {
r = Math.floor(Math.random()*4);
o.html(o.html()+byeOutputArray[r]);
i.val('');
i.focus();
} else {
o.html(o.html()+"I don't know what that means...<br />");
i.val('');
i.focus();
}
}
}

它似乎总是返回 helloOutputArray...

最佳答案

$.inArray 不返回 true 或 false,它返回基于 0 的索引。

-1表示未找到,> -1是数组中匹配的索引:

if ($.inArray(i.val(), helloInputArray) > -1) {
// The item was in this array
}

Working version here.

关于javascript - 创建 "fake AI"聊天程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3716656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com