본문 바로가기
푸닥거리

gpt-3.5-turbo api 호출

by [김경민]™ ┌(  ̄∇ ̄)┘™ 2023. 3. 8.
728x90

 

<?php
$api_key = "";
$prompt = "";

$url = "https://api.openai.com/v1/chat/completions";

$data = array(
    "model" => "gpt-3.5-turbo",
    "messages" => array(
        array(
            "role" => "user",
            "content" => $prompt
        )
    ),
    "max_tokens" => 3000,
    "temperature" => 0.5,
);

 


$data_string = json_encode($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Content-Type: application/json",
    "Authorization: Bearer $api_key",
    "Content-Length: " . strlen($data_string))
);

$output = curl_exec($ch);
curl_close($ch);
print_r($output);
?>

 

https://platform.openai.com/docs/models/gpt-4

 

OpenAI API

An API for accessing new AI models developed by OpenAI

platform.openai.com

 

728x90

댓글