This documentation page is also available as an interactive notebook. You can launch the notebook in
Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the
above links.
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.
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.