Skip to main content
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.
input response
What was the outcome of the 1904 US Presidential election? The **1904 U.S. Presidential election** resulted in a decisive victory for the incumbent **Republican** President **Theodore Roosevelt**, who had assumed office in 1901 after the assassination of William McKinley. ### **Key Results:** - **Theodore Roosevelt (Republican)** won **56.4%** of the popular vote and **336 electoral votes** (70.6% of the total). - **Alton B. Parker (Democrat)** received **37.6%** of the popular vote and **140 electoral votes**. - **Eugene V. Debs (Socialist)** and **Silas C. Swallow (Prohibition)** also ran but received minimal support. ### **Significance:** - Roosevelt's landslide victory solidified his leadership and progressive policies, including trust-busting and conservation efforts. - This was the first election in which a sitting president who had inherited the office (rather than being elected to it) won a full term in his own right. Roosevelt carried **32 of the 45 states**, demonstrating broad national support.

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.