-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
We need two things, to make it perfect. #266
Comments
Did you call
|
Re: webpack. I have the async-await branch open where I was working on converting RiveScript to use async functions and the In the process I was also upgrading to CoffeeScript 2 (which outputs very nice JavaScript, which I'd eventually use to convert the code back into vanilla JS) and replacing Grunt with webpack. I lost a bit of steam when trying to get the codebase to be backwards compatible with Node < 6. The code builds in CI for versions of Node with async/await, but I was trying to get Babel and such involved to build a backward compatible version. If you'd like to help, you can fork that branch and work on it. I haven't had a lot of free time or interest to mess with JavaScript recently. |
I sorted the replies before, tried with replyAysnc() and reply(), I actually made it 'work' by removing the .length property directly from node_modules folder, but I am not really sure if it actually worked since I got my user is in a empty random topic always. I tried to force the user to be in a topic hardcoding but got no sucesss, I guess rivescript isn't seeing the .rive files properly because of some webpack transpiling 'magic' :/ I am playing with rivescript.js, trying to port it to ECMA 8, got a lot of progresss, but I think the problem will be testing everything when I finallly finish, if I succeed I will pulll request with tests, if you want to, just create a rollup/webpack ecma8 branch for rivescript.js when I finish. |
To help debug it, try doing I'm starting to think it was failing to load the replies in the first place! Also if you turn on debug mode and don't see it parsing all your rivescript files, that could be it. I actually got inspired to work more on my async/await branch today, so progress on that will be coming along. I'm getting rid of CoffeeScript in the process! Going full ES2015+ :) |
Going back to your original ticket:
Are you making sure to call The Here's an example for how to load RiveScript properly: let bot = new RiveScript();
// loadDirectory and loadFile are async so resolve their Promise
// and that's when you know they've finished loading.
bot.loadDirectory("./brain").then( () => {
bot.sortReplies(); // only after the replies were loaded,
// here, in the promise.then function
// now you're ok to get a reply
bot.reply("user", "hello bot").then( (reply) => {
console.log("Bot>", reply);
});
}); If you were to comment out the Try |
Since you locked the PR I will answer here.
Look my PR and see what I did with webpack.config.js and makefile, you will understand what I did. |
Hi, To help me verify what exactly the problem is, can you give me a working test case? Maybe as a GitHub gist or link me to a branch on your repo. I think if you were to copy my example code above into a new |
Hello Ok I will upload to my github and edit this comment. I will upload a example project, not my original one (because of hardcoded things, api tokens, password and etc), but the behavior occurs the same in both. @kirsle https://github.com/Kuchiriel/example Any help to run the project just ask. |
See here https://github.com/Kuchiriel/example/blob/master/client/views/ai/index.js I will try to run again, since you made a lot of modifications, this issue is old. Oh sorry, i didn't mention, you with interact with the bot by speech (Chrome/Chromium), I did not put other interface, you may need to put one or hardcode to get replies. (Now there is an interface) I am editing to put an interface and make sure I am sorting replies. |
await this.bot.loadFile([
'./brain/begin.rive',
'./brain/sarcasm.rive',
'./brain/about.rive',
// web,
// backend,
// about,
// search,
// spotify
],
this.bot.sortReplies() && console.log('RiveScript: Replies Sorted'),
on_load_error) I think that the line You're using Try this instead: // `await` will already wait until the Promise resolves
// before continuing with your code. If the promise throws
// a rejection, this can be caught with try/catch when using
// async/await.
await this.bot.loadFile([
'./brain/begin.rive',
'./brain/sarcasm.rive',
'./brain/about.rive',
// web,
// backend,
// about,
// search,
// spotify
]);
// here, loadFiles() has blocked until it resolved and you
// can sort the replies now.
this.bot.sortReplies() && console.log('RiveScript: Replies Sorted'); Another example of how async/await works: when you // The reply() function returns a Promise, so when you `await` it you can
// get the string reply and catch possible exceptions in a way that resembles
// normal sync code.
var reply;
try {
reply = bot.reply(username, message);
} catch(e) {
reply = "I ran into an error: " + e;
}
console.log("Bot>", reply);
/////////////////////////
// (when not using async functions or await, the Promise version
// of the above looked like this):
bot.reply(username, message).then(function(reply) {
console.log("Bot>", reply);
}).catch(function(error) {
console.log("Bot>", error);
}); |
Right, I will try and give a feedback. Now I got this.
I will put a try catch and see the result Same error and this Unhandled promise rejection TypeError: "this.master._users[user] is undefined" |
Man I will push my modifications, I manage to sort the replies now, BUT I KEEP IN A EMPTY TOPIC NAMED RANDOM, that is the issue, and the debugger says the .rives are properly loaded. RiveScript Interpreter v1.19.0 Initialized. 213:113:14 <- I guess I need to upgrade this. ERR: No default topic 'random' was found! @kirsle I will upgrade every dep try to run and push again. |
This usually means the replies didn't load properly. I saw in your console output you had an empty object Ideas on what to do next: 1) Turn on debug mode and examine all the output.
The debug log should show you two things:
e.g.:
e.g.
2) Log the
|
I upgraded the whole thing, now Webpack is messing with me about vue-loader xD @kirsle RiveScript Interpreter v2.0.0-alpha.6 Initialized. 316:325:12 I guess I found the problem. I will update if I manage to fix. (I was sending the message parameter without the user parameter LoL) Anyway same ghost, Bot ERR: No default topic 'random' was found RiveScript Interpreter v2.0.0-alpha.6 Initialized. 316:325:12 User Trevor was in an empty topic named 'random' |
The trouble is the Vue context. Rivescript inside Vue context don't work properly. This by example
Edit: Even outside Vue context, the code above does not work. If we force hardcoding to sort the replies, Rivescript is unable to manage the user context and the user always will be in the topic 'random' which Rivescript does not see (because its inside the Vue context), therefore, can't get an answer for the query, since it does not see the user message either.
This is not a Webpack compatibilty issue, this was solved with Webpack Copy Plugin, the real problem is Vue.js compatibility. If I run Rivescript outside the Vue context, it works flawless. So the improvement here will be make it work inside Vue context. I don't know if is needed to change the project code, or rivescript code. I will be doing tests, if I suceed you may create a Vue.js e.g. Pushed modifications. |
Working now. This is not a solution just a workaround for people that uses Vue.js, you need to put rivescript outside the Vue context. The problem is, you can't restrict the bot by Vue elements, if someone have a better idea to work with rivescript and Vue.js please comment here. e.g
|
@Kuchiriel I use Vue, Webpack, and Rivescript together in a project of mine. If it helps, this is my simple setup: I have the engine initialize, load files, and sort replies in its own file/module, and then I export the engine instance. Wherever I need the engine, I import it. It'll be the same instance anywhere you import it, so you don't have to re-initialize/load/sort each time you want to use it. Since |
This is a simplified version of the pattern I use: // this can be found in 'bot/bot_engine'
import RiveScript from 'rivescript';
import config from 'bot/config';
class BotEngine {
queue(onSuccess = () => {}, onError = () => {}) {
if (this._engine) {
onSuccess(this._engine);
return;
}
const rsEngine = new RiveScript();
rsEngine.loadFile(config.brainFiles).then(() => {
rsEngine.sortReplies();
this._engine = rsEngine;
onSuccess(this._engine);
}).catch((error) => {
console.warn(`Error loading brainfiles: ${error}`);
if (this._engine) delete this._engine;
onError(error);
});
}
}
const botEngine = new BotEngine();
export default botEngine; The <template>
<div>
<ul class="responses">
<li v-for="message in messages">{{message}}</li>
</ul>
<input v-model="inputMessage" @keyup.enter="sendMessage"/>
</div>
</template>
<script>
import botEngine from 'bot/bot_engine';
export default {
data() {
return {
messages: [],
inputMessage: '',
};
},
methods: {
sendMessage() {
this.messages.push(this.inputMessage);
botEngine.queue((engine) => {
engine.reply('keegan', this.inputMessage, this).then((outputMessage) => {
this.messages.push(outputMessage);
});
this.inputMessage = '';
});
},
},
};
</script> You probably don't even need the queue, really, as long as you're not immediately sending messages to the bot before it has a chance to asynchronously load the files and sort the replies... but if you are, then that might be a pattern you should consider. Hope it helps. |
@kjleitz It really helped! Thanks a lot! |
Hi @kjleitz & @Kuchiriel – I realise this is an old thread but am hoping someone can help me out with a quick question. @kjleitz, when you call |
@IdealPress no worries! I left // in bot/config.js
const config = {
// ...other config...
brainFiles: [
// These are your `.rive` files; if you're in the browser it'll try to get them
// over the network from "https://www.your.website/brain/begin.rive", and then
// "https://www.your.website/brain/main.rive", and so on (you get the picture)
'/brain/begin.rive',
'/brain/main.rive',
'/brain/some_other_stuff.rive',
'/brain/et_cetera.rive',
],
// ...other config...
};
export default config; ...but you don't have to do it that way if you don't have a separate // in bot/bot_engine.js
// ...
class BotEngine {
queue(onSuccess = () => {}, onError = () => {}) {
// ...
rsEngine.loadFile([
// These are your `.rive` files; if you're in the browser it'll try to get them
// over the network from "https://www.your.website/brain/begin.rive", and then
// "https://www.your.website/brain/main.rive", and so on (you get the picture)
'/brain/begin.rive',
'/brain/main.rive',
'/brain/some_other_stuff.rive',
'/brain/et_cetera.rive',
]).then(() => {
// ...
}
}
}
// ... Hope that helps! |
A release made up with rollup or webpack, and a .rive loader for webpack.
Almost solved the loader issue with CopyWebpackPlugin
But I am getting that error
Its something related to this line in brain.js
if (this.master._sorted.thats[top].length) {
That
and that
My guess, is babel-loader fucking up things (edit isn't I've tested, its probably babel-polyfill)
Edit: Wasn't babel, I've tested it, and I can't remove babel-polyfill because of async await support.
The text was updated successfully, but these errors were encountered: