Comments (11)
jsonify in this case transform the content of the yaml into a json output (and add headers and a few things).
But whatever yaml file you jsonify, the result will be a correct json.
The content however, is where the jsonapi standards indicate what the json must contains.
eg:, for /synapses, kalliope API returns an array of synapses like
{
"synapses": [
{
"name": "say-hello-fr",
"neurons": [
{
"say": {
"message": [
"Bonjour monsieur"
]
}
}
],
"signals": [
{
"order": "bonjour"
}
]
}
]
}
whereas with the jsonapi standard, the content should be something like:
{
"links": {
"self": "http://kalliopeHost:5000/synapses"
},
"data": [{
"type": "synapses",
"id": "1",
"attributes": {
"name": "say-hello-fr",
"neurons": [
{
"say": {
"message": [
"Bonjour monsieur"
]
}
}
],
"signals": [
{
"order": "bonjour"
}
]
}
}]
}
That being said, it is not that important to follow it but JS frontend can work with very limited amount of custom code if the API follow it (eg: https://github.com/jakubrohleder/angular-jsonapi for angularjs or http://emberjs.com/api/data/classes/DS.JSONAPIAdapter.html in core of emberjs).
But
from kalliope.
Does it returns all synapses in included yaml or just the "include" pointer?
from kalliope.
I found the problem. I chose to send the loaded yaml file directly instead of serialize object per object.
I need to update this part...
from kalliope.
As a more global remark on the API, I think the API should:
- be JsonAPI compliant (so easier to create backend using angularjs or emberjs frontend)
- Be configurable to authorize cors request in case frontend has not the same origine as kalliope (origine being host + port + scheme). It might often be the case as a JS app might not run on the same port as kalliope.
from kalliope.
yes I agree, we did not spend much time on the API, we need to investigate deeper on those 2 points.
from kalliope.
Ok, so I did a quick hack to test something.
By adding the flask-cors library, and adding the 2 lines as per the following diff, I can make my emberjs app working (on port 4200, my node server) and with kalliope on port 5000.
Is this something worth investigating? I could try to set this up as optional (as the authentication part) so that only people allowing CORS request will have this feature?
(obviously the code below is just a quick hack that need better config, eg: for origin acceptance)
diff --git i/kalliope/core/RestAPI/FlaskAPI.py w/kalliope/core/RestAPI/FlaskAPI.py
index 01c3856..298a0bc 100644
--- i/kalliope/core/RestAPI/FlaskAPI.py
+++ w/kalliope/core/RestAPI/FlaskAPI.py
@@ -4,6 +4,8 @@ from flask import jsonify
from flask import request
from flask_restful import abort
+from flask_cors import CORS, cross_origin
+
from kalliope.core import OrderAnalyser
from kalliope.core.RestAPI.utils import requires_auth
from kalliope.core.SynapseLauncher import SynapseLauncher
@@ -23,6 +25,8 @@ class FlaskAPI(threading.Thread):
self.port = port
self.brain = brain
+ cors = CORS(app, resources={r"/*": {"origins": "*"}}, supports_credentials=True)
+
self.app.add_url_rule('/synapses/', view_func=self.get_synapses, methods=['GET'])
self.app.add_url_rule('/synapses/<synapse_name>', view_func=self.get_synapse, methods=['GET'])
self.app.add_url_rule('/synapses/<synapse_name>', view_func=self.run_synapse, methods=['POST'])
edit: Also, simply adding the line:
self.app.add_url_rule('/synapses', view_func=self.get_synapses, methods=['GET'])
seems to work fine to add a more standard routes to retrieve synapses (GET /synapses)
from kalliope.
be JsonAPI compliant
We are not JSON compliant here?
from kalliope.
The API return json but is not really jsonapi compliant (which is a new standard for api that return json for url and response content)
from kalliope.
Actually we are using the jsonify lib to return from the yaml so it seems compliant ... or the lib itself is not
from kalliope.
Ok, thanks for the example.
It seems it's not really implemented a lot yet. Even in professional projects. So, we'll see if we implement it from our side when we will review the Web App for Kalliope client config. It will be in Angular 2 I think.
from kalliope.
Fixed in the v0.4.0.
Now included brains are returned and we've also allowed the remove the last slaches in URL.
from kalliope.
Related Issues (20)
- support deepspeech for speech-to-text HOT 1
- werkzeug HOT 2
- Is possible update Spanish version I want to collaborate HOT 3
- python setuptools bad marshal data (unknown type code) HOT 5
- Ansible install error HOT 11
- Help, I get an error on "kalliope --version" HOT 5
- Does Kalliope have the ability to understand domain specific knowledge? HOT 4
- Error when starting Kalliope HOT 20
- ReSpeaker Mic Array V2 microphone sensibility HOT 4
- Script does not work. HOT 7
- Fatal error for module Snowboydetect HOT 4
- Update on Playstore or upload to F-droid HOT 1
- Script neuron does not accept script with arguments
- Add support for Mimic3 offline TTS
- I installed Kalliope from source on Ubuntu 22.04 and I get error messages. It doesn't work. HOT 4
- can't get kalliope working HOT 3
- Install seems to fail HOT 1
- Brain example / code for using (cloud or local) chat gpt-4 conversations
- Whisper support HOT 5
- Running in Debian HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kalliope.