ai-ui/cli/init_assistant.php
2024-09-09 10:22:45 +02:00

35 lines
851 B
PHP

<?php
if (PHP_SAPI != 'cli') {
exit('PHP SAPI must be cli');
}
require(__DIR__ . '/../vendor/autoload.php');
foreach (require __DIR__ . '/../env.php' as $key => $val) {
putenv("{$key}={$val}");
}
$db = new PDO('sqlite:' . getenv('SQLITE_DB'));
$query =<<<SQL
CREATE TABLE IF NOT EXISTS "chat_assistant" (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
title VARCHAR(255) NOT NULL,
model VARCHAR(64) NOT NULL,
system_prompt TEXT NOT NULL,
temperature REAL NOT NULL DEFAULT 0,
top_p REAL NOT NULL 0,
"default" INTEGER NOT NULL DEFAULT 0,
foreign key (user_id) references "user" (id) on delete cascade on update cascade
);
SQL;
if ($db->exec($query) === false) {
$error = $db->errorInfo();
throw new RuntimeException("Query failed with error : {$error[2]}");
}
echo "Assistant table created.\n";