Skip to content

Commit

Permalink
chore: wip (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss authored Dec 23, 2023
1 parent bb0045d commit 8df37d0
Show file tree
Hide file tree
Showing 79 changed files with 790 additions and 2,055 deletions.
73 changes: 73 additions & 0 deletions app/Console/Commands/CreateMainCharacteristics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace App\Console\Commands;

use App\Jobs\ProcessCelebrities;
use App\Jobs\ProcessCountryOfOrigin;
use App\Jobs\ProcessElficTraits;
use App\Jobs\ProcessKlingonName;
use App\Jobs\ProcessLitteratureReferences;
use App\Jobs\ProcessMainCaracteristics;
use App\Jobs\ProcessMixte;
use App\Jobs\ProcessOrigins;
use App\Jobs\ProcessPersonality;
use App\Jobs\ProcessSimilarNames;
use App\Jobs\ProcessSyllabes;
use App\Models\Characteristic;
use App\Models\Name;
use Illuminate\Console\Command;
use Illuminate\Support\Str;

class CreateMainCharacteristics extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'openname:create-main-characteristics';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';

/**
* Execute the console command.
*/
public function handle(): void
{
foreach (Name::orderBy('total', 'desc')->lazy() as $name) {

if (is_null($name->characteristics)) {
continue;
}

$strings = explode(',', $name->characteristics);
foreach ($strings as $string) {
// lowercase
$lowercase = Str::lower($string);

// remove the space at the beginning and the end
$string = Str::of($lowercase)->trim()->__toString();

// remove any comma or dot at the end
$string = Str::of($string)->rtrim(',.')->__toString();

// count the number of words and skip the word if there is more than 1
$words = explode(' ', $string);
if (count($words) > 1) {
continue;
}

$characteristic = Characteristic::firstOrCreate([
'name' => $string,
]);

$name->mainCharacteristics()->syncWithoutDetaching([$characteristic->id]);
}
}
}
}
16 changes: 13 additions & 3 deletions app/Console/Commands/FetchMetaData.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
use App\Jobs\ProcessElficTraits;
use App\Jobs\ProcessKlingonName;
use App\Jobs\ProcessLitteratureReferences;
use App\Jobs\ProcessMainCaracteristics;
use App\Jobs\ProcessMixte;
use App\Jobs\ProcessOrigins;
use App\Jobs\ProcessPersonality;
use App\Jobs\ProcessSimilarNames;
use App\Jobs\ProcessSyllabes;
use App\Models\Name;
use Illuminate\Console\Command;

Expand Down Expand Up @@ -72,9 +74,17 @@ public function handle(): void
//ProcessKlingonName::dispatch($name);
}

// if (is_null($name->unisex)) {
// ProcessMixte::dispatch($name);
// }
if (is_null($name->unisex)) {
ProcessMixte::dispatch($name);
}

if ($name->syllabes === 0) {
ProcessSyllabes::dispatch($name);
}

if (is_null($name->characteristics)) {
ProcessMainCaracteristics::dispatch($name);
}
}
}
}
42 changes: 41 additions & 1 deletion app/Helpers/OpenAIHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,47 @@ public static function getUnisex(string $name): ?string
[
'role' => 'system',
'content' => <<<'PROMPT'
pour le prénom donné par l'utilisateur, indiquez si le prénom est unisexe. répondez uniquement par "oui" ou "non", sans rien d'autres, et sans les guillements bien sur.
pour le prénom donné par l'utilisateur, indiquez si le prénom est mixte/unisexe. répondez uniquement par "oui" ou "non", sans rien ajouter d'autres, et sans les guillements bien sur.
PROMPT,
], [
'role' => 'user',
'content' => $name,
],
],
]);

return $response->choices[0]->message->content;
}

public static function getSyllabes(string $name): ?string
{
$response = OpenAI::chat()->create([
'model' => 'gpt-3.5-turbo',
'messages' => [
[
'role' => 'system',
'content' => <<<'PROMPT'
pour le prénom donné par l'utilisateur, indique le nombre de syllabes. écris simplement le chiffre, sans rien d'autres.
PROMPT,
], [
'role' => 'user',
'content' => $name,
],
],
]);

return $response->choices[0]->message->content;
}

public static function getMainCharacteristics(string $name): ?string
{
$response = OpenAI::chat()->create([
'model' => 'gpt-3.5-turbo',
'messages' => [
[
'role' => 'system',
'content' => <<<'PROMPT'
pour le prénom donné par l'utilisateur, donne jusqu'à 3 termes ou qualités qui décrivent la personnalité du prénom. donne la reponse en mettant uniquement les mots, séparés par une virgule, sans rien d'autres.
PROMPT,
], [
'role' => 'user',
Expand Down
5 changes: 0 additions & 5 deletions app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,13 @@ public function create(): View
public function store(Request $request): RedirectResponse
{
$request->validate([
'first_name' => ['required', 'string', 'max:255'],
'last_name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:' . User::class],
'password' => ['required', 'confirmed', Rules\Password::defaults()],
]);

$user = (new CreateAccount(
email: $request->input('email'),
password: $request->input('password'),
firstName: $request->input('first_name'),
lastName: $request->input('last_name'),
organizationName: $request->input('organization_name'),
))->execute();

event(new Registered($user));
Expand Down
40 changes: 40 additions & 0 deletions app/Http/Controllers/SearchController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Http\Controllers;

use App\Http\ViewModels\Home\HomeViewModel;
use App\Http\ViewModels\Search\SearchViewModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\View\View;

class SearchController extends Controller
{
public function index(): View
{
$stats = Cache::remember('stats', 604800, function () {
return HomeViewModel::serverStats();
});

return view('search.index', [
'stats' => $stats,
'names' => SearchViewModel::names(),
]);
}

public function post(Request $request): View
{
$stats = Cache::remember('stats', 604800, function () {
return HomeViewModel::serverStats();
});

$term = trim($request->input('term'));
$names = SearchViewModel::names($term);
dd($names);
return view('search.index', [
'stats' => $stats,
'names' => $names,
'term' => $term,
]);
}
}
96 changes: 0 additions & 96 deletions app/Http/Controllers/Settings/SettingsLevelController.php

This file was deleted.

14 changes: 0 additions & 14 deletions app/Http/Controllers/Settings/SettingsProfileController.php

This file was deleted.

Loading

0 comments on commit 8df37d0

Please sign in to comment.