How do I create an instance of a Groq LLM?
# ask-ai
m
How do I create an instance of a Groq LLM?
t
Thanks for reaching out, Alexander. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you’re looking to create an instance of a Groq LLM, here’s a simple step-by-step guide to get you started: 1. Install the LiveKit Groq Plugin: Just run
pip install "livekit-agents[groq]~=1.2"
to grab the package you need. 2. Set Up Authentication: Head over to the Groq Console to get your Groq API key, then pop it into your
.env
file like this:
GROQ_API_KEY=<your-groq-api-key>
. 3. Initialize the Groq LLM Instance: Create your instance using the
groq.LLM
class. Here’s a quick example:
Copy code
from livekit.plugins import groq

llm_instance = groq.LLM(
    model="llama3-8b-8192",
    temperature=0.8,
    parallel_tool_calls=True,
    tool_choice="auto"
)
4. Integrate into an Agent Session: You can mix the LLM with other cool services like STT and TTS to build a full pipeline. For example:
Copy code
session = AgentSession(
    stt=groq.STT(model="whisper-large-v3-turbo"),
    llm=llm_instance,
    tts=groq.TTS(model="playai-tts", voice="Cheyenne-PlayAI"),
    vad=silero.VAD.load()
)
If you want to dive deeper, check out the plugin reference or explore the Groq Voice Assistant GitHub repository. Happy coding! Sources: Groq LLM integration guide | LiveKit Docs | Groq and LiveKit | LiveKit Docs | Large language model (LLM) integrations | LiveKit Docs | livekit-plugins/livekit-plugins-groq/livekit/plugins/groq/tts.py | Groq integration guide | LiveKit Docs
m
how would I chat / request a chat completion from groq in say an RPC call?
t
If you want to request a chat completion from Groq LLM using an RPC call, you can easily do that through the Groq API endpoint, which works just like OpenAI’s. Here’s a friendly guide on how to set up your request: 1. Set Up the API Key: Make sure your
GROQ_API_KEY
is ready—either set in your environment or included in the request headers. 2. Make an HTTP POST Request: Use the endpoint
<GROQ_API_BASE_URL>/openai/v1/chat/completions
. Your request body should look something like this:
Copy code
{
  "model": "llama-3.3-70b-versatile",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": "What is the weather today?"
    }
  ],
  "temperature": 0.7,
  "max_tokens": 100
}
3. Example Using Python: Here’s a quick Python snippet using the
requests
library to get you started:
Copy code
import requests

url = "<GROQ_API_BASE_URL>/openai/v1/chat/completions"
headers = {
    "Authorization": f"Bearer {your_api_key}",
    "Content-Type": "application/json"
}
data = {
    "model": "llama-3.3-70b-versatile",
    "messages": [
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is the weather today?"}
    ],
    "temperature": 0.7,
    "max_tokens": 100
}

response = requests.post(url, headers=headers, json=data)
print(response.json())
This method makes it super simple to plug Groq LLM into any system that supports HTTP requests, including RPC frameworks. If you run into any questions or want a hand with anything else, just let me know—I’m here to help!