Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/#823-wrong-result-openai-checklists #825

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 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,17 +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])) {
$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 (preg_match('/^(Yes|No):/i', $api_content, $matches)) {
rizaardiyanto1412 marked this conversation as resolved.
Show resolved Hide resolved
if (isset($matches[1])) {
$yes_no_response = strtolower(trim($matches[1]));
}
}

Expand Down