dreammelter / agfzb-CloudAppDevelopment_Capstone

Capstone Project for IBM Full Stack Cloud Dev cert on Course Era.
https://tac-x0-dealerapp.us-south.cf.appdomain.cloud
Apache License 2.0
0 stars 1 forks source link

Update reviews with Watson NLU #16

Closed dreammelter closed 3 years ago

dreammelter commented 3 years ago

Task 3/4 to create the proxy services for the Cloud functions. Incorporate Watson NLU in get_dealer_details view for analyzing review sentiment

dreammelter commented 3 years ago

Since the NLU service was connected to the app, I tried using just the endpoint URL with instance/service ID, but no dice. All the results are returned with "unauthorized" - meaning an APIKEY needs to get involved somewhere, as suspected.

(Unless there's a different step missing in the step where I connect the services... VCAP_SERVICES seems to be holding onto some creds.)

dreammelter commented 3 years ago

....PR accidentally auto-closed.

dreammelter commented 3 years ago

Sentiment analysis now works both locally and in Cloud Foundry w/ latest build!

dreammelter commented 3 years ago

Quick notes on env vars/accessing them:

"""
VCAP is a dict
-- NLU []
----another dict in which 'credentials'{} sits
-------then in there is the apikey and url.
"""

if 'VCAP_SERVICES' in os.environ:
    vcap_svcs = json.loads(os.environ['VCAP_SERVICES'])
    NLU_SVC=vcap_svcs['NLU'][0]?    
    NLU_SVC_CREDS=NLU_SVC.get('credentials')
    NLU_SVC_CREDS['apikey']