OpenAI API fix

This commit is contained in:
Flatlogic Bot 2025-12-29 12:32:25 +00:00
parent 3d232d5225
commit 8a8f06ab2b
2 changed files with 108 additions and 12 deletions

View File

@ -54,29 +54,27 @@ $stmt->execute([$session_id, $message]);
$kb_documents = search_kb($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)) { if (!empty($kb_documents)) {
$prompt .= "Context from knowledge base:\n"; $system_prompt .= "\n\nContext from knowledge base:\n";
foreach ($kb_documents as $doc) { foreach ($kb_documents as $doc) {
$prompt .= "- Title: " . $doc['title'] . "\n"; $system_prompt .= "- Title: " . $doc['title'] . "\n";
$prompt .= " Content: " . $doc['content'] . "\n"; $system_prompt .= " Content: " . $doc['content'] . "\n";
} }
$prompt .= "\n";
} }
$prompt .= "Conversation history:\n"; $messages[] = ['role' => 'system', 'content' => $system_prompt];
foreach ($history as $msg) { foreach ($history as $msg) {
$prompt .= $msg['sender'] . ": " . $msg['message'] . "\n"; $messages[] = ['role' => $msg['sender'], 'content' => $msg['message']];
} }
$prompt .= "user: " . $message . "\n"; $messages[] = ['role' => 'user', 'content' => $message];
$prompt .= "assistant:";
$response = LocalAIApi::createResponse([ $response = LocalAIApi::createResponse([
'input' => [ 'input' => $messages,
['role' => 'system', 'content' => $prompt]
]
]); ]);
if (!empty($response['success'])) { if (!empty($response['success'])) {

View File

@ -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 Found product price. Net: 233.2, Gross: 286.84
FINAL: Returning 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
---