alwilayah-logo

قناة الولاية الفضائية

Patient Medication Review

Patient Medication Review

Recommendations and Concerns:
				
					<?php
// File: openai-api.php
header('Content-Type: application/json');

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $apiKey = 'YOUR_OPENAI_API_KEY';
    $inputData = json_decode(file_get_contents('php://input'), true);

    $postData = json_encode(array(
        "model" => "text-davinci-003",
        "prompt" => $inputData['prompt'],
        "max_tokens" => 100
    ));

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://api.openai.com/v1/completions');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Authorization: Bearer ' . $apiKey
    ));

    $response = curl_exec($ch);
    if (curl_errno($ch)) {
        echo json_encode(array('error' => curl_error($ch)));
    } else {
        echo $response;
    }
    curl_close($ch);
} else {
    echo json_encode(array('error' => 'Invalid request method.'));
}
?>