Skip to content

Commit a775e43

Browse files
ignore
0 parents  commit a775e43

18 files changed

+559
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Place Finder assistant
2+
3+
This repository contains the code of the Rasa-powered Place Finder assistant.
4+
5+
## Setup and installation
6+
7+
In order to run this assistant, you will need Rasa and a few additional dependencies. You can install them all by running the following command:
8+
9+
```
10+
pip install rasa-x --extra-index-url https://pypi.rasa.com/simple
11+
```
12+
13+
You also need to install a spaCy English language model. You can install it by running:
14+
15+
```
16+
python -m spacy download en
17+
```
18+
19+
## What's in this repository
20+
The repository consists of the following files and directories:
21+
22+
- **data/nlu_data.md** - training data examples for Rasa NLU model
23+
- **data/stories.md** - training data examples for Rasa Core model
24+
- **actions.py** the code of the custom action used to retrieve data from Google Places API.
25+
- **config.yml** contains the configuration of NLU processing pipeline.
26+
- **ga_credentials.yml** is a file where you should place your Google Places API key.
27+
- **domain.yml** file contains the domain configuration of the assistant.
28+
- **endpoints.yml** contains the webhook configuration for the custom action.
29+
- **ga_connector.py** contains the code of Rasa-Google Assistant connector.
30+
- **credentials.yml** is a file where you have to configure your custom connector.
31+
- **models** is a directory which contains the pretrained models for you to test.
32+
33+
34+
To run this assistant you will need a [Google Place API](https://developers.google.com/places/web-service/get-api-key) key which you should provide inside the credentials.yml file of these directories.
35+
36+
## Let us know how you are getting on!
37+
If you have any questions regarding this repository, please post them on the [Rasa Community Forum](https://forum.rasa.com)!
38+

__pycache__/actions.cpython-36.pyc

1.93 KB
Binary file not shown.

__pycache__/actions.cpython-39.pyc

1.94 KB
Binary file not shown.

__pycache__/connector.cpython-36.pyc

954 Bytes
Binary file not shown.
2.42 KB
Binary file not shown.
4.52 KB
Binary file not shown.
2.5 KB
Binary file not shown.

__pycache__/test.cpython-36.pyc

215 Bytes
Binary file not shown.

actions.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from __future__ import absolute_import
2+
from __future__ import division
3+
from __future__ import unicode_literals
4+
5+
from rasa_sdk import Action
6+
from rasa_sdk.events import SlotSet, AllSlotsReset
7+
import requests
8+
import json
9+
from random import randint
10+
import datetime
11+
import os
12+
import yaml
13+
14+
15+
16+
17+
class ActionPlaceSearch(Action):
18+
def name(self):
19+
#define the name of the action
20+
return 'action_place_search'
21+
22+
def run(self, dispatcher, tracker, domain):
23+
#retrieve slot values
24+
query = tracker.get_slot('query')
25+
radius = tracker.get_slot('number')
26+
27+
#retrieve google api key
28+
with open("./ga_credentials.yml", 'r') as ymlfile:
29+
cfg = yaml.load(ymlfile)
30+
key = cfg['credentials']['GOOGLE_KEY']
31+
32+
#get user's current location
33+
get_origin = requests.post(
34+
"https://www.googleapis.com/geolocation/v1/geolocate?key={}".format(key)).json()
35+
print(get_origin)
36+
origin_lat = get_origin['location']['lat']
37+
origin_lng = get_origin['location']['lng']
38+
39+
#look for a place using all the details
40+
place = requests.get('https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={},{}&radius={}&type={}&key={}'.format(origin_lat, origin_lng, radius, query, key)).json()
41+
if len(place['results'])==0:
42+
dispatcher.utter_message("Sorry, I didn't find anything")
43+
return [SlotSet('location_match', 'none')]
44+
else:
45+
for i in place['results']:
46+
if 'rating' and 'vicinity' in i.keys():
47+
name = i['name']
48+
rating = i['rating']
49+
address = i['vicinity']
50+
if i['opening_hours']['open_now']==True:
51+
opening_hours = 'open'
52+
else:
53+
opening_hours = 'closed'
54+
break
55+
speech = "I found a {} called {} based on your specified parameters.".format(query, name)
56+
dispatcher.utter_message(speech) #send the response back to the user
57+
return [SlotSet('location_match', 'one'), SlotSet('rating', rating), SlotSet('address', address), SlotSet('opening_hours', opening_hours)] #set returned details as slots
58+
59+
60+

0 commit comments

Comments
 (0)