Step 1: Install package groq
Code: Select all
pip install groq
Code: Select all
pip3 install groq
Code: Select all
% pip install groq
zsh: command not found: pip
% pip3 install groq
Collecting groq
Using cached groq-0.5.0-py3-none-any.whl (75 kB)
...
...
Collecting annotated-types>=0.4.0
Using cached annotated_types-0.6.0-py3-none-any.whl (12 kB)
Installing collected packages: typing-extensions, sniffio, idna, h11, exceptiongroup, distro, certifi, annotated-types, pydantic-core, httpcore, anyio, pydantic, httpx, groq
Successfully installed
Next, generate your API Key at https://console.groq.com/keys
Step 3: Add your Groq API Key to the Environment Variable.
Code: Select all
export GROQ_API_KEY=gsk_6sVS2dqG8szzxxxxxxxxWGdyb3FYwPpuRTdJxxxxxxx5wrVSM
Code: Select all
import os
from groq import Groq
client = Groq(
api_key=os.environ.get("GROQ_API_KEY"),
)
response = client.chat.completions.create(
messages=[
{
"role": "user",
"content": "Name the capital of France",
}
],
model="llama3-8b-8192",
)
print(response.choices[0].message.content)
Code: Select all
% python3 example.py
The capital of France is Paris.
Read More: https://console.groq.com/docs/models