$prompt1, 'max_tokens' => 1000, 'temperature' => 0, ]; // Create the request data for prompt 2 $data2 = [ 'prompt' => $prompt2, 'max_tokens' => 1000, 'temperature' => 0, ]; $headers = [ 'Authorization: Bearer ' . $api_key, 'Content-Type: application/json', ]; // Send the request for prompt 1 and get the response $response1 = file_get_contents($api_url, false, stream_context_create([ 'http' => [ 'method' => 'POST', 'header' => implode("\r\n", $headers), 'content' => json_encode($data1), ], ])); // Send the request for prompt 2 and get the response $response2 = file_get_contents($api_url, false, stream_context_create([ 'http' => [ 'method' => 'POST', 'header' => implode("\r\n", $headers), 'content' => json_encode($data2), ], ])); // Check for errors if ($response1 === false || $response2 === false) { echo 'Error occurred while fetching the ratings.'; return null; } // Print the entire API responses for debugging echo "API Response for Prompt 1:
" . htmlspecialchars($response1) . "
"; echo "API Response for Prompt 2:
" . htmlspecialchars($response2) . "
"; // Decode the JSON responses $responseData1 = json_decode($response1, true); $responseData2 = json_decode($response2, true); // Extract the ratings from the responses if available $ratings1 = isset($responseData1['choices'][0]['text']) ? $responseData1['choices'][0]['text'] : null; $ratings2 = isset($responseData2['choices'][0]['text']) ? $responseData2['choices'][0]['text'] : null; return [$ratings1, $ratings2]; } // Main script if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['food_item'])) { $foodItem = $_POST['food_item']; // Call the function to get the ratings for both prompts $ratings = getRatings($foodItem); if ($ratings !== null) { list($ratings1, $ratings2) = $ratings; echo "Ratings for $foodItem (Healthiness):"; echo $ratings1; echo "
" . "Ratings for $foodItem (Nutritional Values):"; echo $ratings2; } else { echo "No ratings available for $foodItem."; } } ?> Food Ratings

Food Ratings