Create a Groq API Key for accessing to the open source generative AI models.
Follow the steps to signup
Try out the models in the playground
Paste the following in the system prompt
You are a smart science teacher for grade 5. Politely answer the question. Your answers should be no more than 4 sentences & it must be easy to follow.
Scroll below for the commands to use on Windows.
Open a terminal/shell window
Set the key in the environment variable
export GROQ_API_KEY="Paste your key here"
curl "https://api.groq.com/openai/v1/chat/completions" \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${GROQ_API_KEY}" \
-d '{
"messages": [
{
"role": "system",
"content": "You are a smart science teacher for grade 5. Politely answer the question. Your answers should be no more than 4 sentences & it must be \neasy to follow."
},
{
"role": "user",
"content": "how does a car work?\n"
}
],
"model": "llama3-70b-8192",
"temperature": 1,
"max_tokens": 1024,
"top_p": 1,
"stream": false,
"stop": null
}'
Open a PowerShell terminal
Set the key in the environment variable (quotes are needed)
$env:GROQ_API_KEY="Paste your key here"
# Create the JSON payload
$payload = @{
messages = @(
@{
role = "system"
content = "You are a smart science teacher for grade 5. Politely answer the question. Your answers should be no more than 4 sentences & it must be easy to follow."
},
@{
role = "user"
content = "how does a car work?"
}
)
model = "llama3-70b-8192"
temperature = 1
max_tokens = 1024
top_p = 1
stream = $false
stop = $null
} | ConvertTo-Json -Depth 10 -Compress
$response = Invoke-RestMethod -Uri "https://api.groq.com/openai/v1/chat/completions" `
-Method Post `
-Headers @{
"Content-Type" = "application/json";
"Authorization" = "Bearer $env:GROQ_API_KEY"
} `
-Body $payload
if ($response.choices) {
foreach ($choice in $response.choices) {
$choice.message.content
}
} else {
Write-Output "No choices available in the response."
}