-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a08f13
commit f6ab32e
Showing
6 changed files
with
158 additions
and
82 deletions.
There are no files selected for viewing
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Rules extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $table = "rules_for_cities"; | ||
protected $fillable = [ | ||
"city_id", | ||
"country_id", | ||
"rulesENG", | ||
"rulesPL", | ||
]; | ||
|
||
public function city() | ||
{ | ||
return $this->belongsTo(City::class); | ||
} | ||
|
||
public function country() | ||
{ | ||
return $this->belongsTo(Country::class); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http; | ||
|
||
use App\Models\City; | ||
use Exception; | ||
use OpenAI; | ||
|
||
class OpenAIService | ||
{ | ||
public function getRules() | ||
{ | ||
$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(); | ||
$data = []; | ||
|
||
foreach ($cities as $city) { | ||
$data[] = ["city" => $city, "country" => $city->country, "rulesENG" => $responseENG, "rulesPL" => $responsePL]; | ||
|
||
return $data; | ||
} | ||
|
||
foreach ($data as $i) { | ||
$promptENG = "What are the legal limitations for riding electric scooters in " . $i->name . ", " . $i->country->name . "? 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 " . $i["city"] . ", " . $i["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, | ||
], | ||
], | ||
]); | ||
|
||
$i["rulesENG"] = $responseENG["choices"][0]["text"]; | ||
$i["rulesPL"] = $responsePL["choices"][0]["text"]; | ||
} | ||
} catch (Exception $e) { | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
database/migrations/2024_01_07_182205_create_rules_for_cities_table.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class() extends Migration { | ||
public function up(): void | ||
{ | ||
Schema::create("rules_for_cities", function (Blueprint $table): void { | ||
$table->id(); | ||
$table->timestamps(); | ||
|
||
$table->unsignedBigInteger("city_id"); | ||
$table->foreign("city_id") | ||
->references("id") | ||
->on("cities") | ||
->onDelete("cascade"); | ||
|
||
$table->unsignedBigInteger("country_id"); | ||
$table->foreign("country_id") | ||
->references("id") | ||
->on("countries") | ||
->onDelete("cascade"); | ||
|
||
$table->string("rulesENG"); | ||
$table->string("rulesPL;"); | ||
}); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::dropIfExists("rules_for_cities"); | ||
} | ||
}; |
This file contains 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