LiveKit Groq Plugin

1.5.4 · active · verified Thu Apr 16

livekit-plugins-groq is a Python plugin that enables LiveKit Agents to utilize Groq's high-speed inference for Large Language Models (LLM), Speech-to-Text (STT), and Text-to-Speech (TTS). It is actively maintained as part of the livekit-agents ecosystem, with releases generally aligning with the livekit-agents project, currently at version 1.5.4.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a LiveKit Agent session using Groq as the Large Language Model (LLM) provider. It highlights the essential import and configuration steps, including setting the `GROQ_API_KEY` environment variable. Groq can also be configured for STT and TTS.

import os
from livekit.agents import AgentSession, JobContext, WorkerOptions
from livekit.plugins import groq

# Set your Groq API key (e.g., in a .env file or directly as an environment variable)
os.environ['GROQ_API_KEY'] = os.environ.get('GROQ_API_KEY', 'your_groq_api_key_here')

async def entrypoint(ctx: JobContext):
    session = AgentSession(
        llm=groq.LLM(
            model="llama3-8b-8192", # or 'llama-3.3-70b-versatile'
            temperature=0.7
        ),
        # Optionally add Groq STT and TTS
        # stt=groq.STT(model="whisper-large-v3-turbo"),
        # tts=groq.TTS(model="playai-tts", voice="Arista-PlayAI"),
        # ... other agent session configurations like vad, turn_handling
    )

    # In a real application, you'd handle participant events and process audio/text
    # For a minimal quickstart, this demonstrates LLM initialization.
    # For example:
    # while True:
    #     user_message = await session.stt.recognize_one_utterance()
    #     if user_message:
    #         reply_text = await session.llm.generate_reply(messages=[{'role': 'user', 'content': user_message.text}])
    #         await session.tts.synthesize(reply_text)

    print("Groq LLM initialized within AgentSession. Ensure GROQ_API_KEY is set.")

# Example of how you might run this (typically part of a larger LiveKit Agent server setup)
if __name__ == "__main__":
    # This part is illustrative; actual LiveKit Agent deployment uses AgentServer.start()
    # You would normally run your agent via `python -m your_agent_file dev`
    print("To run a full LiveKit Agent, please refer to the LiveKit Agents documentation.")
    print("Ensure GROQ_API_KEY is set in your environment or .env file.")

view raw JSON →