Skip to main content
Open in Kaggle  Open in Colab  Download Notebook
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 Deepseek integration enables you to access Deepseek’s LLM via the Deepseek API.

Prerequisites

Important Notes

  • Deepseek usage may incur costs based on your Deepseek plan.
  • Be mindful of sensitive data and consider security measures when integrating with external services.
First you’ll need to install the required libraries and enter a Deepseek API key. Deepseek uses the OpenAI SDK as its Python API, so we need to install it in addition to Pixeltable.
%pip install -qU pixeltable openai
import os
import getpass

if 'DEEPSEEK_API_KEY' not in os.environ:
    os.environ['DEEPSEEK_API_KEY'] = getpass.getpass('Deepseek API Key:')
Now let’s create a Pixeltable directory to hold the tables for our demo.
import pixeltable as pxt

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

Messages

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 Deepseek.
from pixeltable.functions import deepseek

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

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

msgs = [{'role': 'user', 'content': t.input}]
t.add_computed_column(output=deepseek.chat_completions(
    messages=msgs,
    model='deepseek-chat',
))
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': 'What was the outcome of the 1904 US Presidential election?'}])
t.select(t.input, t.response).show()
Inserting rows into `chat`: 1 rows [00:00, 105.11 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.