File: /var/www/html/laravel/app/Console/Commands/SendAerodromeDataToRag.php
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class SendAerodromeDataToRag extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'aerodrome:send-data-to-rag';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Send Aerodromes data to rag';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$counter = 0;
$data['model'] = 'local'; // To make call to N8N local LLM proxy
// getfrom file ../docs/aerodromes.csv
$filePath = storage_path('../../docs/Airports.csv');
// read csv file line by line
$aerodromesData = [];
$handle = fopen($filePath, 'r');
while (($line = fgetcsv($handle, 0, ';')) !== false) {
if ($counter == 0) {
$headers = $line;
$counter++;
continue;
}
// combine headers and line to associative array
$lineData = array_combine($headers, $line);
$lineData = json_encode($lineData);
$aerodromesData[] = [
'code' => $line[0],
'data' => $lineData,
];
$counter++;
}
fclose($handle);
$endpoint = 'aerodromeToRag';
foreach ($aerodromesData as $aerodrome) {
$data['input'] = json_encode([
'code' => $aerodrome['code'],
'data' => $aerodrome['data'],
]);
$result = callGptProxi($data, $endpoint, 'rag');
print_r($result);
}
}
}