-
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.
Merge branch '#10-regulations-for-escooters' of https://github.com/bl…
…umilksoftware/escooters into #10-regulations-for-escooters
- Loading branch information
Showing
4 changed files
with
225 additions
and
6 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
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 | ||
|
||
} | ||
|
||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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