Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getResponseFromGroq($prompt) {
- $GROQ_API_KEY = "isi api key";
- $url = "https://api.groq.com/openai/v1/chat/completions";
- $headers = ["Content-Type: application/json","Authorization: Bearer " . $GROQ_API_KEY];
- $data = "";
- if (containsWord($prompt, "land")) {
- preg_match('/\d+/', $prompt, $matches);
- if (isset($matches[0])) {
- $data = landScreener($matches[0]);
- echo "$data";
- } else {
- $data = "No number found";
- }
- }
- $data = [
- "messages" => [
- [
- "role" => "system",
- "content" => "Your name is Xy, only answer with data, if you being ask about land data / information, you can answer with ". $data. " , you can wrap it with ```\n ```"
- ],
- [
- "role" => "user",
- "content" => $prompt
- ]
- ],
- "model" => "llama3-70b-8192",
- "temperature" => 0.5,
- "max_tokens" => 8192,
- "top_p" => 1,
- "stream" => false,
- "stop" => null
- ];
- $options = [
- CURLOPT_URL => $url,
- CURLOPT_CUSTOMREQUEST => "POST",
- CURLOPT_POSTFIELDS => json_encode($data),
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_HTTPHEADER => $headers
- ];
- $curl = curl_init();
- curl_setopt_array($curl, $options);
- $response = curl_exec($curl);
- curl_close($curl);
- $result = json_decode($response, true);
- $msg = $result['choices'][0]['message']['content'];
- $ptoken = $result['usage']['prompt_tokens'];
- $rtoken = $result['usage']['completion_tokens'];
- $ttoken = $result['usage']['total_tokens'];
- $speed = $result['usage']['total_time'];
- $final = array("$msg","`Prompt tokens: " . $ptoken . "\nCompletion tokens: " . $rtoken . "\nTotal tokens: " . $ttoken . "\nSpeed: " . $speed . " seconds` | XC");
- return $final;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement