diff --git a/admin.php b/admin.php
index b78cec4..1f396fa 100644
--- a/admin.php
+++ b/admin.php
@@ -28,6 +28,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$head_ads = $_POST['head_ads'] ?? '';
$body_ads = $_POST['body_ads'] ?? '';
$openai_api_key = $_POST['openai_api_key'] ?? '';
+ $openai_model = $_POST['openai_model'] ?? 'gpt-4o-mini';
$site_name = $_POST['site_name'] ?? 'TikTok Live AI Assistant';
$default_language = $_POST['default_language'] ?? 'en';
@@ -57,6 +58,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
'head_ads' => $head_ads,
'body_ads' => $body_ads,
'openai_api_key' => $openai_api_key,
+ 'openai_model' => $openai_model,
'site_name' => $site_name,
'site_icon' => $site_icon,
'site_favicon' => $site_favicon,
@@ -77,6 +79,7 @@ $settings = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
$head_ads = $settings['head_ads'] ?? '';
$body_ads = $settings['body_ads'] ?? '';
$openai_api_key = $settings['openai_api_key'] ?? '';
+$openai_model = $settings['openai_model'] ?? 'gpt-4o-mini';
$site_name = $settings['site_name'] ?? 'TikTok Live AI Assistant';
$site_icon = $settings['site_icon'] ?? 'assets/images/logo.png';
$site_favicon = $settings['site_favicon'] ?? 'favicon.ico';
@@ -165,12 +168,22 @@ $default_language = $settings['default_language'] ?? 'en';
+
+
+
+
+
Choose which model to use with your API Key.
+
+
diff --git a/ai/LocalAIApi.php b/ai/LocalAIApi.php
index 0c97839..fd131c7 100644
--- a/ai/LocalAIApi.php
+++ b/ai/LocalAIApi.php
@@ -41,9 +41,9 @@ class LocalAIApi
];
}
- // Use custom model if provided, else use default from config
+ // Use custom model if provided, else use default from site_settings or config
if (!isset($payload['model']) || $payload['model'] === '') {
- $payload['model'] = !empty($cfg['openai_api_key']) ? 'gpt-4o-mini' : $cfg['default_model'];
+ $payload['model'] = !empty($cfg['openai_model']) ? $cfg['openai_model'] : (!empty($cfg['openai_api_key']) ? 'gpt-4o-mini' : $cfg['default_model']);
}
// If we have a custom OpenAI API key, we call OpenAI directly (synchronously)
@@ -386,18 +386,22 @@ class LocalAIApi
throw new RuntimeException('Invalid AI config format: expected array');
}
- // Try to load custom API key from DB if possible
+ // Try to load custom API key and model from DB if possible
$dbConfig = __DIR__ . '/../db/config.php';
if (file_exists($dbConfig)) {
try {
require_once $dbConfig;
$pdo = db();
- $stmt = $pdo->query("SELECT setting_value FROM site_settings WHERE setting_key = 'openai_api_key' LIMIT 1");
- $val = $stmt->fetchColumn();
- $cfg['openai_api_key'] = $val ?: null;
+
+ // Fetch all relevant settings in one go
+ $stmt = $pdo->query("SELECT setting_key, setting_value FROM site_settings WHERE setting_key IN ('openai_api_key', 'openai_model')");
+ while ($row = $stmt->fetch()) {
+ $cfg[$row['setting_key']] = $row['setting_value'] ?: null;
+ }
} catch (Exception $e) {
- // Fail silently, fallback to proxy
+ // Fail silently, fallback to defaults
$cfg['openai_api_key'] = null;
+ $cfg['openai_model'] = null;
}
}
diff --git a/ai/config.php b/ai/config.php
index c890698..d9c8e76 100644
--- a/ai/config.php
+++ b/ai/config.php
@@ -24,7 +24,7 @@ if (
if ($key === '') {
continue;
}
- $value = trim($value, "\"' ");
+ $value = trim($value, "' ");
if (getenv($key) === false || getenv($key) === '') {
putenv("{$key}={$value}");
}
@@ -46,7 +46,7 @@ return [
'project_id' => $projectId,
'project_uuid' => $projectUuid,
'project_header' => 'project-uuid',
- 'default_model' => 'gpt-5-mini',
+ 'default_model' => 'gpt-4o-mini',
'timeout' => 30,
'verify_tls' => true,
-];
+];
\ No newline at end of file
diff --git a/api/chat.php b/api/chat.php
index dbe026c..1274e46 100644
--- a/api/chat.php
+++ b/api/chat.php
@@ -32,7 +32,7 @@ try {
// 3. Call AI API
$response = LocalAIApi::createResponse([
- 'model' => 'gpt-4o-mini',
+ // Model is handled by LocalAIApi defaults/site_settings if omitted
'input' => [
['role' => 'system', 'content' => $systemPrompt],
['role' => 'user', 'content' => $message],
@@ -61,4 +61,4 @@ try {
} catch (Exception $e) {
error_log("Chat Error: " . $e->getMessage());
echo json_encode(['reply' => "An internal error occurred."]);
-}
+}
\ No newline at end of file
diff --git a/api/telegram_webhook.php b/api/telegram_webhook.php
index fa4899c..e3e2094 100644
--- a/api/telegram_webhook.php
+++ b/api/telegram_webhook.php
@@ -19,7 +19,7 @@ if (empty($text)) {
}
// Get Telegram Token from DB
-$stmt = db()->query("SELECT setting_value FROM settings WHERE setting_key = 'telegram_token'");
+$stmt = db()->query("SELECT setting_value FROM site_settings WHERE setting_key = 'telegram_token'");
$token = $stmt->fetchColumn();
if (!$token) {
@@ -64,7 +64,7 @@ try {
// 2. Call AI
$response = LocalAIApi::createResponse([
- 'model' => 'gpt-4o-mini',
+ // Model is handled by LocalAIApi defaults/site_settings if omitted
'input' => [
['role' => 'system', 'content' => $systemPrompt],
['role' => 'user', 'content' => $text],
@@ -88,4 +88,4 @@ try {
} catch (Exception $e) {
error_log("Telegram Webhook Error: " . $e->getMessage());
-}
+}
\ No newline at end of file
diff --git a/db/migrations/add_openai_model_setting.sql b/db/migrations/add_openai_model_setting.sql
new file mode 100644
index 0000000..7b62526
--- /dev/null
+++ b/db/migrations/add_openai_model_setting.sql
@@ -0,0 +1 @@
+INSERT INTO site_settings (setting_key, setting_value) VALUES ('openai_model', 'gpt-4o-mini') ON DUPLICATE KEY UPDATE setting_key=setting_key;
diff --git a/db/migrations/faqs_and_messages.sql b/db/migrations/faqs_and_messages.sql
new file mode 100644
index 0000000..08a00cb
--- /dev/null
+++ b/db/migrations/faqs_and_messages.sql
@@ -0,0 +1,13 @@
+CREATE TABLE IF NOT EXISTS faqs (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ keywords TEXT NOT NULL,
+ answer TEXT NOT NULL,
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
+);
+
+CREATE TABLE IF NOT EXISTS messages (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ user_message TEXT NOT NULL,
+ ai_response TEXT NOT NULL,
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
+);
diff --git a/languages/en.php b/languages/en.php
index 5525dd7..64ceea6 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -30,6 +30,7 @@ return [
'save_settings' => 'Save All Settings',
'site_settings' => 'Site Settings',
'openai_key' => 'OpenAI API Key',
+ 'openai_model' => 'OpenAI Model',
'head_scripts' => 'Head Scripts',
'body_scripts' => 'Body Scripts',
'site_name' => 'Site Name',
@@ -40,4 +41,4 @@ return [
'personality_funny' => 'Funny',
'personality_serious' => 'Serious',
'personality_expert' => 'Expert',
-];
\ No newline at end of file
+];
diff --git a/languages/id.php b/languages/id.php
index 314a327..3752735 100644
--- a/languages/id.php
+++ b/languages/id.php
@@ -30,6 +30,7 @@ return [
'save_settings' => 'Simpan Semua Pengaturan',
'site_settings' => 'Pengaturan Situs',
'openai_key' => 'Kunci API OpenAI',
+ 'openai_model' => 'Model OpenAI',
'head_scripts' => 'Skrip Head',
'body_scripts' => 'Skrip Body',
'site_name' => 'Nama Situs',
@@ -40,4 +41,4 @@ return [
'personality_funny' => 'Lucu',
'personality_serious' => 'Serius',
'personality_expert' => 'Pakar',
-];
\ No newline at end of file
+];