Skip to main content

Groq LLM plugin for elizaOS - Python implementation for fast inference

Project description

elizaos-plugin-groq

Python implementation of the Groq LLM plugin for elizaOS.

Features

  • 🐍 Pythonic API - Clean, intuitive async interface
  • 📦 Type hints - Full typing with Pydantic models
  • 🔄 Auto-retry - Automatic rate limit and error handling
  • 🧪 Well tested - Comprehensive test coverage

Installation

pip install elizaos-plugin-groq

For development:

pip install elizaos-plugin-groq[dev]

Usage

Basic Text Generation

import asyncio
from elizaos_plugin_groq import GroqClient, GenerateTextParams

async def main():
    async with GroqClient(api_key="your-api-key") as client:
        # Generate text with the large model
        response = await client.generate_text_large(
            GenerateTextParams(
                prompt="Explain quantum computing in simple terms.",
                temperature=0.7,
                max_tokens=1024,
            )
        )
        print(response)

asyncio.run(main())

Audio Transcription

from elizaos_plugin_groq import GroqClient, TranscriptionParams

async def transcribe_audio(audio_data: bytes) -> str:
    async with GroqClient(api_key="your-api-key") as client:
        text = await client.transcribe(
            TranscriptionParams(
                audio=audio_data,
                format="mp3",
            )
        )
        return text

Text-to-Speech

from elizaos_plugin_groq import GroqClient, TextToSpeechParams

async def generate_speech(text: str) -> bytes:
    async with GroqClient(api_key="your-api-key") as client:
        audio = await client.text_to_speech(
            TextToSpeechParams(text=text)
        )
        return audio

JSON Object Generation

from elizaos_plugin_groq import GroqClient, GenerateObjectParams

async def generate_json() -> dict:
    async with GroqClient(api_key="your-api-key") as client:
        obj = await client.generate_object(
            GenerateObjectParams(
                prompt="Generate a user profile with name, age, and hobbies",
                temperature=0.7,
            )
        )
        return obj

Configuration

Create a client with custom configuration:

from elizaos_plugin_groq import GroqClient, GroqConfig

config = GroqConfig(
    api_key="your-api-key",
    base_url="https://api.groq.com/openai/v1",
    small_model="llama-3.1-8b-instant",
    large_model="llama-3.3-70b-versatile",
    tts_model="playai-tts",
    tts_voice="Chip-PlayAI",
    transcription_model="distil-whisper-large-v3-en",
)

client = GroqClient(api_key="", config=config)

Error Handling

The package provides typed exceptions:

from elizaos_plugin_groq import GroqClient, GroqError, GroqErrorCode

async def safe_generate():
    async with GroqClient(api_key="your-api-key") as client:
        try:
            response = await client.generate_text_large(params)
            return response
        except GroqError as e:
            if e.code == GroqErrorCode.RATE_LIMIT_EXCEEDED:
                print(f"Rate limited, retry after {e.retry_after}s")
            elif e.code == GroqErrorCode.INVALID_API_KEY:
                print("Invalid API key")
            elif e.is_retryable:
                print(f"Retryable error: {e}")
            raise

elizaOS Integration

Use the plugin with elizaOS:

from elizaos_plugin_groq import get_plugin

# Get the plugin definition
plugin = get_plugin()
print(f"Plugin: {plugin['name']} v{plugin['version']}")

Development

# Clone and install dev dependencies
git clone https://github.com/elizaos-plugins/plugin-groq.git
cd plugin-groq/python
pip install -e ".[dev]"

# Run tests
pytest

# Run linting
ruff check .
ruff format .

# Run type checking
mypy elizaos_plugin_groq

Requirements

  • Python >= 3.11
  • httpx >= 0.28.0
  • pydantic >= 2.10.0
  • tiktoken >= 0.8.0

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

elizaos_plugin_groq-2.0.0a4.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

elizaos_plugin_groq-2.0.0a4-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file elizaos_plugin_groq-2.0.0a4.tar.gz.

File metadata

  • Download URL: elizaos_plugin_groq-2.0.0a4.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for elizaos_plugin_groq-2.0.0a4.tar.gz
Algorithm Hash digest
SHA256 741c624d89f3d19be8efdd9863c44fd05e1110eb095a54261a48db389e589d84
MD5 9cdf76bdeaeca64e73d7c9902c34de6c
BLAKE2b-256 297c36061b699cfa0b59fc57dbb68548a9ae00c14c65a3301df871ef6ddb40ce

See more details on using hashes here.

File details

Details for the file elizaos_plugin_groq-2.0.0a4-py3-none-any.whl.

File metadata

File hashes

Hashes for elizaos_plugin_groq-2.0.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 7929d7d8423ba8793bd945052ac5b49b24d45c4bced8296bc3b356e70afd4bb9
MD5 b816539115acc0f14f84396479356098
BLAKE2b-256 d869ffabeec638e4f765f25ccdb9908cdf4bf89f5ba86d1d54b523416d7cc31e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page