Skip to content

Instantly share code, notes, and snippets.

@DustinAlandzes
Last active December 26, 2018 21:32
Show Gist options
  • Save DustinAlandzes/8940f46951093eb9b3851c8a1d3a928d to your computer and use it in GitHub Desktop.
Save DustinAlandzes/8940f46951093eb9b3851c8a1d3a928d to your computer and use it in GitHub Desktop.
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
<?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