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.
Together.ai usage may incur costs based on your Together.ai 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 Together
API key.
%pip install -qU pixeltable together
import getpassimport osif 'TOGETHER_API_KEY' not in os.environ: os.environ['TOGETHER_API_KEY'] = getpass.getpass('Together API Key: ')
Now let’s create a Pixeltable directory to hold the tables for our demo.
import pixeltable as pxt# Remove the 'together_demo' directory and its contents, if it existspxt.drop_dir('together_demo', force=True)pxt.create_dir('together_demo')
Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/asiegel/.pixeltable/pgdata
Created directory ‘together_demo’.
<pixeltable.catalog.dir.Dir at 0x168536050>
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
OpenAI.
from pixeltable.functions import togetherchat_t = pxt.create_table('together_demo/chat', {'input': pxt.String})messages = [{'role': 'user', 'content': chat_t.input}]chat_t.add_computed_column( output=together.chat_completions( messages=messages, model='Qwen/Qwen3.5-9B', model_kwargs={ # Optional dict with parameters for the Together API 'max_tokens': 300, 'stop': ['\n'], 'temperature': 0.7, 'top_p': 0.9, }, ))chat_t.add_computed_column( response=chat_t.output.choices[0].message.content)
Created table ‘chat’.
Added 0 column values with 0 errors in 0.01 s
Added 0 column values with 0 errors in 0.01 s
No rows affected.
# Start a conversationchat_t.insert( [ {'input': 'How many species of felids have been classified?'}, {'input': 'Can you make me a coffee?'}, ])chat_t.select(chat_t.input, chat_t.response).head()
Inserted 2 rows with 0 errors in 1.58 s (1.27 rows/s)