Skip to main content
Pixeltable’s Groq integration enables you to access Groq models via the Groq API.

Prerequisites

Important Notes

  • Groq usage may incur costs based on your Groq plan.
  • Be mindful of sensitive data and consider security measures when integrating with external services.
First you’ll need to install required libraries and enter your OpenAI API key.
%pip install -qU pixeltable groq
import os
import getpass
if 'GROQ_API_KEY' not in os.environ:
    os.environ['GROQ_API_KEY'] = getpass.getpass('Enter your Groq API key:')
Now let’s create a Pixeltable directory to hold the tables for our demo.
import pixeltable as pxt

# Remove the 'groq_demo' directory and its contents, if it exists
pxt.drop_dir('groq_demo', force=True)
pxt.create_dir('groq_demo')
Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/asiegel/.pixeltable/pgdata
Created directory 'groq_demo'.
<pixeltable.catalog.dir.Dir at 0x30bb80b20>

Chat Completions

Create a Table: In Pixeltable, create a table with columns to represent your input data and the columns where you want to store the results from Groq.
from pixeltable.functions import groq

# Create a table in Pixeltable and add a computed column that calls OpenAI

t = pxt.create_table('groq_demo.chat', {'input': pxt.String})

messages = [{'role': 'user', 'content': t.input}]
t.add_computed_column(output=groq.chat_completions(
    messages=messages,
    model='llama-3.1-8b-instant',
    model_kwargs={
        # Optional dict with parameters for the Groq API
        'max_tokens': 300,
        'top_p': 0.9,
        'temperature': 0.7
    }
))
Created table `chat`.
Added 0 column values with 0 errors.
UpdateStatus(num_rows=0, num_computed_values=0, num_excs=0, updated_cols=[], cols_with_excs=[])
# Parse the response into a new column
t.add_computed_column(response=t.output.choices[0].message.content)
Added 0 column values with 0 errors.
UpdateStatus(num_rows=0, num_computed_values=0, num_excs=0, updated_cols=[], cols_with_excs=[])
# Start a conversation
t.insert([{'input': 'How many islands are in the Aleutian island chain?'}])
t.select(t.input, t.response).head()
Inserting rows into `chat`: 1 rows [00:00, 76.95 rows/s]
Inserted 1 row with 0 errors.
input response
How many islands are in the Aleutian island chain? The Aleutian Island chain is a part of Alaska, United States, and it stretches for approximately 1,200 miles (1,950 km) westward from the Alaska Peninsula toward Japan. The chain consists of more than 300 islands, with the largest island being Unimak Island. According to the Alaska Geographic Society, there are 314 islands in the Aleutian Island chain, although the exact number can vary depending on how the islands are defined and counted. Some sources may group certain islands together or recognize smaller islands that others do not. The Aleutian Islands are a remote and rugged chain, with many of the islands being uninhabited. The islands are volcanic in origin, and they are home to a diverse range of wildlife, including sea otters, puffins, and brown bears.

Learn More

To learn more about advanced techniques like RAG operations in Pixeltable, check out the RAG Operations in Pixeltable tutorial. If you have any questions, don’t hesitate to reach out.