Skip to content

Commit

Permalink
fix/#823-wrong-result-openai-checklists
Browse files Browse the repository at this point in the history
  • Loading branch information
rizaardiyanto1412 committed Oct 28, 2024
1 parent 886fa42 commit 2c1e3ff
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions core/Requirement/Openai_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = '<div class="ppch-yes-no-response">';
Expand Down

0 comments on commit 2c1e3ff

Please sign in to comment.