From 2c1e3ff5b884dc4cc042019da90f07a951f52309 Mon Sep 17 00:00:00 2001 From: Riza Maulana Ardiyanto Date: Mon, 28 Oct 2024 21:42:20 +0700 Subject: [PATCH] fix/#823-wrong-result-openai-checklists --- core/Requirement/Openai_item.php | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/core/Requirement/Openai_item.php b/core/Requirement/Openai_item.php index 8bccc226..f420ad69 100644 --- a/core/Requirement/Openai_item.php +++ b/core/Requirement/Openai_item.php @@ -307,13 +307,15 @@ public function handle_ajax_request() { } else { // configure prompt $prompt = " + You are a content analyzer. Your task is to analyze the following content based on the given prompt. + You must start your response with either 'No:' or 'Yes:' followed by your explanation. + Do not use any other format for the yes/no response. + Prompt: {$requirement['label']} Content: {$content} - Please provide your analysis in the following format: - Yes/No: [Your Yes/No response] - Full Response: [Your detailed analysis] + Remember: Start your response with either 'Yes:' or 'No:' followed by your explanation. "; // prepare body data @@ -360,20 +362,10 @@ public function handle_ajax_request() { // Extract Yes/No response $yes_no_response = ''; - preg_match('/Yes\/No: (Yes|No)/', $api_content, $matches); - if (isset($matches[1])) { + if (preg_match('/^(Yes|No):/i', $api_content, $matches)) { $yes_no_response = strtolower(trim($matches[1])); } - // Compatibility for rare cases where the api may not follow our requested format - if (!in_array($yes_no_response, ['yes', 'no'])) { - if (stripos($api_content, "Yes") === 0) { - $yes_no_response = 'yes'; - } elseif (stripos($api_content, "Yes") === 0) { - $yes_no_response = 'no'; - } - } - if (in_array($yes_no_response, ['yes', 'no'])) { $response['yes_no'] = $yes_no_response; $response_content = '
';