feat(ai): add per-character AI model assignment and identity profiles
Implements deterministic model resolution (column → env map → pool → default) and adds AI identity fields to characters. Migration backfills existing rows with deterministic defaults. Controller uses resolved model and identity block in system prompts for contextual conversations.
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* Adds the per-character AI profile to "characters".
|
||||
*
|
||||
* Every citizen can now carry its own model override plus the identity
|
||||
* used by the conversational persona: age, gender, short biography and
|
||||
* personality. Existing rows are backfilled with a deterministic default
|
||||
* persona so no character speaks without one.
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Personality pool used for the backfill (kept inline so this
|
||||
* migration stays a self-contained snapshot).
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
private const PERSONALITIES = [
|
||||
'Extrovertido e curioso, adora puxar conversa com quem passa.',
|
||||
'Tranquilo e observador, fala pouco mas escuta tudo com atenção.',
|
||||
'Bem-humorado e espirituoso, brinca com todo mundo por perto.',
|
||||
'Sério e direto, vai ao ponto sem rodeios.',
|
||||
'Gentil e prestativo, sempre oferece ajuda antes de perguntarem.',
|
||||
'Aventureiro e barulhento, vive contando histórias da cidade.',
|
||||
];
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('characters', function (Blueprint $table): void {
|
||||
$table->string('ai_model', 120)->nullable()->after('name');
|
||||
$table->unsignedSmallInteger('ai_age')->nullable();
|
||||
$table->string('ai_gender', 24)->nullable();
|
||||
$table->string('ai_personality', 255)->nullable();
|
||||
$table->string('ai_bio', 500)->nullable();
|
||||
});
|
||||
|
||||
DB::table('characters')
|
||||
->whereNull('ai_personality')
|
||||
->orderBy('id')
|
||||
->get()
|
||||
->each(function (object $row): void {
|
||||
DB::table('characters')->where('id', $row->id)->update([
|
||||
'ai_age' => 18 + (7 * (int) $row->id) % 50,
|
||||
'ai_personality' => self::PERSONALITIES[(int) $row->id % count(self::PERSONALITIES)],
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('characters', function (Blueprint $table): void {
|
||||
$table->dropColumn(['ai_model', 'ai_age', 'ai_gender', 'ai_personality', 'ai_bio']);
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user