Use Cases

Groq's compound systems excel at a wide range of use cases, particularly when real-time information is required.

Real-time Fact Checker and News Agent

Your application needs to answer questions or provide information that requires up-to-the-minute knowledge, such as:

  • Latest news
  • Current stock prices
  • Recent events
  • Weather updates

Building and maintaining your own web scraping or search API integration is complex and time-consuming.

Solution with Compound Beta

Simply send the user's query to compound-beta. If the query requires current information beyond its training data, it will automatically trigger its built-in web search tool to fetch relevant, live data before formulating the answer.

Why It's Great

  • Get access to real-time information instantly without writing any extra code for search integration
  • Leverage Groq's speed for a real-time, responsive experience

Code Example

Python
import os
from groq import Groq

# Ensure your GROQ_API_KEY is set as an environment variable
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))

user_query = "What were the main highlights from the latest Apple keynote event?"
# Or: "What's the current weather in San Francisco?"
# Or: "Summarize the latest developments in fusion energy research this week."

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": user_query,
        }
    ],
    # The *only* change needed: Specify the compound model!
    model="compound-beta",
)

print(f"Query: {user_query}")
print(f"Compound Beta Response:\n{chat_completion.choices[0].message.content}")

# You might also inspect chat_completion.choices[0].message.executed_tools
# if you want to see if/which tool was used, though it's not necessary.

Natural Language Calculator and Code Extractor

You want users to perform calculations, run simple data manipulations, or execute small code snippets using natural language commands within your application, without building a dedicated parser or execution environment.

Solution with Compound Beta

Frame the user's request as a task involving computation or code. compound-beta-mini can recognize these requests and use its secure code execution tool to compute the result.

Why It's Great

  • Effortlessly add computational capabilities
  • Users can ask things like:
    • "What's 15% of $540?"
    • "Calculate the standard deviation of [10, 12, 11, 15, 13]"
    • "Run this python code: print('Hello from Compound Beta!')"

Code Example

Python
import os
from groq import Groq

client = Groq(api_key=os.environ.get("GROQ_API_KEY"))

# Example 1: Calculation
computation_query = "Calculate the monthly payment for a $30,000 loan over 5 years at 6% annual interest."

# Example 2: Simple code execution
code_query = "What is the output of this Python code snippet: `data = {'a': 1, 'b': 2}; print(data.keys())`"

# Choose one query to run
selected_query = computation_query

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "system",
            "content": "You are a helpful assistant capable of performing calculations and executing simple code when asked.",
        },
        {
            "role": "user",
            "content": selected_query,
        }
    ],
    # Use the compound model
    model="compound-beta-mini",
)

print(f"Query: {selected_query}")
print(f"Compound Beta Response:\n{chat_completion.choices[0].message.content}")

Code Debugging Assistant

Developers often need quick help understanding error messages or testing small code fixes. Searching documentation or running snippets requires switching contexts.

Solution with Compound Beta

Users can paste an error message and ask for explanations or potential causes. Compound Beta Mini might use web search to find recent discussions or documentation about that specific error. Alternatively, users can provide a code snippet and ask "What's wrong with this code?" or "Will this Python code run: ...?". It can use code execution to test simple, self-contained snippets.

Why It's Great

  • Provides a unified interface for getting code help
  • Potentially draws on live web data for new errors
  • Executes code directly for validation
  • Speeds up the debugging process

Note: compound-beta-mini uses one tool per turn, so it might search OR execute, not both simultaneously in one response.

Code Example

Python
import os
from groq import Groq

client = Groq(api_key=os.environ.get("GROQ_API_KEY"))

# Example 1: Error Explanation (might trigger search)
debug_query_search = "I'm getting a 'Kubernetes CrashLoopBackOff' error on my pod. What are the common causes based on recent discussions?"

# Example 2: Code Check (might trigger code execution)
debug_query_exec = "Will this Python code raise an error? `import numpy as np; a = np.array([1,2]); b = np.array([3,4,5]); print(a+b)`"

# Choose one query to run
selected_query = debug_query_exec

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "system",
            "content": "You are a helpful coding assistant. You can explain errors, potentially searching for recent information, or check simple code snippets by executing them.",
        },
        {
            "role": "user",
            "content": selected_query,
        }
    ],
    # Use the compound model
    model="compound-beta-mini",
)

print(f"Query: {selected_query}")
print(f"Compound Beta Response:\n{chat_completion.choices[0].message.content}")

Chart Generation

Need to quickly create data visualizations from natural language descriptions? Compound Beta's code execution capabilities can help generate charts without writing visualization code directly.

Solution with Compound Beta

Describe the chart you want in natural language, and Compound Beta will generate and execute the appropriate Python visualization code. The model automatically parses your request, generates the visualization code using libraries like matplotlib or seaborn, and returns the chart.

Why It's Great

  • Generate charts from simple natural language descriptions
  • Supports common chart types (scatter, line, bar, etc.)
  • Handles all visualization code generation and execution
  • Customize data points, labels, colors, and layouts as needed

Usage and Results

shell
curl -X POST https://api.groq.com/openai/v1/chat/completions \
  -H "Authorization: Bearer $GROQ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "compound-beta",
    "messages": [
      {
        "role": "user",
        "content": "Create a scatter plot showing the relationship between market cap and daily trading volume for the top 5 tech companies (AAPL, MSFT, GOOGL, AMZN, META). Use current market data."
      }
    ]
  }'

Was this page helpful?