Mantap
This commit is contained in:
parent
3f421e9a53
commit
0c23b971b3
15
admin.php
15
admin.php
@ -28,6 +28,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$head_ads = $_POST['head_ads'] ?? '';
|
$head_ads = $_POST['head_ads'] ?? '';
|
||||||
$body_ads = $_POST['body_ads'] ?? '';
|
$body_ads = $_POST['body_ads'] ?? '';
|
||||||
$openai_api_key = $_POST['openai_api_key'] ?? '';
|
$openai_api_key = $_POST['openai_api_key'] ?? '';
|
||||||
|
$openai_model = $_POST['openai_model'] ?? 'gpt-4o-mini';
|
||||||
$site_name = $_POST['site_name'] ?? 'TikTok Live AI Assistant';
|
$site_name = $_POST['site_name'] ?? 'TikTok Live AI Assistant';
|
||||||
$default_language = $_POST['default_language'] ?? 'en';
|
$default_language = $_POST['default_language'] ?? 'en';
|
||||||
|
|
||||||
@ -57,6 +58,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
'head_ads' => $head_ads,
|
'head_ads' => $head_ads,
|
||||||
'body_ads' => $body_ads,
|
'body_ads' => $body_ads,
|
||||||
'openai_api_key' => $openai_api_key,
|
'openai_api_key' => $openai_api_key,
|
||||||
|
'openai_model' => $openai_model,
|
||||||
'site_name' => $site_name,
|
'site_name' => $site_name,
|
||||||
'site_icon' => $site_icon,
|
'site_icon' => $site_icon,
|
||||||
'site_favicon' => $site_favicon,
|
'site_favicon' => $site_favicon,
|
||||||
@ -77,6 +79,7 @@ $settings = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
|
|||||||
$head_ads = $settings['head_ads'] ?? '';
|
$head_ads = $settings['head_ads'] ?? '';
|
||||||
$body_ads = $settings['body_ads'] ?? '';
|
$body_ads = $settings['body_ads'] ?? '';
|
||||||
$openai_api_key = $settings['openai_api_key'] ?? '';
|
$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_name = $settings['site_name'] ?? 'TikTok Live AI Assistant';
|
||||||
$site_icon = $settings['site_icon'] ?? 'assets/images/logo.png';
|
$site_icon = $settings['site_icon'] ?? 'assets/images/logo.png';
|
||||||
$site_favicon = $settings['site_favicon'] ?? 'favicon.ico';
|
$site_favicon = $settings['site_favicon'] ?? 'favicon.ico';
|
||||||
@ -165,12 +168,22 @@ $default_language = $settings['default_language'] ?? 'en';
|
|||||||
<hr class="border-secondary my-2">
|
<hr class="border-secondary my-2">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-12">
|
<div class="col-md-6">
|
||||||
<label for="openai_api_key" class="form-label fw-semibold text-secondary small"><?= __('openai_key') ?></label>
|
<label for="openai_api_key" class="form-label fw-semibold text-secondary small"><?= __('openai_key') ?></label>
|
||||||
<input type="password" name="openai_api_key" id="openai_api_key" class="form-control" placeholder="sk-..." value="<?= htmlspecialchars($openai_api_key) ?>">
|
<input type="password" name="openai_api_key" id="openai_api_key" class="form-control" placeholder="sk-..." value="<?= htmlspecialchars($openai_api_key) ?>">
|
||||||
<div class="form-text text-muted">If left empty, the application will use the Flatlogic AI Proxy.</div>
|
<div class="form-text text-muted">If left empty, the application will use the Flatlogic AI Proxy.</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label for="openai_model" class="form-label fw-semibold text-secondary small"><?= __('openai_model') ?></label>
|
||||||
|
<select name="openai_model" id="openai_model" class="form-select">
|
||||||
|
<option value="gpt-4o-mini" <?= $openai_model === 'gpt-4o-mini' ? 'selected' : '' ?>>GPT-4o Mini (Default)</option>
|
||||||
|
<option value="o3-mini" <?= $openai_model === 'o3-mini' ? 'selected' : '' ?>>o3-mini (Reasoning)</option>
|
||||||
|
<option value="gpt-4o" <?= $openai_model === 'gpt-4o' ? 'selected' : '' ?>>GPT-4o (High Quality)</option>
|
||||||
|
</select>
|
||||||
|
<div class="form-text text-muted">Choose which model to use with your API Key.</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<label for="head_ads" class="form-label fw-semibold text-secondary small"><?= __('head_scripts') ?></label>
|
<label for="head_ads" class="form-label fw-semibold text-secondary small"><?= __('head_scripts') ?></label>
|
||||||
<textarea name="head_ads" id="head_ads" rows="4" class="form-control" placeholder="Paste your <head> scripts here..."><?= htmlspecialchars($head_ads) ?></textarea>
|
<textarea name="head_ads" id="head_ads" rows="4" class="form-control" placeholder="Paste your <head> scripts here..."><?= htmlspecialchars($head_ads) ?></textarea>
|
||||||
|
|||||||
@ -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'] === '') {
|
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)
|
// 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');
|
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';
|
$dbConfig = __DIR__ . '/../db/config.php';
|
||||||
if (file_exists($dbConfig)) {
|
if (file_exists($dbConfig)) {
|
||||||
try {
|
try {
|
||||||
require_once $dbConfig;
|
require_once $dbConfig;
|
||||||
$pdo = db();
|
$pdo = db();
|
||||||
$stmt = $pdo->query("SELECT setting_value FROM site_settings WHERE setting_key = 'openai_api_key' LIMIT 1");
|
|
||||||
$val = $stmt->fetchColumn();
|
// Fetch all relevant settings in one go
|
||||||
$cfg['openai_api_key'] = $val ?: null;
|
$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) {
|
} catch (Exception $e) {
|
||||||
// Fail silently, fallback to proxy
|
// Fail silently, fallback to defaults
|
||||||
$cfg['openai_api_key'] = null;
|
$cfg['openai_api_key'] = null;
|
||||||
|
$cfg['openai_model'] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,7 +24,7 @@ if (
|
|||||||
if ($key === '') {
|
if ($key === '') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$value = trim($value, "\"' ");
|
$value = trim($value, "' ");
|
||||||
if (getenv($key) === false || getenv($key) === '') {
|
if (getenv($key) === false || getenv($key) === '') {
|
||||||
putenv("{$key}={$value}");
|
putenv("{$key}={$value}");
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ return [
|
|||||||
'project_id' => $projectId,
|
'project_id' => $projectId,
|
||||||
'project_uuid' => $projectUuid,
|
'project_uuid' => $projectUuid,
|
||||||
'project_header' => 'project-uuid',
|
'project_header' => 'project-uuid',
|
||||||
'default_model' => 'gpt-5-mini',
|
'default_model' => 'gpt-4o-mini',
|
||||||
'timeout' => 30,
|
'timeout' => 30,
|
||||||
'verify_tls' => true,
|
'verify_tls' => true,
|
||||||
];
|
];
|
||||||
@ -32,7 +32,7 @@ try {
|
|||||||
|
|
||||||
// 3. Call AI API
|
// 3. Call AI API
|
||||||
$response = LocalAIApi::createResponse([
|
$response = LocalAIApi::createResponse([
|
||||||
'model' => 'gpt-4o-mini',
|
// Model is handled by LocalAIApi defaults/site_settings if omitted
|
||||||
'input' => [
|
'input' => [
|
||||||
['role' => 'system', 'content' => $systemPrompt],
|
['role' => 'system', 'content' => $systemPrompt],
|
||||||
['role' => 'user', 'content' => $message],
|
['role' => 'user', 'content' => $message],
|
||||||
@ -61,4 +61,4 @@ try {
|
|||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
error_log("Chat Error: " . $e->getMessage());
|
error_log("Chat Error: " . $e->getMessage());
|
||||||
echo json_encode(['reply' => "An internal error occurred."]);
|
echo json_encode(['reply' => "An internal error occurred."]);
|
||||||
}
|
}
|
||||||
@ -19,7 +19,7 @@ if (empty($text)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get Telegram Token from DB
|
// 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();
|
$token = $stmt->fetchColumn();
|
||||||
|
|
||||||
if (!$token) {
|
if (!$token) {
|
||||||
@ -64,7 +64,7 @@ try {
|
|||||||
|
|
||||||
// 2. Call AI
|
// 2. Call AI
|
||||||
$response = LocalAIApi::createResponse([
|
$response = LocalAIApi::createResponse([
|
||||||
'model' => 'gpt-4o-mini',
|
// Model is handled by LocalAIApi defaults/site_settings if omitted
|
||||||
'input' => [
|
'input' => [
|
||||||
['role' => 'system', 'content' => $systemPrompt],
|
['role' => 'system', 'content' => $systemPrompt],
|
||||||
['role' => 'user', 'content' => $text],
|
['role' => 'user', 'content' => $text],
|
||||||
@ -88,4 +88,4 @@ try {
|
|||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
error_log("Telegram Webhook Error: " . $e->getMessage());
|
error_log("Telegram Webhook Error: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
1
db/migrations/add_openai_model_setting.sql
Normal file
1
db/migrations/add_openai_model_setting.sql
Normal file
@ -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;
|
||||||
13
db/migrations/faqs_and_messages.sql
Normal file
13
db/migrations/faqs_and_messages.sql
Normal file
@ -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
|
||||||
|
);
|
||||||
@ -30,6 +30,7 @@ return [
|
|||||||
'save_settings' => 'Save All Settings',
|
'save_settings' => 'Save All Settings',
|
||||||
'site_settings' => 'Site Settings',
|
'site_settings' => 'Site Settings',
|
||||||
'openai_key' => 'OpenAI API Key',
|
'openai_key' => 'OpenAI API Key',
|
||||||
|
'openai_model' => 'OpenAI Model',
|
||||||
'head_scripts' => 'Head Scripts',
|
'head_scripts' => 'Head Scripts',
|
||||||
'body_scripts' => 'Body Scripts',
|
'body_scripts' => 'Body Scripts',
|
||||||
'site_name' => 'Site Name',
|
'site_name' => 'Site Name',
|
||||||
@ -40,4 +41,4 @@ return [
|
|||||||
'personality_funny' => 'Funny',
|
'personality_funny' => 'Funny',
|
||||||
'personality_serious' => 'Serious',
|
'personality_serious' => 'Serious',
|
||||||
'personality_expert' => 'Expert',
|
'personality_expert' => 'Expert',
|
||||||
];
|
];
|
||||||
|
|||||||
@ -30,6 +30,7 @@ return [
|
|||||||
'save_settings' => 'Simpan Semua Pengaturan',
|
'save_settings' => 'Simpan Semua Pengaturan',
|
||||||
'site_settings' => 'Pengaturan Situs',
|
'site_settings' => 'Pengaturan Situs',
|
||||||
'openai_key' => 'Kunci API OpenAI',
|
'openai_key' => 'Kunci API OpenAI',
|
||||||
|
'openai_model' => 'Model OpenAI',
|
||||||
'head_scripts' => 'Skrip Head',
|
'head_scripts' => 'Skrip Head',
|
||||||
'body_scripts' => 'Skrip Body',
|
'body_scripts' => 'Skrip Body',
|
||||||
'site_name' => 'Nama Situs',
|
'site_name' => 'Nama Situs',
|
||||||
@ -40,4 +41,4 @@ return [
|
|||||||
'personality_funny' => 'Lucu',
|
'personality_funny' => 'Lucu',
|
||||||
'personality_serious' => 'Serius',
|
'personality_serious' => 'Serius',
|
||||||
'personality_expert' => 'Pakar',
|
'personality_expert' => 'Pakar',
|
||||||
];
|
];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user