Skip to content

Commit

Permalink
Merge branch '#10-regulations-for-escooters' of https://github.com/bl…
Browse files Browse the repository at this point in the history
…umilksoftware/escooters into #10-regulations-for-escooters
  • Loading branch information
Lee0z committed Jan 6, 2024
2 parents b642a84 + 707e620 commit 62871c3
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 6 deletions.
66 changes: 66 additions & 0 deletions app/Http/RulesImporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace App\Http;

use Exception;
use OpenAI;
use App\Models\City;

class RulesImporter
{

public function importRules()
{
$responseENG = "Sorry, we couldn't find any rules for this city.";
$responsePL = "Przepraszamy, nie udało nam się znaleźć żadnych zasad dla tego miasta.";
try {
$client = OpenAI::client(env('OPENAI_API_KEY'));

$cities = City::all();
$places = [];
foreach ($cities as $city){
$places[] = ['city' => $city->name, "country" => $city->country->name, "rulesENG" => $responseENG, "rulesPL" => $responsePL];
}


foreach ($places as $place){


$promptENG = "What are the legal limitations for riding electric scooters in " . $place['city'] . ", " . $place['country'] . "? Contain information about: max speed, helmet requirements, allowed ABV, passengers, other relevant details. Be formal, end with a legal disclaimer.";
$promptPL = "Jakie są prawa dotyczące jazdy na hulajnogach elektrycznych w " . $place['city'] . ", " . $place['country'] . "? Zawrzyj informacje o: maksymalnej prędkości, potrzebie kasku, dozwolonym alkoholu we krwi, pasażerach, inne. Bądź formalny, zakończ oświadczeniem prawnym.";

$responseENG = $client->chat()->create([
'model' => 'gpt-3.5-turbo',
'messages' => [
[
'role' => 'user',
'content' => $promptENG,
],

],
]);
$responsePL = $client->chat()->create([
'model' => 'gpt-3.5-turbo',
'messages' => [
[
'role' => 'user',
'content' => $promptPL,
],

],
]);

$place['rulesENG'] = $responseENG['choices'][0]['text'];
$place['rulesPL'] = $responsePL['choices'][0]['text'];
}


} catch (Exception $e) {

}

//store data, maybe in db

}

}
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
"license": "MIT",
"require": {
"php": "^8.2",
"ext-dom": "*",
"ext-pdo": "*",
"guzzlehttp/guzzle": "^7.7",
"guzzlehttp/guzzle": "^7.8",
"inertiajs/inertia-laravel": "^0.6.9",
"laravel/framework": "^10.13.0",
"laravel/sanctum": "^3.2.5",
"laravel/socialite": "^5.10",
"laravel/tinker": "^2.8.1",
"openai-php/client": "^0.8.1",
"sentry/sentry-laravel": "^3.7",
"spatie/laravel-permission": "^6.1",
"stichoza/google-translate-php": "^5.1",
"symfony/dom-crawler": "^6.3",
"ext-dom": "*"
"symfony/dom-crawler": "^6.3"
},
"require-dev": {
"blumilksoftware/codestyle": "v2.5.0",
Expand Down
154 changes: 151 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\FavoritesController;
use App\Http\Controllers\RulesController;
use App\Http\RulesImporter;
use Illuminate\Support\Facades\Route;

Route::middleware("guest")->group(function (): void {
Expand Down Expand Up @@ -47,6 +48,9 @@
Route::post("/run-importers", [CityProviderController::class, "runImporters"]);
Route::delete("/delete-city-without-assigned-country/{city}", [CityWithoutAssignedCountryController::class, "destroy"]);
Route::post("/delete-all-cities-without-assigned-country", [CityWithoutAssignedCountryController::class, "destroyAll"]);

Route::get("/importRules", [RulesImporter::class, "importRules"]);

});
});

Expand Down

0 comments on commit 62871c3

Please sign in to comment.