#!/usr/bin/env node /** * Add DeepSeek LLM Configuration * This script adds a DeepSeek configuration to the llm_configs table */ import { pool, query } from '../config.js'; import dotenv from 'dotenv'; dotenv.config(); async function addDeepSeekConfig() { console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'); console.log(' Adding DeepSeek LLM Configuration'); console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'); try { // Check if DeepSeek config already exists const existing = await query( `SELECT id FROM 5Why_llm_configs WHERE provider = 'DeepSeek' LIMIT 1` ); if (existing.length > 0) { console.log('✅ DeepSeek configuration already exists (ID:', existing[0].id, ')'); console.log(' Skipping...\n'); return; } // Get API key from environment or leave empty const apiKey = process.env.DEEPSEEK_API_KEY || ''; if (!apiKey) { console.log('⚠️ Warning: DEEPSEEK_API_KEY not found in .env'); console.log(' You will need to add the API key in the admin panel\n'); } // First, deactivate all existing configs await query('UPDATE 5Why_llm_configs SET is_active = 0'); // Insert DeepSeek configuration const result = await query( `INSERT INTO 5Why_llm_configs (provider, api_url, api_key, model_name, temperature, max_tokens, timeout, is_active) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [ 'DeepSeek', process.env.DEEPSEEK_API_URL || 'https://api.deepseek.com', apiKey || null, process.env.DEEPSEEK_MODEL || 'deepseek-chat', 0.7, 6000, 120000, 1 // Set as active ] ); console.log('✅ DeepSeek configuration added successfully!'); console.log(' Config ID:', result.insertId); console.log(' Provider: DeepSeek'); console.log(' Model: deepseek-chat'); console.log(' Status: Active\n'); console.log('📝 Next steps:'); console.log(' 1. Go to Admin Panel > LLM 配置'); console.log(' 2. Add your DeepSeek API key if not already set'); console.log(' 3. Test the connection'); console.log(' 4. Start using DeepSeek for 5 Why analysis!\n'); } catch (error) { console.error('❌ Error adding DeepSeek configuration:', error.message); process.exit(1); } finally { await pool.end(); } } // Run the script addDeepSeekConfig() .then(() => { console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'); console.log(' Configuration Complete'); console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'); process.exit(0); }) .catch((error) => { console.error('Fatal error:', error); process.exit(1); });