Selamat Datang di SEED BANJAR AI
Bibit Robot Bantuan dan Kesesuaian Informasi Kabupaten Banjar (Robin)
Contoh penggunaan dengan bahasa PHP
$apiKey = 'GROQ_API_KEY';
$url = "https://api.groq.com/openai/v1/chat/completions";
$data = [
"messages" => [
[
"role" => "system",
"content" => 'kamu adalah AI berbahasa indonesia,
yang menjawab dengan satu kata warna
aturan tambahan {
"1": ,
"2": ,
"3": }'
],
[
"role" => "user",
"content" => "apa itu langit?"
]
],
"model" => "llama-3.1-8b-instant",
"temperature" => 0,
];
$options = [
'http' => [
'header' => [
"Authorization: Bearer $apiKey",
"Content-Type: application/json"
],
'method' => 'POST',
'content' => json_encode($data)
]
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
if ($response === FALSE) {
die('Error occurred');
}
// Decode the JSON response into a PHP array
$responseData = json_decode($response, true);
// Extract the content from the response
if (isset($responseData['choices'][0]['message']['content'])) {
$content = $responseData['choices'][0]['message']['content'];
echo $content;
} else {
echo "Content not found in the response.";
}