GladysAssistant / Gladys

A privacy-first, open-source home assistant
https://gladysassistant.com
Apache License 2.0
2.63k stars 280 forks source link

Expected response for brain/classify #161

Closed danships closed 6 years ago

danships commented 7 years ago

Hi,

I am writing a Gladys integration for genie-router. But am running into some problems with the brain/classify API function.

It was rather hard to find working input, I now use turn on the lights, that works. Other queries returned a HTTP 500. The result is [null], but what does that mean? Does this mean the input is accepted, or is there still something missing?

Regards,

Dean

Pierre-Gilles commented 7 years ago

Hi,

Thanks for your message, and sorry for the late reply.

I'm currently improving the messaging part, and refactoring the error handling system of Gladys Rest API, so it should work fine in a near future !

For now, when no sentence is matching, a 500 is returned, that's pretty bad. It means that Gladys did not recognize your text.

I'm going instead to return a JSON with an answer so that Gladys can give a text feedback to the user.

No more dumb 500 errors will be returned, but a default message like "sorry I did not understand" :)

danships commented 7 years ago

Great, that will be ideal for my use case. Any idea on an ETA? I'll pause the Gladys integration for now, pending on your update.

Pierre-Gilles commented 7 years ago

Mmm I'm working on it as fast as possible, but I don't exactly know when it will be ready

I'll tell you when it's ready !

But the API won't change that much, you'll receive a 200 response with a json like :

{
    "response": "Light turned on with success !"
} 

( the format is not defined yet, but will be something like that )

danships commented 7 years ago

Ok, no rush, was just curious. There is enough other stuff to focus on. 😄

Pierre-Gilles commented 7 years ago

I just published a first draft as I was working on it :)

Here it is => https://twitter.com/gladysproject/status/841699699782496257

If you have any feedbacks before I start coding all routes, don't hesitate :)

danships commented 7 years ago

No feedback, looks good! I am also interesting in how you plan to update the brain behind it to be able to immediately provide the feedback. I was thinking about implementing a notification plugin for my use case, to respond to the brain/classify input, but that is not necessary anymore looking at this.

Pierre-Gilles commented 7 years ago

Nice!

Good question, that's my main interrogation. I think we can have both behavior :

danships commented 7 years ago

Ah yes. The message would then be sent via notification. Possibly with some identifier that links it to the request made earlier.

danships commented 7 years ago

Is there something I can do to contribute to this feature? I know some basics of the core. Or I could perhaps test it in beta or write some docs once it is done.

Pierre-Gilles commented 7 years ago

In fact I'm going to separate messages and notifications in Gladys. It's going to be two separate concepts (like in facebook for example).

A message is defined like this :


datetime: {
    type: 'datetime'
},

sender: {
    model: 'user'
},

receiver: {
    model: 'user'
},

text: {
    type: 'text'
},

label: {
    type: 'string'
},

scope: {
    type: 'json'
},

conversation: {
    type: 'uuid'
},

isRead: {
    type: 'boolean',
    defaultsTo: false
}

and represents the same as in Facebook, a message between two users in Gladys.

The two users speaking can be either "a real user" <=> "gladys", or "a real user" <=> "another real user", the goal is to have a flexible system.

Gladys is going to be a real chatbot with interactions, history, that can be plugged into others system ( Messenger API, Telegram API, Slack API )

I'm going to push soon the first job I did on this on git, so you can test and tell me what you think of it, and if you want to help of course don't hesitate, that's great :)

danships commented 7 years ago

If you are looking into supporting the Messenger, Telegram and Slack API directly from Gladys, I might be able to help with that. I have done integrations with them before, and am currently setting up genie-router (https://github.com/matueranet/genie-router). The goal is to have a module you can integrate into an existing project and easily support several 'clients' (Messenger, Telegram, but also Google Home, Alexa and voice systems). In a couple of months it will probably have reached a level stable enough to be used in Gladys. What do you think?

Pierre-Gilles commented 7 years ago

The integration will not be in Gladys core but in modules as always, but yes that can be great !

The goal is to have one gladys module per platform ( Telegram, Slack, .. ) that makes the bridge between gladys and the platform. So yes why not :)

danships commented 6 years ago

Hi, I have picked up working on Gladys integration for genie-router. I noticed that in the response to a POST to /message I do not get a response back. Which is different than the proposal you tweeted in March.

{"text":"turn on the lights","sender":1,"conversation":"275cc774-9cbd-475b-959a-b6f21fa957cf","datetime":"2017-10-15T13:09:16.514Z","receiver":null,"isRead":false,"createdAt":"2017-10-15T13:09:16.517Z","updatedAt":"2017-10-15T13:09:16.517Z","id":9,"senderName":"Dean"}

Is this the expected behavior? I see that it attempts to send a message back, but that is probably via a different channel. Should I fetch the conversation using its identifier and read the last message from that?

gladys_1 | Access with token to user Dean
gladys_1 | brain : classify : Identified label brain;no-command-detected
gladys_1 | Getting conversation 8cec657b-4b91-47a3-a22a-fa3e5c32235e, found 1 messages.
gladys_1 | Brain : answer : Answering with label no-command-detected in language en-US
gladys_1 | Brain : answer : Found 2 possible.
gladys_1 | User is not available on any service. Cannot contact him.
gladys_1 | brain : classify : Answered in 0s, 115.776 ms
Pierre-Gilles commented 6 years ago

Hey!

Sorry for the late reply. Yes I changed the behavior, the answer is not in the original request as it's often long to answer (for example if you ask for the weather, it needs to fetch an foreign API that does not respond instantly)

For your work, you need to develop a Gladys module (it's just one or two JS files), like this one for example that implements a notify + install function .

Then, when Gladys will want to answer via your genie-router, it will call your module that will forward the message to your genie-router!

I don't know if I'm clear.. Don't hesitate to ask :)

danships commented 6 years ago

Hi, thanks for the reply. I now do it differently, I query the conversations for a user, and find the reply there. Not ideal, because as you mention it may be that there is no reply available yet. I might look into the Gladys module solution you suggest in the future.