alan-ai / alan-sdk-flutter

Conversational AI SDK for Flutter to enable text and voice conversations with actions (iOS and Android)
https://alan.app
1.81k stars 39 forks source link

Fatal exception: main #10

Closed erueloi closed 2 years ago

erueloi commented 2 years ago

Hello,

Code in Alan Studio on load and execute is:

//Is a Json with pokemon data same this: project.pokemons = [ { form: "Normal", pokemon_id: 663, pokemon_name: "Talonflame", type: [ "Fire", "Flying" ] }, { form: "Normal", pokemon_id: 664, pokemon_name: "Scatterbug", type: [ "Bug" ] }, ...

onCreateProject(() => { project.pokemonsdata = project.pokemons.map(p => ${p.pokemon_name}~${p.pokemon_id}).join('|'); console.log(project.pokemonsdata); });

const userInput = context(() => { console.log(project.pokemonsdata); follow("$(POKEMON~ p:pokemonsdata)", p => p.resolve(p.POKEMON.value)); })

intent("Add (first|lead) (Poke|Pokemon) (1|one)", async p => { p.play("What pokemon add?");
var pokemon = await p.then(userInput); console.log(pokemon);
p.play({command: "pokemon1", value: pokemon});
});

When play a command with values return error: "E/AndroidRuntime(29591): java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.alan.alansdk.events.EventParsed$ParsedEntity E/AndroidRuntime(29591): at com.alan.alansdk.button.AlanStateListener.onParsedEvent(:1) E/AndroidRuntime(29591): at com.alan.alansdk.d.run(:6) E/AndroidRuntime(29591): at android.os.Handler.handleCallback(Handler.java:938) E/AndroidRuntime(29591): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(29591): at android.os.Looper.loop(Looper.java:236) E/AndroidRuntime(29591): at android.app.ActivityThread.main(ActivityThread.java:8056) E/AndroidRuntime(29591): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(29591): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656) E/AndroidRuntime(29591): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)"

Can you help me with the error? I don't know if the syntax is incorrect or an internal error.

Thks.

snyuryev commented 2 years ago

Hey @erueloi

I did a small adjustment for your script (please take a look to pokemonsPattern) and tried to run it with flutter app. Works fine.

project.pokemons = [
    {
        form: "Normal",
        pokemon_id: 663,
        pokemon_name: "Talonflame",
        type: [
            "Fire",
            "Flying"
        ]
    },
    {
        form: "Normal",
        pokemon_id: 664,
        pokemon_name: "Scatterbug",
        type: [
            "Bug"
        ]
    }
];

const pokemonsPattern = project.pokemons.map(p => `${p.pokemon_name}~${p.pokemon_id}`).join('|');

const userInput = context(() => {
    follow(`$(POKEMON~ ${pokemonsPattern})`, p => p.resolve(p.POKEMON.value));
})

intent("Add (first|lead) (Poke|Pokemon) (1|one)", async p => {
    p.play("What pokemon add?");
    var pokemon = await p.then(userInput);
    p.play(`Adding ${pokemon}`);
    p.play({command: "pokemon1", value: pokemon});
});

Please try and let me know if it works for you.

Thanks.

erueloi commented 2 years ago

Hello,

Thks for your answer, but error persists with same error in "java.lang.ClassCastException":

E/AndroidRuntime(24889): java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.alan.alansdk.events.EventParsed$ParsedEntity
E/AndroidRuntime(24889):    at com.alan.alansdk.button.AlanStateListener.onParsedEvent(:1)

For more information, i call AlanVoice in a button on a Flutter App inside a "Widget build(BuildContext context)":

void initAlan() {
      AlanVoice.addButton("key",
          buttonAlign: AlanVoice.BUTTON_ALIGN_LEFT);
      AlanVoice.setLogLevel("all");    
      AlanVoice.onCommand.add((command) => _handleCommand(command));

   }

And handle command function get de command data "value":

Future<void> _handleCommand(Map<String, dynamic> command) async {

switch (command["command"]) {
...
}}

Thks.

snyuryev commented 2 years ago

@erueloi what version of alan_voice are you using? I've been testing 3.1.0 with no error.

Could you provide whole script if it is possible?

erueloi commented 2 years ago

@snyuryev yes, use alan_voice 3.1.0.

In debug mode it works correctly, but when use in release mode it fails.

snyuryev commented 2 years ago

@erueloi got it. will try in release mode.

snyuryev commented 2 years ago

@erueloi Release build (with script above) is working fine for me.

I/flutter (16571): got new command {command: pokemon1, value: Scatterbug}

What is "value" in your scenario? Could you provide a script from Alan Studio which you are using. Or provide minimal reproducible example.

erueloi commented 2 years ago

@snyuryev the command value is a return of "userInput"

This is the script:

project.pokemons = [
    {
        form: "Normal",
        pokemon_id: 663,
        pokemon_name: "Talonflame",
        type: [
            "Fire",
            "Flying"
        ]
    },
    {
        form: "Normal",
        pokemon_id: 664,
        pokemon_name: "Scatterbug",
        type: [
            "Bug"
        ]
    }
];

const pokemonsPattern = project.pokemons.map(p => `${p.pokemon_name}~${p.pokemon_id}`).join('|');

const userInput = context(() => {
    //console.log(project.pokemonsdata);
    follow(`$(POKEMON~ ${pokemonsPattern})`, p => p.resolve(p.POKEMON.value));
})

intent("Add (first|lead) (Poke|Pokemon) (1|one)", async p => {
    p.play("What pokemon one add?");    
    var pokemon = await p.then(userInput);
    p.play(`Adding ${pokemon}`);
    p.play({command: "pokemon1", value: pokemon});
    p.state.pokemon1 = pokemon;    
    p.play(`Pokemon one added is: ${pokemon}`);
});

Commandsthat do not return anything work correctly, for example:

intent("(Add|New) battle", async p => {    
    p.play({command: "newbattle"});
    p.play('New battle created, add pokemons!');
});

Release print <<<<

I/flutter (22854): got new command {command: newbattle}
E/AndroidRuntime(22854): FATAL EXCEPTION: main
E/AndroidRuntime(22854): Process: com.erueloi.pogobattlestatics, PID: 22854
E/AndroidRuntime(22854): java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.alan.alansdk.events.EventParsed$ParsedEntity

thks for your help!

snyuryev commented 2 years ago

@erueloi we tried to reproduce this issue and no luck. Could you share your project on flutter (at least part with _handleCommand)

the-accidental-engineer commented 2 years ago

@snyuryev facing same issue please look into my issue if you time. @erueloi did you find the solution ? if yes please let me know.

erueloi commented 2 years ago

@Prateek0Srivastav no, the issue continues to fail.

snyuryev commented 2 years ago

@erueloi

Please try to add additional params for release build type

shrinkResources false
minifyEnabled false

to your build.gradle file. It should be located

[your_app_folder]/android/app/build.gradle

As result you should have something similar to:

buildTypes {
        release {
            signingConfig signingConfigs.debug
            shrinkResources false
            minifyEnabled false
        }
}

After that please try to run

snyuryev commented 2 years ago

@erueloi

Also updated version on plugin (3.3.0) is available. Please try this one.

snyuryev commented 2 years ago

Fixed with previous release. Please create a new issue if you need any additional help.