Update twitter python demo for 1.0.0 (#50)

This commit is contained in:
Charlie Stanley 2021-02-17 16:07:53 -08:00 committed by GitHub
parent 143c59b6e5
commit 2c493f23bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 21 additions and 20 deletions

View File

@ -4,8 +4,8 @@
| Attribute | Details | | Attribute | Details |
|--------|--------| |--------|--------|
| Dapr runtime version | v0.11.3+ | | Dapr runtime version | v1.0.0+ |
| Dapr Python SDK | v0.8.0a0+ | | Dapr Python SDK | v1.0.0+ |
| Language | Python | | Language | Python |
| Environment | Local | | Environment | Local |

View File

@ -5,7 +5,7 @@ import logging
from azure.ai.textanalytics import TextAnalyticsClient from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential from azure.core.credentials import AzureKeyCredential
from dapr.clients import DaprClient from dapr.clients import DaprClient
from dapr.ext.grpc import App, InvokeServiceRequest, InvokeServiceResponse from dapr.ext.grpc import App, InvokeMethodRequest, InvokeMethodResponse
LANG_DEFAULT = 'en' LANG_DEFAULT = 'en'
SECRET_STORE_NAME = 'pipeline-secrets' SECRET_STORE_NAME = 'pipeline-secrets'
@ -23,7 +23,7 @@ analytics_key = ''
app = App() app = App()
@app.method(name='sentiment-score') @app.method(name='sentiment-score')
def sentiment(request: InvokeServiceRequest) -> InvokeServiceResponse: def sentiment(request: InvokeMethodRequest) -> InvokeMethodResponse:
req = json.loads(request.data) req = json.loads(request.data)
logging.info(req) logging.info(req)
lang = req.get('lang') or LANG_DEFAULT lang = req.get('lang') or LANG_DEFAULT
@ -32,7 +32,7 @@ def sentiment(request: InvokeServiceRequest) -> InvokeServiceResponse:
logging.info(score) logging.info(score)
return InvokeServiceResponse(json.dumps(score), 'application/json') return InvokeMethodResponse(json.dumps(score), 'application/json')
def get_analytics_client(endpoint: str, key: str): def get_analytics_client(endpoint: str, key: str):

View File

@ -1,3 +1,3 @@
azure-ai-textanalytics >= 5.1.0b2 azure-ai-textanalytics >= 5.1.0b2
dapr-ext-grpc >= 0.8.0a0 dapr-ext-grpc >= 1.0.0
dapr >= 0.8.0a0 dapr >= 1.0.0

View File

@ -25,9 +25,9 @@ def binding(request: BindingRequest):
tweet_data = json.dumps(m) tweet_data = json.dumps(m)
d.save_state(STORE_NAME, m['id'], tweet_data) d.save_state(STORE_NAME, m['id'], tweet_data)
resp = d.invoke_service( resp = d.invoke_method(
id='tweet-processor', 'tweet-processor',
method='sentiment-score', 'sentiment-score',
data=tweet_data) data=tweet_data)
m['sentiment'] = json.loads(resp.data) m['sentiment'] = json.loads(resp.data)

View File

@ -1,2 +1,2 @@
dapr-ext-grpc >= 0.8.0a0 dapr-ext-grpc >= 1.0.0
dapr >= 0.8.0a0 dapr >= 1.0.0

View File

@ -1,4 +1,4 @@
dapr-ext-grpc >= 0.8.0a0 dapr-ext-grpc >= 1.0.0
dapr >= 0.8.0a0 dapr >= 1.0.0
flask-socketio >= 4.3.2 flask-socketio == 4.*
flask >= 1.1.2 flask >= 1.1.2

View File

@ -28,9 +28,10 @@ window.onload = function () {
connDiv.innerText = "closed"; connDiv.innerText = "closed";
}); });
sock.on('message', function (t) { sock.on('message', function (m) {
var scoreStr = "neutral"; var scoreStr = "neutral";
var scoreAlt = "neutral: 0" var scoreAlt = "neutral: 0";
t = JSON.parse(m);
if (t.hasOwnProperty("sentiment")) { if (t.hasOwnProperty("sentiment")) {
console.log(t.sentiment); console.log(t.sentiment);
@ -54,4 +55,4 @@ window.onload = function () {
}); });
} // if log } // if log
}; };

View File

@ -40,4 +40,4 @@
</body> </body>
</html> </html>