This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/import_wp') | |
def import_data_blog(): | |
# Connect to Elasticsearch (locally installed) | |
document_store = ElasticsearchDocumentStore(host="localhost", username="", password="", index="blogposts") | |
# convert files to dicts containing documents that can be indexed to our datastore | |
dicts = convert_sql_to_dicts(True) | |
# You can optionally supply a cleaning function that is applied to each doc (e.g. to remove footers) | |
# It must take a str as input, and return a str. | |
# Now, let's write the docs to our DB. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* We send the query to haystack hoping for an answer | |
*/ | |
val defaultFallback = fallbackState() | |
.body(context -> { | |
String question = context.getIntent().getMatchedInput(); | |
if (question != null) { | |
HttpResponse<JsonNode> response = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ReactPlatform reactPlatform = new ReactPlatform(); | |
ReactEventProvider reactEventProvider = reactPlatform.getReactEventProvider(); | |
ReactIntentProvider reactIntentProvider = reactPlatform.getReactIntentProvider(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
awaitingInput | |
.next() | |
.when(intentIs(greetings)).moveTo(handleWelcome) | |
.when(intentIs(AnyOtherThing)).moveTo(handleAnyOtherThing); | |
handleWelcome | |
.body(context -> reactPlatform.reply(context, "Hello World!")) | |
.next() | |
/* | |
* A transition that is automatically navigated: in this case once we have answered the user we |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val greetings = intent("Greetings") | |
.trainingSentence("Hi") | |
.trainingSentence("Hello") | |
.trainingSentence("Good morning") | |
.trainingSentence("Good afternoon"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
handleCanYou | |
.body(context -> | |
{ | |
String request = (String) context.getIntent().getValue("request"); | |
if(isNull(request) || request.isEmpty()) { | |
reactPlatform.reply(context, "Sorry, I didn't get it, could you rephrase?"); | |
} | |
else { | |
String url = giphyPlatform.getGif(context, request); | |
reactPlatform.reply(context, "Sure! \n![look](" + url + ")"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val canYou = intent("CanYou") | |
.trainingSentence("Can you dance?") | |
.trainingSentence("Have you seen Scarface?") | |
.trainingSentence("Do you know Jim Carrey?") | |
.trainingSentence("Any thoughts about politics?") | |
.trainingSentence("What do you think about testing?") | |
.trainingSentence("dance?") | |
.trainingSentence("Can you dance") | |
.trainingSentence("Have you seen Scarface") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
printWeather | |
.body(context -> { | |
String cityName = (String) context.getIntent().getValue("cityName"); | |
Map<String, Object> queryParameters = new HashMap<>(); | |
queryParameters.put("q", cityName); | |
ApiResponse<JsonElement> response = restPlatform.getJsonRequest(context, "http://api" + | |
".openweathermap.org/data/2.5/weather", queryParameters, Collections.emptyMap(), Collections.emptyMap()); | |
if (response.getStatus() == 200) { | |
long temp = Math.round(response.getBody().getAsJsonObject().get("main").getAsJsonObject().get("temp").getAsDouble()); | |
long tempMin = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
awaitingInput | |
.next() | |
.when(intentIs(howIsTheWeather)).moveTo(printWeather); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val howIsTheWeather = intent("HowIsTheWeather") | |
.trainingSentence("How is the weather today in CITY?") | |
.trainingSentence("What is the forecast for today in CITY?") | |
.parameter("cityName").fromFragment("CITY").entity(city()); |