Skip to content

Commit

Permalink
Add LUIS
Browse files Browse the repository at this point in the history
  • Loading branch information
François MATHIEU committed Mar 20, 2018
1 parent 1684fe7 commit 70faf14
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 26 deletions.
12 changes: 4 additions & 8 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ APP_SECRET=3b4f95ebaf0877f3f7ff85bb4bff33bc
#TRUSTED_HOSTS=localhost,example.com
###< symfony/framework-bundle ###

###> symfony/swiftmailer-bundle ###
# For Gmail as a transport, use: "gmail://username:password@localhost"
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
# Delivery is disabled by default via "null://localhost"
MAILER_URL=null://localhost
###< symfony/swiftmailer-bundle ###

###> doctrine/doctrine-bundle ###
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
Expand All @@ -24,4 +17,7 @@ DATABASE_URL=mysql://root:root@mariadb:3306/hackathon
###< doctrine/doctrine-bundle ###

GOS_WEB_HOST="webserver"
GOS_WEB_PORT="8356"
GOS_WEB_PORT="8356"

LUIS_URL=""
LUIS_KEY=""
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@

.idea
/public/build
/docker-compose.yml
/docker-compose.yml
###> symfony/web-server-bundle ###
.web-server-pid
###< symfony/web-server-bundle ###
2 changes: 2 additions & 0 deletions config/packages/parameters.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
parameters:
gos_web_host: '%env(GOS_WEB_HOST)%'
gos_web_port: '%env(GOS_WEB_PORT)%'
luis_url: '%env(LUIS_URL)%'
luis_key: '%env(LUIS_KEY)%'
8 changes: 6 additions & 2 deletions config/services.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: 'en'

services:
# default configuration for services in *this* file
Expand All @@ -11,7 +10,9 @@ services:
public: false # Allows optimizing the container by removing unused services; this also means
# fetching services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.

bind:
$luisUrl: "%luis_url%"
$luisKey: "%luis_key%"
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
Expand All @@ -26,3 +27,6 @@ services:

# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones

App\Utils\LuisSDK:
public: true
5 changes: 0 additions & 5 deletions engine/php-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,4 @@ RUN apt-get update \
&& apt-get -y install git \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

#NodeJS and NPM
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs
RUN npm install -g bower

WORKDIR "/application"
10 changes: 0 additions & 10 deletions engine/php-fpm/php-ini-overrides.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,4 @@ short_open_tag = on
upload_max_filesize = 100M
post_max_size = 108M
pm.max_requests = 100
; maximum memory that OPcache can use to store compiled PHP files
opcache.memory_consumption=256

; maximum number of files that can be stored in the cache
opcache.max_accelerated_files=20000
opcache.validate_timestamps=0
; maximum memory allocated to store the results
realpath_cache_size=4096K

; save the results for 10 minutes (600 seconds)
realpath_cache_ttl=600
17 changes: 17 additions & 0 deletions src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

namespace App\Controller;

use App\Utils\LuisSDK;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class DefaultController extends Controller
{
Expand All @@ -15,4 +18,18 @@ public function homepage()
{
return $this->render('base.html.twig');
}

/**
* @Route("/query", name="query")
* @param Request $request
* @return Response
*/
public function queryAction(Request $request)
{
$response = $this->get(LuisSDK::class)->query($request->query->get('q'));

var_dump($response);

return new Response();
}
}
48 changes: 48 additions & 0 deletions src/Utils/LuisSDK.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Utils;

/**
* Class LuisSDK
*
* @author François MATHIEU <[email protected]>
*/
class LuisSDK
{

/** @var string url */
private $url;

/**
* LuisSDK constructor.
* @param $luisUrl
* @param $luisKey
*/
public function __construct($luisUrl, $luisKey)
{
$this->url = sprintf("%s?subscription-key=%s&verbose=true&timezoneOffset=0&q=", $luisUrl, $luisKey);
}

/**
* Send a GET Request and return its result
*
* @param string $text
* @return array
*/
public function query($text)
{
$url = $this->url . $text;
$url = str_replace(' ', '%20', $url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');

$data = curl_exec($ch);
curl_close($ch);

return json_decode($data, true);
}
}

0 comments on commit 70faf14

Please sign in to comment.