move tokens to config

This commit is contained in:
team 1
2026-04-26 11:00:13 +02:00
parent 00ebe2fd73
commit 38ae9d528f
5 changed files with 216 additions and 37 deletions

View File

@@ -36,136 +36,180 @@ final class AgentRunnerConfig
public function getOptimizedShopQueryTrimCharacters(): string
{
return " \t\n\r\0\x0B\"'`";
return $this->getString('optimized_shop_query_trim_characters', " \t\n\r\0\x0B\"'`");
}
private function getInt(string $key, int $default): int
{
$value = $this->config[$key] ?? $default;
$value = $this->value($key, $default);
return is_numeric($value) ? (int) $value : $default;
}
private function getString(string $key, string $default): string
{
$value = $this->config[$key] ?? $default;
$value = $this->value($key, $default);
return is_string($value) && $value !== '' ? $value : $default;
}
/**
* @param string[] $default
* @return string[]
*/
private function getStringList(string $key, array $default): array
{
$value = $this->value($key, $default);
if (!is_array($value)) {
return $default;
}
$out = [];
foreach ($value as $item) {
if (!is_scalar($item)) {
continue;
}
$item = trim((string) $item);
if ($item !== '') {
$out[] = $item;
}
}
return $out !== [] ? $out : $default;
}
private function value(string $key, mixed $default): mixed
{
$current = $this->config;
foreach (explode('.', $key) as $segment) {
if (!is_array($current) || !array_key_exists($segment, $current)) {
return $default;
}
$current = $current[$segment];
}
return $current;
}
public function getEmptyPromptMessage(): string
{
return '❌ Empty prompt.';
return $this->getString('messages.empty_prompt', '❌ Empty prompt.');
}
public function getAnalyzeRequestMessage(): string
{
return 'Ich analysiere deine Anfrage...';
return $this->getString('messages.analyze_request', 'Ich analysiere deine Anfrage...');
}
public function getCheckInternetSourcesMessage(): string
{
return 'Ich prüfe auf Internetquellen...';
return $this->getString('messages.check_internet_sources', 'Ich prüfe auf Internetquellen...');
}
public function getRetrieveKnowledgeMessage(): string
{
return 'Ich hole relevante Daten aus meinem RAG-Wissen...';
return $this->getString('messages.retrieve_knowledge', 'Ich hole relevante Daten aus meinem RAG-Wissen...');
}
public function getOptimizeSearchMessage(): string
{
return 'Ich optimiere die Recherche...';
return $this->getString('messages.optimize_search', 'Ich optimiere die Recherche...');
}
public function getFetchSearchDataMessageTemplate(): string
{
return 'Ich rufe Recherchedaten ab (type: %s)';
return $this->getString('messages.fetch_search_data_template', 'Ich rufe Recherchedaten ab (type: %s)');
}
public function getAnalyzeAllInformationMessage(): string
{
return 'Ich analysiere alle Informationen...';
return $this->getString('messages.analyze_all_information', 'Ich analysiere alle Informationen...');
}
public function getThinkingWhileStreamingMessage(): string
{
return 'Denke nach...';
return $this->getString('messages.thinking_while_streaming', 'Denke nach...');
}
public function getNoLlmDataReceivedMessage(): string
{
return '❌ Es wurden keine Daten vom LLM empfangen.';
return $this->getString('messages.no_llm_data_received', '❌ Es wurden keine Daten vom LLM empfangen.');
}
public function getGenericInternalErrorMessage(): string
{
return '❌ Bei der Verarbeitung der Anfrage ist ein interner Fehler aufgetreten.';
return $this->getString('messages.generic_internal_error', '❌ Bei der Verarbeitung der Anfrage ist ein interner Fehler aufgetreten.');
}
public function getDebugInternalErrorPrefix(): string
{
return '❌ Interner Fehler: ';
return $this->getString('messages.debug_internal_error_prefix', '❌ Interner Fehler: ');
}
public function getExternalUrlSourceLabel(): string
{
return 'Externe URL';
return $this->getString('source_labels.external_url', 'Externe URL');
}
public function getRagKnowledgeSourceLabel(): string
{
return 'RAG Wissen';
return $this->getString('source_labels.rag_knowledge', 'RAG Wissen');
}
public function getConversationHistorySourceLabel(): string
{
return 'Chatverlauf';
return $this->getString('source_labels.conversation_history', 'Chatverlauf');
}
public function getShopSystemSourceLabel(): string
{
return 'Shopsystem';
return $this->getString('source_labels.shop_system', 'Shopsystem');
}
public function getExtendedShopSearchSourceLabel(): string
{
return 'Erweiterte Shopsuche';
return $this->getString('source_labels.extended_shop_search', 'Erweiterte Shopsuche');
}
public function getUsedSourcesPrefix(): string
{
return 'Genutzte Quellen: ';
return $this->getString('source_labels.used_sources_prefix', 'Genutzte Quellen: ');
}
public function getSourcesPrefix(): string
{
return 'Quellen: ';
return $this->getString('source_labels.sources_prefix', 'Quellen: ');
}
public function getSourceBadgeHtmlTemplate(): string
{
return '<span class="badge bg-info text-black">%s</span>';
return $this->getString('html.source_badge_template', '<span class="badge bg-info text-black">%s</span>');
}
public function getErrorHtmlTemplate(): string
{
return '<div class="retriex-alert retriex-alert--error"><div class="retriex-alert__icon">❌</div><div class="retriex-alert__content"><div class="retriex-alert__title">Hinweis</div><div class="retriex-alert__text">%s</div></div></div>' . "\n";
return $this->getString('html.error_template', '<div class="retriex-alert retriex-alert--error"><div class="retriex-alert__icon">❌</div><div class="retriex-alert__content"><div class="retriex-alert__title">Hinweis</div><div class="retriex-alert__text">%s</div></div></div>' . "\n");
}
public function getThinkHtmlTemplate(): string
{
return '<span class="text-info think">%s</span>' . "\n";
return $this->getString('html.think_template', '<span class="text-info think">%s</span>' . "\n");
}
public function getInfoHtmlTemplate(): string
{
return "\n\n" . '<span class="text-info fw-bolder">%s</span>' . "\n";
return $this->getString('html.info_template', "\n\n" . '<span class="text-info fw-bolder">%s</span>' . "\n");
}
public function getDebugHtmlTemplate(): string
{
return "\n\nDEBUG: <code>%s</code>\n";
return $this->getString('html.debug_template', "\n\nDEBUG: <code>%s</code>\n");
}
public function getShopPrompt(string $prompt, string $commerceHistoryContext = ''): string
@@ -200,7 +244,7 @@ final class AgentRunnerConfig
*/
public function getShopPromptRules(): array
{
return [
return $this->getStringList('shop_prompt.rules', [
'- Output only the final search query.',
'- Always convert relevant search terms to their singular form.',
'- No introduction, no explanation, no quotation marks.',
@@ -215,7 +259,7 @@ final class AgentRunnerConfig
'- Look for terms such as Testomat, Horiba, Tritromat, or words like indicator.',
'- If the current user input is vague or referential, use the recent conversation context only as support.',
'- Do not output words that only describe conversation flow, such as "same", "again", "also", or "like above".',
];
]);
}
/**
@@ -223,34 +267,34 @@ final class AgentRunnerConfig
*/
public function getConversationContextRules(): array
{
return [
return $this->getStringList('shop_prompt.conversation_context_rules', [
'- The current user input has highest priority.',
'- Use the recent conversation context only to resolve omitted references.',
'- Use it only for product carry-over, brand carry-over, model carry-over, or variant follow-ups.',
'- Do not revive older products unless the current user input clearly refers to them.',
'- If the current input starts a new topic, ignore older product context.',
'- Prefer the most recent product reference over older ones.',
];
]);
}
public function getShopPromptIntro(): string
{
return 'Generate a short search query for Shopware 6 from the following user input text.';
return $this->getString('shop_prompt.intro', 'Generate a short search query for Shopware 6 from the following user input text.');
}
public function getShopPromptOutputFormatBlock(): string
{
return "Output format:\nKeyword1 Keyword2 Keyword3";
return $this->getString('shop_prompt.output_format_block', "Output format:\nKeyword1 Keyword2 Keyword3");
}
public function getRecentConversationContextLabel(): string
{
return 'RECENT CONVERSATION CONTEXT';
return $this->getString('shop_prompt.recent_conversation_context_label', 'RECENT CONVERSATION CONTEXT');
}
public function getCurrentUserInputLabel(): string
{
return 'CURRENT USER INPUT';
return $this->getString('shop_prompt.current_user_input_label', 'CURRENT USER INPUT');
}
private function buildRulesBlock(array $rules, string $headline = 'Rules:'): string