Summarize text with LLMs

Generate concise summaries of long text, articles, or documents using large language models.

Text · Notebook · Updated

Colab runs it in your browser. If it calls a model provider, it asks for that provider's API key in a cell.

How it works

You add a computed column that calls an LLM to generate summaries. When you insert new text, summaries are generated automatically.

What it covers

  • Summarize text using OpenAI GPT models
  • Customize summary style with prompts
  • Process multiple documents automatically

What it uses

Install
terminal
pip install pixeltable openai
Environment variables it names
OPENAI_API_KEY
Pixeltable calls
openai.chat_completions()pxt.create_table()insert()add_computed_column()

A look at the code

text-summarize.ipynb
# Create prompt template for summarization
prompt = (
'Summarize the following article in 2-3 sentences:\n\n'
+ articles.content
)
# Add computed column for LLM response
articles.add_computed_column(
response=openai.chat_completions(
messages=[{'role': 'user', 'content': prompt}],
model='gpt-4o-mini',
)
)

One cell of the notebook, copied as it is. Open it in Colab for the rest.

Browse all 103