refactor: kb & station & terminal
This commit is contained in:
@@ -2,20 +2,18 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\KnowledgeBase;
|
||||
use App\Models\Station;
|
||||
use App\Models\Terminal;
|
||||
use App\Models\TerminalPrompt;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class TerminalSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->command->info('开始创建终端数据...');
|
||||
$this->command->info('开始创建线站、知识库和终端...');
|
||||
|
||||
// 光束线列表
|
||||
$beamlines = [
|
||||
'BL02U1' => '192.168.1.21',
|
||||
'BL07U' => '192.168.1.27',
|
||||
@@ -29,19 +27,32 @@ class TerminalSeeder extends Seeder
|
||||
'BL16U1' => '192.168.1.39',
|
||||
];
|
||||
|
||||
// 默认提示词模板(占位符由HMI端替换)
|
||||
$defaultPrompt = <<<'PROMPT'
|
||||
你是{station_id}光束线的AI助手。当前时间是{time}。请根据用户{user}的问题,提供准确的光束线操作指导、实验支持和技术咨询。你可以回答关于光束线参数、实验流程、设备状态、安全规范等方面的问题。
|
||||
你是{station_name}光束线的AI助手(终端: {terminal_name} / {terminal_code})。当前时间是{time}。请根据用户{user}的问题,提供准确的光束线操作指导、实验支持和技术咨询。你可以回答关于光束线参数、实验流程、设备状态、安全规范等方面的问题。
|
||||
PROMPT;
|
||||
|
||||
// 为每条光束线创建智慧屏终端
|
||||
$this->command->info('创建光束线智慧屏终端...');
|
||||
// 创建通用知识库(全局,不关联线站)
|
||||
$this->command->info('创建通用知识库...');
|
||||
KnowledgeBase::create(['name' => '通用知识库', 'description' => '全站通用的规章制度和管理文档', 'status' => 'active']);
|
||||
|
||||
foreach ($beamlines as $beamline => $ipAddress) {
|
||||
// 创建线站
|
||||
$station = Station::firstOrCreate(['name' => $beamline]);
|
||||
|
||||
// 创建线站专属知识库并关联
|
||||
$kb = KnowledgeBase::create([
|
||||
'name' => "{$beamline} 知识库",
|
||||
'description' => "{$beamline} 光束线专用文档",
|
||||
'status' => 'active',
|
||||
]);
|
||||
$station->knowledgeBases()->attach($kb);
|
||||
|
||||
// 创建终端
|
||||
$terminal = Terminal::create([
|
||||
'name' => "{$beamline} 智慧屏",
|
||||
'code' => "SCREEN-{$beamline}",
|
||||
'ip_address' => $ipAddress,
|
||||
'station_id' => $beamline,
|
||||
'station_id' => $station->id,
|
||||
'diagram_url' => 'https://ssrf.9z.work/scada/demo.html',
|
||||
'is_online' => in_array($beamline, ['BL02U1', 'BL07U', 'BL08U', 'BL13U', 'BL15U']),
|
||||
'last_online_at' => in_array($beamline, ['BL02U1', 'BL07U', 'BL08U', 'BL13U', 'BL15U'])
|
||||
@@ -49,7 +60,6 @@ PROMPT;
|
||||
: now()->subHours(rand(1, 24)),
|
||||
]);
|
||||
|
||||
// 为每个终端创建提示词
|
||||
TerminalPrompt::create([
|
||||
'terminal_id' => $terminal->id,
|
||||
'prompt_template' => $defaultPrompt,
|
||||
@@ -57,12 +67,9 @@ PROMPT;
|
||||
]);
|
||||
}
|
||||
|
||||
$this->command->info('终端数据创建完成!');
|
||||
$this->command->newLine();
|
||||
$this->command->info('=== 生成的终端摘要 ===');
|
||||
$this->command->info('总终端数量: ' . Terminal::count());
|
||||
$this->command->info(' - 在线终端: ' . Terminal::where('is_online', true)->count());
|
||||
$this->command->info(' - 离线终端: ' . Terminal::where('is_online', false)->count());
|
||||
$this->command->info(' - 配置提示词的终端: ' . TerminalPrompt::count());
|
||||
$this->command->info('线站/知识库/终端创建完成!');
|
||||
$this->command->info(' - 线站: ' . Station::count());
|
||||
$this->command->info(' - 知识库: ' . KnowledgeBase::count());
|
||||
$this->command->info(' - 终端: ' . Terminal::count());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user