Last active
December 26, 2018 21:32
-
-
Save DustinAlandzes/8940f46951093eb9b3851c8a1d3a928d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from flask import Flask | |
app = Flask(__name__) | |
@app.route('/api/intent/train', methods=['POST']) | |
def create_intent(): | |
''' | |
Use this to create new intent. accepts a string | |
''' | |
# maybe just modify file? | |
return 'unimplemented' | |
@app.route('/api/intent/train', methods=['POST']) | |
def train(): | |
''' | |
Accepts intent string and training data in an array format. | |
''' | |
# maybe just modify file? | |
return 'unimplemented' | |
@app.route('/api/analysis', methods=['GET']) | |
def analysis(sender, message): | |
''' | |
Accepts message and returns interpreter data. | |
Use rasa_core.agent and rasa_core.interpreter for this purpose. | |
''' | |
response = requests.post("{}/webhooks/callback/webhook".format(base_url), | |
data={ | |
'sender': sender, | |
'message': message | |
}) | |
return response |
This file contains hidden or 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
<?php | |
namespace App\Models; | |
use Illuminate\Database\Eloquent\Model; | |
use App\Models\Connection; | |
use DB; | |
class Rasa extends Model | |
{ | |
protected $fillable = [] | |
protected $table = 'rasa' | |
protected $hidden = []; | |
public $base_url = "https://localhost:3333" | |
public function get($url) { | |
$curl = curl_init(); | |
if (!$curl) { | |
die("Couldn't initialize a cURL handle"); | |
} | |
// Set the file URL to fetch through cURL | |
curl_setopt($curl, CURLOPT_URL, $url); | |
$response = curl_exec($curl); | |
if (curl_errno($curl)) | |
{ | |
echo 'cURL error: ' . curl_error($curl); | |
curl_close($curl); | |
} | |
else | |
{ | |
curl_close($curl); | |
return $response | |
} | |
} | |
public function post($url, $data) { | |
$curl = curl_init(); | |
if (!$curl) { | |
die("Couldn't initialize a cURL handle"); | |
} | |
// Set the file URL to fetch through cURL | |
curl_setopt($curl, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_POST, true); | |
$response = curl_exec($curl); | |
if (curl_errno($curl)) | |
{ | |
echo 'cURL error: ' . curl_error($curl); | |
curl_close($curl); | |
} | |
else | |
{ | |
curl_close($curl); | |
return $response | |
} | |
} | |
public function create_intent($intent_str) { | |
// intent creation | |
// use this to create a new intent, accepts a string | |
post('$base_url/api/intent', array('intent' => $intent_str)) | |
} | |
public function train($intent_str, $training_data) { | |
// intent training | |
// accepts intent string and training data in an array format | |
post('$base_url/api/intent/train', array('intent' => $intent_str, 'data' => $training_data)) | |
} | |
public function analyze($message) { | |
// intent analysis | |
// accepts message and returns interpreter data | |
get('$base_url/api/analysis', array('message' => $message)) | |
} | |
public static function evaluate($condition, $text) { | |
analyze($text) | |
$intent = $condition['intent'] | |
$value = $condition['value'] | |
// check that the confidence of the provided intent | |
// is greater than or equal to $value | |
// if it is return true else return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment