2500 lines
45 KiB
JavaScript
2500 lines
45 KiB
JavaScript
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const AiModels = db.ai_models;
|
|
|
|
const SystemPrompts = db.system_prompts;
|
|
|
|
const ChatSessions = db.chat_sessions;
|
|
|
|
const ChatMessages = db.chat_messages;
|
|
|
|
const MessageAttachments = db.message_attachments;
|
|
|
|
const ApiKeys = db.api_keys;
|
|
|
|
const UsageEvents = db.usage_events;
|
|
|
|
const ModerationRules = db.moderation_rules;
|
|
|
|
const FeatureFlags = db.feature_flags;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const AiModelsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"provider": "openai",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"model_name": "gpt-4o-mini",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"display_name": "4o Mini",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"supports_streaming": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"context_window_tokens": 128000,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"input_cost_per_1k": 0.15,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"output_cost_per_1k": 0.6,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"provider": "openai",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"model_name": "gpt-4.1",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"display_name": "GPT 4.1",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"supports_streaming": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"context_window_tokens": 128000,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"input_cost_per_1k": 3.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"output_cost_per_1k": 12.0,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"provider": "anthropic",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"model_name": "claude-3-5-sonnet",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"display_name": "Claude Sonnet 3.5",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"supports_streaming": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"context_window_tokens": 200000,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"input_cost_per_1k": 3.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"output_cost_per_1k": 15.0,
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const SystemPromptsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Dark Minimal Assistant",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "You are a direct, concise assistant. Use a professional tone. Ask clarifying questions when needed. Do not fabricate.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"safety_mode": "balanced",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_default": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "No Fluff Mode",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "Answer with only the essential information. Use short bullet points when helpful.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"safety_mode": "strict",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_default": false,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Strict Compliance",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "Follow policy strictly. Refuse disallowed requests. Provide safe alternatives when refusing.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"safety_mode": "strict",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_default": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const ChatSessionsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "Productivity shortcuts",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "deleted",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_pinned": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ui_theme": "dark",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"accent_color": "neon-green",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2026-03-30T18:25:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_message_at": new Date('2026-03-30T18:29:30Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "Quick coding help",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "archived",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_pinned": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ui_theme": "dark",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"accent_color": "neon-green",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2026-03-27T16:50:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_message_at": new Date('2026-03-27T16:55:20Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "Prompt experiments",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "archived",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_pinned": false,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ui_theme": "dark",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"accent_color": "electric-blue",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2026-03-20T10:05:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_message_at": new Date('2026-03-20T10:22:40Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const ChatMessagesData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sender_role": "tool",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "Give me three ways to speed up my daily workflow.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_streamed": false,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sequence_index": 1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"prompt_tokens": 18,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"completion_tokens": 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"cost": 0.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sent_at": new Date('2026-03-30T18:25:10Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"moderation_flag": "blocked",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sender_role": "system",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "1) Batch similar tasks into focus blocks. 2) Use templates for repeatable work. 3) Automate reminders and recurring checklists.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_streamed": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sequence_index": 2,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"prompt_tokens": 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"completion_tokens": 46,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"cost": 0.01,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sent_at": new Date('2026-03-30T18:25:15Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"moderation_flag": "blocked",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sender_role": "assistant",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "Write a TypeScript function to debounce an async call.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_streamed": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sequence_index": 1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"prompt_tokens": 12,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"completion_tokens": 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"cost": 0.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sent_at": new Date('2026-03-27T16:50:10Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"moderation_flag": "blocked",
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const MessageAttachmentsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"attachment_type": "file",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"caption": "debounce-example.ts reference",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"attachment_type": "file",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"caption": "workflow sketch image",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"attachment_type": "image",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"caption": "notes.txt",
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const ApiKeysData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"label": "Root Key",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"key_prefix": "dgpt_live_root",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"key_hash": "hash_root_9f2c1b",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_used_at": new Date('2026-03-30T18:29:40Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"expires_at": new Date('2027-03-30T00:00:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"label": "Ops Dashboard Key",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"key_prefix": "dgpt_live_ops",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"key_hash": "hash_ops_1a7b3d",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_used_at": new Date('2026-03-29T09:11:10Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"expires_at": new Date('2026-12-31T00:00:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"label": "Moderation Tool Key",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"key_prefix": "dgpt_live_mod",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"key_hash": "hash_mod_77c0aa",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_used_at": new Date('2026-03-29T12:16:20Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"expires_at": new Date('2026-10-01T00:00:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const UsageEventsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"event_type": "message_created",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"input_tokens": 18,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"output_tokens": 46,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"cost": 0.01,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ip_address": "203.0.113.10",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"user_agent": "Mozilla/5.0 Chrome",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"occurred_at": new Date('2026-03-30T18:25:15Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"event_type": "message_created",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"input_tokens": 12,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"output_tokens": 33,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"cost": 0.01,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ip_address": "198.51.100.22",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"user_agent": "Mozilla/5.0 Safari",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"occurred_at": new Date('2026-03-27T16:50:15Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"event_type": "message_created",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"input_tokens": 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"output_tokens": 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"cost": 0.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ip_address": "203.0.113.55",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"user_agent": "Mozilla/5.0 Chrome",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"occurred_at": new Date('2026-03-20T10:05:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const ModerationRulesData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "PII Detection Keywords",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"rule_type": "keyword",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"pattern": "social security number,passport number,credit card number",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"action": "flag",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"priority": 10,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Hate Slur Blocklist",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"rule_type": "regex",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"pattern": "hate_speech",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"action": "flag",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"priority": 100,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Self Harm Escalation",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"rule_type": "category",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"pattern": "self_harm",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"action": "block",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"priority": 90,
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const FeatureFlagsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "streaming_responses",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_enabled": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Enable token streaming for assistant responses.",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "attachments_upload",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_enabled": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Allow users to attach files or images to messages.",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "prompt_library",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_enabled": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Enable system prompt presets selection.",
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateChatSessionWithUser() {
|
|
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ChatSession0 = await ChatSessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (ChatSession0?.setUser)
|
|
{
|
|
await
|
|
ChatSession0.
|
|
setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ChatSession1 = await ChatSessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (ChatSession1?.setUser)
|
|
{
|
|
await
|
|
ChatSession1.
|
|
setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ChatSession2 = await ChatSessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (ChatSession2?.setUser)
|
|
{
|
|
await
|
|
ChatSession2.
|
|
setUser(relatedUser2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateChatSessionWithAi_model() {
|
|
|
|
const relatedAi_model0 = await AiModels.findOne({
|
|
offset: Math.floor(Math.random() * (await AiModels.count())),
|
|
});
|
|
const ChatSession0 = await ChatSessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (ChatSession0?.setAi_model)
|
|
{
|
|
await
|
|
ChatSession0.
|
|
setAi_model(relatedAi_model0);
|
|
}
|
|
|
|
const relatedAi_model1 = await AiModels.findOne({
|
|
offset: Math.floor(Math.random() * (await AiModels.count())),
|
|
});
|
|
const ChatSession1 = await ChatSessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (ChatSession1?.setAi_model)
|
|
{
|
|
await
|
|
ChatSession1.
|
|
setAi_model(relatedAi_model1);
|
|
}
|
|
|
|
const relatedAi_model2 = await AiModels.findOne({
|
|
offset: Math.floor(Math.random() * (await AiModels.count())),
|
|
});
|
|
const ChatSession2 = await ChatSessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (ChatSession2?.setAi_model)
|
|
{
|
|
await
|
|
ChatSession2.
|
|
setAi_model(relatedAi_model2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateChatSessionWithSystem_prompt() {
|
|
|
|
const relatedSystem_prompt0 = await SystemPrompts.findOne({
|
|
offset: Math.floor(Math.random() * (await SystemPrompts.count())),
|
|
});
|
|
const ChatSession0 = await ChatSessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (ChatSession0?.setSystem_prompt)
|
|
{
|
|
await
|
|
ChatSession0.
|
|
setSystem_prompt(relatedSystem_prompt0);
|
|
}
|
|
|
|
const relatedSystem_prompt1 = await SystemPrompts.findOne({
|
|
offset: Math.floor(Math.random() * (await SystemPrompts.count())),
|
|
});
|
|
const ChatSession1 = await ChatSessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (ChatSession1?.setSystem_prompt)
|
|
{
|
|
await
|
|
ChatSession1.
|
|
setSystem_prompt(relatedSystem_prompt1);
|
|
}
|
|
|
|
const relatedSystem_prompt2 = await SystemPrompts.findOne({
|
|
offset: Math.floor(Math.random() * (await SystemPrompts.count())),
|
|
});
|
|
const ChatSession2 = await ChatSessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (ChatSession2?.setSystem_prompt)
|
|
{
|
|
await
|
|
ChatSession2.
|
|
setSystem_prompt(relatedSystem_prompt2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateChatMessageWithChat_session() {
|
|
|
|
const relatedChat_session0 = await ChatSessions.findOne({
|
|
offset: Math.floor(Math.random() * (await ChatSessions.count())),
|
|
});
|
|
const ChatMessage0 = await ChatMessages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (ChatMessage0?.setChat_session)
|
|
{
|
|
await
|
|
ChatMessage0.
|
|
setChat_session(relatedChat_session0);
|
|
}
|
|
|
|
const relatedChat_session1 = await ChatSessions.findOne({
|
|
offset: Math.floor(Math.random() * (await ChatSessions.count())),
|
|
});
|
|
const ChatMessage1 = await ChatMessages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (ChatMessage1?.setChat_session)
|
|
{
|
|
await
|
|
ChatMessage1.
|
|
setChat_session(relatedChat_session1);
|
|
}
|
|
|
|
const relatedChat_session2 = await ChatSessions.findOne({
|
|
offset: Math.floor(Math.random() * (await ChatSessions.count())),
|
|
});
|
|
const ChatMessage2 = await ChatMessages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (ChatMessage2?.setChat_session)
|
|
{
|
|
await
|
|
ChatMessage2.
|
|
setChat_session(relatedChat_session2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateMessageAttachmentWithChat_message() {
|
|
|
|
const relatedChat_message0 = await ChatMessages.findOne({
|
|
offset: Math.floor(Math.random() * (await ChatMessages.count())),
|
|
});
|
|
const MessageAttachment0 = await MessageAttachments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (MessageAttachment0?.setChat_message)
|
|
{
|
|
await
|
|
MessageAttachment0.
|
|
setChat_message(relatedChat_message0);
|
|
}
|
|
|
|
const relatedChat_message1 = await ChatMessages.findOne({
|
|
offset: Math.floor(Math.random() * (await ChatMessages.count())),
|
|
});
|
|
const MessageAttachment1 = await MessageAttachments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (MessageAttachment1?.setChat_message)
|
|
{
|
|
await
|
|
MessageAttachment1.
|
|
setChat_message(relatedChat_message1);
|
|
}
|
|
|
|
const relatedChat_message2 = await ChatMessages.findOne({
|
|
offset: Math.floor(Math.random() * (await ChatMessages.count())),
|
|
});
|
|
const MessageAttachment2 = await MessageAttachments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (MessageAttachment2?.setChat_message)
|
|
{
|
|
await
|
|
MessageAttachment2.
|
|
setChat_message(relatedChat_message2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateApiKeyWithUser() {
|
|
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ApiKey0 = await ApiKeys.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (ApiKey0?.setUser)
|
|
{
|
|
await
|
|
ApiKey0.
|
|
setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ApiKey1 = await ApiKeys.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (ApiKey1?.setUser)
|
|
{
|
|
await
|
|
ApiKey1.
|
|
setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ApiKey2 = await ApiKeys.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (ApiKey2?.setUser)
|
|
{
|
|
await
|
|
ApiKey2.
|
|
setUser(relatedUser2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateUsageEventWithUser() {
|
|
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const UsageEvent0 = await UsageEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (UsageEvent0?.setUser)
|
|
{
|
|
await
|
|
UsageEvent0.
|
|
setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const UsageEvent1 = await UsageEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (UsageEvent1?.setUser)
|
|
{
|
|
await
|
|
UsageEvent1.
|
|
setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const UsageEvent2 = await UsageEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (UsageEvent2?.setUser)
|
|
{
|
|
await
|
|
UsageEvent2.
|
|
setUser(relatedUser2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateUsageEventWithChat_session() {
|
|
|
|
const relatedChat_session0 = await ChatSessions.findOne({
|
|
offset: Math.floor(Math.random() * (await ChatSessions.count())),
|
|
});
|
|
const UsageEvent0 = await UsageEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (UsageEvent0?.setChat_session)
|
|
{
|
|
await
|
|
UsageEvent0.
|
|
setChat_session(relatedChat_session0);
|
|
}
|
|
|
|
const relatedChat_session1 = await ChatSessions.findOne({
|
|
offset: Math.floor(Math.random() * (await ChatSessions.count())),
|
|
});
|
|
const UsageEvent1 = await UsageEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (UsageEvent1?.setChat_session)
|
|
{
|
|
await
|
|
UsageEvent1.
|
|
setChat_session(relatedChat_session1);
|
|
}
|
|
|
|
const relatedChat_session2 = await ChatSessions.findOne({
|
|
offset: Math.floor(Math.random() * (await ChatSessions.count())),
|
|
});
|
|
const UsageEvent2 = await UsageEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (UsageEvent2?.setChat_session)
|
|
{
|
|
await
|
|
UsageEvent2.
|
|
setChat_session(relatedChat_session2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateUsageEventWithChat_message() {
|
|
|
|
const relatedChat_message0 = await ChatMessages.findOne({
|
|
offset: Math.floor(Math.random() * (await ChatMessages.count())),
|
|
});
|
|
const UsageEvent0 = await UsageEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (UsageEvent0?.setChat_message)
|
|
{
|
|
await
|
|
UsageEvent0.
|
|
setChat_message(relatedChat_message0);
|
|
}
|
|
|
|
const relatedChat_message1 = await ChatMessages.findOne({
|
|
offset: Math.floor(Math.random() * (await ChatMessages.count())),
|
|
});
|
|
const UsageEvent1 = await UsageEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (UsageEvent1?.setChat_message)
|
|
{
|
|
await
|
|
UsageEvent1.
|
|
setChat_message(relatedChat_message1);
|
|
}
|
|
|
|
const relatedChat_message2 = await ChatMessages.findOne({
|
|
offset: Math.floor(Math.random() * (await ChatMessages.count())),
|
|
});
|
|
const UsageEvent2 = await UsageEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (UsageEvent2?.setChat_message)
|
|
{
|
|
await
|
|
UsageEvent2.
|
|
setChat_message(relatedChat_message2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await AiModels.bulkCreate(AiModelsData);
|
|
|
|
|
|
|
|
|
|
await SystemPrompts.bulkCreate(SystemPromptsData);
|
|
|
|
|
|
|
|
|
|
await ChatSessions.bulkCreate(ChatSessionsData);
|
|
|
|
|
|
|
|
|
|
await ChatMessages.bulkCreate(ChatMessagesData);
|
|
|
|
|
|
|
|
|
|
await MessageAttachments.bulkCreate(MessageAttachmentsData);
|
|
|
|
|
|
|
|
|
|
await ApiKeys.bulkCreate(ApiKeysData);
|
|
|
|
|
|
|
|
|
|
await UsageEvents.bulkCreate(UsageEventsData);
|
|
|
|
|
|
|
|
|
|
await ModerationRules.bulkCreate(ModerationRulesData);
|
|
|
|
|
|
|
|
|
|
await FeatureFlags.bulkCreate(FeatureFlagsData);
|
|
|
|
|
|
await Promise.all([
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateChatSessionWithUser(),
|
|
|
|
|
|
|
|
|
|
await associateChatSessionWithAi_model(),
|
|
|
|
|
|
|
|
|
|
await associateChatSessionWithSystem_prompt(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateChatMessageWithChat_session(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateMessageAttachmentWithChat_message(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateApiKeyWithUser(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateUsageEventWithUser(),
|
|
|
|
|
|
|
|
|
|
await associateUsageEventWithChat_session(),
|
|
|
|
|
|
|
|
|
|
await associateUsageEventWithChat_message(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await queryInterface.bulkDelete('ai_models', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('system_prompts', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('chat_sessions', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('chat_messages', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('message_attachments', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('api_keys', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('usage_events', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('moderation_rules', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('feature_flags', null, {});
|
|
|
|
|
|
},
|
|
}; |