fossasia / susi_server

SUSI.AI server backend - the Artificial Intelligence server for personal assistants https://susi.ai
GNU Lesser General Public License v2.1
2.51k stars 1.08k forks source link

Changes in json output break susi_python #1315

Closed norbusan closed 5 years ago

norbusan commented 5 years ago

With current susi_server we get the following crash

$ python3
Python 3.7.4 (default, Jul 11 2019, 10:43:21) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import susi_python as susi
connected to local server
>>> susi.ask("what is the time")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/norbert/Development/SuSI.ai/susi_python.git/susi_python/main.py", line 117, in ask
    response = query(query_string)
  File "/home/norbert/Development/SuSI.ai/susi_python.git/susi_python/main.py", line 77, in query
    parsed_res = get_query_response(response_json)
  File "/home/norbert/Development/SuSI.ai/susi_python.git/susi_python/response_parser.py", line 63, in get_query_response
    return QueryResponse(answer,parsed_dict, session)
  File "/home/norbert/Development/SuSI.ai/susi_python.git/susi_python/models.py", line 4, in __init__
    self.count = json['count']
KeyError: 'count'
>>> 

I bisected this and the bad commit introducing this is 3e27f092dbc46247720013d3f158d0b2a071a0f8 refactoring answer computation

Relevant change in the json answers:

--- good-answer 2019-07-18 15:07:10.260255000 +0900
+++ bad-answer  2019-07-18 15:08:21.611581510 +0900
@@ -1,28 +1,31 @@
 {
   "query": "what is the time",
-  "count": 1,
   "client_id": "aG9zdF8xMjcuMC4wLjFfNmJlM2MzODY=",

Relevant change in source code:

diff --git a/src/ai/susi/mind/SusiCognition.java b/src/ai/susi/mind/SusiCognition.java
index 2ad7dbc3..9572cb2e 100644
--- a/src/ai/susi/mind/SusiCognition.java
+++ b/src/ai/susi/mind/SusiCognition.java
@@ -94,7 +94,6 @@ public class SusiCognition {
         // get a response from susis mind
         String client = identity.getClient();
         this.setQuery(query);
-        this.json.put("count", maxcount);
         SusiThought observation = new SusiThought();
         observation.addObservation("timezoneOffset", Integer.toString(timezoneOffset));

Tje susi_python code does:

class QueryResponse:
    def __init__(self,answer, json, session):
        self.query = json['query']
        self.count = json['count']
        self.client_id = json['client_id']
        self.query_date = json['query_date']
        self.answer_time = json['answer_time']
        self.session = session
        self.answer = answer

    def __repr__(self):
        return 'QueryResponse (query = %s , count = %s, client_id = %s, ' \
               'query_date = %s, answer_time = %s, session = %s, answer = %s )' % \
               (self.query, self.count, self.client_id, self.query_date, self.answer_time, self.session, self.answer)

For now I have removed the count related part of the query code in susi_python, see https://github.com/fossasia/susi_python/commit/b9823a0cf0f97f8f370de44fe7368af7b6cb1c18 but I would like to ask @Orbiter @stealthanthrax @hongquan whether this is the correct fix or whether the server should be changed to re-include the count argument.

Orbiter commented 5 years ago

Oh! I see, I actually removed the count attribute because it was fixed to 1 and I did not found a reason why it should every be another number. So thats ok, omit the number!

norbusan commented 5 years ago

So it is working now even on device, let us close this.