Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubKermes committed Jan 13, 2024
1 parent ca4c6ac commit b47758e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/RulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getRules($country, $city): array
->where("city_id", $city->id)
->first();

if(!$rules || !$rules->rulesENG || !$rules->rulesPL){
if(!$rules || $rules->rulesENG === null || $rules->rulesPL === null){
$cityData = [
"city_id" => $city->id,
"country_id" => $country_id,
Expand Down
7 changes: 5 additions & 2 deletions app/Services/OpenAIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct()

public function importRulesForAllCities(bool $force): void
{
$cities = City::query()->whereHas('cityProviders')->get();
$cities = City::query()->whereHas('cityProviders')->orderBy('country.name')->get();
foreach ($cities as $city) {
$cityData = [
"city_id" => $city->id,
Expand Down Expand Up @@ -56,7 +56,7 @@ public function importRulesForCity(array $cityData, bool $force): array
$country_name = $cityData["country_name"];

$promptENG = "Act as a helpful assistant. Explain what are the legal limitations for riding electric scooters in $city_name, $country_name? Contain information about: max speed, helmet requirements, allowed ABV, passengers, other relevant details. Be formal, speak English. Don't include city name in your response. If you don't have information answering the question, write 'null'";
$promptPL = "Zachowuj się jako pomocny asystent, wyjaśnij jakie są prawa dotyczące jazdy na hulajnogach elektrycznych w $city_name, $country_name? Zawrzyj informacje o: maksymalnej prędkości, potrzebie kasku, dozwolonym alkoholu we krwi, pasażerach, inne. Bądź formalny, mów po polsku. Nie zawieraj nazwy miasta w odpowiedzi. Jeśli nie masz informacji odpowiadających na pytanie, napisz 'null'";
$promptPL = "Zachowuj się jako pomocny asystent. wyjaśnij jakie są prawa dotyczące jazdy na hulajnogach elektrycznych w $city_name, $country_name? Zawrzyj informacje o: maksymalnej prędkości, potrzebie kasku, dozwolonym alkoholu we krwi, pasażerach, inne. Bądź formalny, mów po polsku. Nie zawieraj nazwy miasta w odpowiedzi. Jeśli nie masz informacji odpowiadających na pytanie, napisz 'null'";

if (!$force) {
$currentRules = Rules::query()->where("city_id", $city_id)->where("country_id", $country_id)->first();
Expand Down Expand Up @@ -90,6 +90,9 @@ public function importRulesForCity(array $cityData, bool $force): array
];
}

$rulesENG = str_replace("\n", "<br>", $rulesENG);
$rulesPL = str_replace("\n", "<br>", $rulesPL);

Rules::query()->updateOrCreate([
"city_id" => $city_id,
"country_id" => $country_id,
Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
Route::delete("/delete-city-without-assigned-country/{city}", [CityWithoutAssignedCountryController::class, "destroy"]);
Route::post("/delete-all-cities-without-assigned-country", [CityWithoutAssignedCountryController::class, "destroyAll"]);

Route::get("/import-rules/{force}", [\App\Services\OpenAIService::class, "importRules"]);
Route::get("/import-rules/{force}", [\App\Services\OpenAIService::class, "importRulesForAllCities"]);
});
});

Expand Down

0 comments on commit b47758e

Please sign in to comment.