diff --git a/chat_send.php b/chat_send.php index 425de5a..caf4789 100644 --- a/chat_send.php +++ b/chat_send.php @@ -54,29 +54,27 @@ $stmt->execute([$session_id, $message]); $kb_documents = search_kb($message); -$prompt = "You are a helpful assistant for Extrading, a company that sells construction materials. Please answer in ' . ($lang ?? 'en') . ' language. Answer the user\'s questions based on the provided context. If the answer is not in the context, say you don\'t know.\n\n"; +$messages = []; +$system_prompt = "You are a helpful assistant for Extrading, a company that sells construction materials. Please answer in ' . ($lang ?? 'en') . ' language. Answer the user\'s questions based on the provided context. If the answer is not in the context, say you don\'t know."; if (!empty($kb_documents)) { - $prompt .= "Context from knowledge base:\n"; + $system_prompt .= "\n\nContext from knowledge base:\n"; foreach ($kb_documents as $doc) { - $prompt .= "- Title: " . $doc['title'] . "\n"; - $prompt .= " Content: " . $doc['content'] . "\n"; + $system_prompt .= "- Title: " . $doc['title'] . "\n"; + $system_prompt .= " Content: " . $doc['content'] . "\n"; } - $prompt .= "\n"; } -$prompt .= "Conversation history:\n"; +$messages[] = ['role' => 'system', 'content' => $system_prompt]; + foreach ($history as $msg) { - $prompt .= $msg['sender'] . ": " . $msg['message'] . "\n"; + $messages[] = ['role' => $msg['sender'], 'content' => $msg['message']]; } -$prompt .= "user: " . $message . "\n"; -$prompt .= "assistant:"; +$messages[] = ['role' => 'user', 'content' => $message]; $response = LocalAIApi::createResponse([ - 'input' => [ - ['role' => 'system', 'content' => $prompt] - ] + 'input' => $messages, ]); if (!empty($response['success'])) { diff --git a/debug_price.log b/debug_price.log index b879e9b..843c577 100644 --- a/debug_price.log +++ b/debug_price.log @@ -11101,3 +11101,101 @@ Product price query executed. Found: {"price_net":"233.20","price_gross":"286.84 Found product price. Net: 233.2, Gross: 286.84 FINAL: Returning Net: 233.2, Gross: 286.84 --- +--- +START getEffectivePrice for product 1, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"1111.00","price_gross":"1366.53"} +Found product price. Net: 1111, Gross: 1366.53 +FINAL: Returning Net: 1111, Gross: 1366.53 +--- +--- +START getEffectivePrice for product 2, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"1318.05","price_gross":"1621.20"} +Found product price. Net: 1318.05, Gross: 1621.2 +FINAL: Returning Net: 1318.05, Gross: 1621.2 +--- +--- +START getEffectivePrice for product 3, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"9.95","price_gross":"12.24"} +Found product price. Net: 9.95, Gross: 12.24 +FINAL: Returning Net: 9.95, Gross: 12.24 +--- +--- +START getEffectivePrice for product 4, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"9.95","price_gross":"12.24"} +Found product price. Net: 9.95, Gross: 12.24 +FINAL: Returning Net: 9.95, Gross: 12.24 +--- +--- +START getEffectivePrice for product 5, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"68.00","price_gross":"83.64"} +Found product price. Net: 68, Gross: 83.64 +FINAL: Returning Net: 68, Gross: 83.64 +--- +--- +START getEffectivePrice for product 6, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"171.60","price_gross":"211.07"} +Found product price. Net: 171.6, Gross: 211.07 +FINAL: Returning Net: 171.6, Gross: 211.07 +--- +--- +START getEffectivePrice for product 7, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"233.20","price_gross":"286.84"} +Found product price. Net: 233.2, Gross: 286.84 +FINAL: Returning Net: 233.2, Gross: 286.84 +--- +--- +START getEffectivePrice for product 1, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"1111.00","price_gross":"1366.53"} +Found product price. Net: 1111, Gross: 1366.53 +FINAL: Returning Net: 1111, Gross: 1366.53 +--- +--- +START getEffectivePrice for product 2, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"1318.05","price_gross":"1621.20"} +Found product price. Net: 1318.05, Gross: 1621.2 +FINAL: Returning Net: 1318.05, Gross: 1621.2 +--- +--- +START getEffectivePrice for product 3, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"9.95","price_gross":"12.24"} +Found product price. Net: 9.95, Gross: 12.24 +FINAL: Returning Net: 9.95, Gross: 12.24 +--- +--- +START getEffectivePrice for product 4, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"9.95","price_gross":"12.24"} +Found product price. Net: 9.95, Gross: 12.24 +FINAL: Returning Net: 9.95, Gross: 12.24 +--- +--- +START getEffectivePrice for product 5, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"68.00","price_gross":"83.64"} +Found product price. Net: 68, Gross: 83.64 +FINAL: Returning Net: 68, Gross: 83.64 +--- +--- +START getEffectivePrice for product 6, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"171.60","price_gross":"211.07"} +Found product price. Net: 171.6, Gross: 211.07 +FINAL: Returning Net: 171.6, Gross: 211.07 +--- +--- +START getEffectivePrice for product 7, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"233.20","price_gross":"286.84"} +Found product price. Net: 233.2, Gross: 286.84 +FINAL: Returning Net: 233.2, Gross: 286.84 +---