Load system prompt from persistent file
- Load system prompt from data/system-prompt.txt (persistent) - Fallback to AI_SYSTEM_PROMPT env variable - Fallback to hardcoded default - File can be edited without rebuilding container - Includes default UlfBot/SchrottBot personality Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
16
src/index.ts
16
src/index.ts
@@ -1,5 +1,6 @@
|
||||
import 'dotenv/config';
|
||||
import { Telegraf, Context } from 'telegraf';
|
||||
import { readFileSync, existsSync } from 'fs';
|
||||
import { MarkovChain } from './markov.js';
|
||||
import { generateAIResponse, maskApiKey, getDefaultBaseUrl, getProviderModels } from './ai.js';
|
||||
import {
|
||||
@@ -27,7 +28,20 @@ const bot = new Telegraf(process.env.BOT_TOKEN!);
|
||||
const AI_DEFAULT_API_KEY = process.env.AI_DEFAULT_API_KEY || '';
|
||||
const AI_DEFAULT_BASE_URL = process.env.AI_DEFAULT_BASE_URL || 'https://api.openai.com/v1';
|
||||
const AI_DEFAULT_MODEL = process.env.AI_DEFAULT_MODEL || 'gpt-4o-mini';
|
||||
const AI_SYSTEM_PROMPT = process.env.AI_SYSTEM_PROMPT || 'Du bist ein freundlicher Chat-Bot in einer Telegram-Gruppe. Antworte kurz und prägnant auf Deutsch.';
|
||||
|
||||
// System prompt: load from file or fallback to env/default
|
||||
const SYSTEM_PROMPT_FILE = 'data/system-prompt.txt';
|
||||
function loadSystemPrompt(): string {
|
||||
try {
|
||||
if (existsSync(SYSTEM_PROMPT_FILE)) {
|
||||
return readFileSync(SYSTEM_PROMPT_FILE, 'utf-8').trim();
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Could not load system-prompt.txt, using fallback');
|
||||
}
|
||||
return process.env.AI_SYSTEM_PROMPT || 'Du bist ein freundlicher Chat-Bot in einer Telegram-Gruppe. Antworte kurz und prägnant auf Deutsch.';
|
||||
}
|
||||
const AI_SYSTEM_PROMPT = loadSystemPrompt();
|
||||
|
||||
// In-memory cache of chains
|
||||
const chains = new Map<number, MarkovChain>();
|
||||
|
||||
Reference in New Issue
Block a user