Basic Examples
Basic Examples
This page provides several basic examples of AI Task pipelines to help you understand how to use the framework for common tasks.
Text Summarization
This example demonstrates how to create a pipeline that summarizes a text document using an LLM.
Configuration File (summarize.ai)
name: "Text Summarization"
description: "Summarizes a text document using an LLM"
pipe:
- type: function
function: aisource
params:
file: "data/article.txt"
- type: llm
tmpl: "summarize"
model: "claude-3-7-sonnet-latest"
- type: function
function: airesult
params:
file: "data/results/summary.txt"
format: "text"Template File (templates/summarize.tmpl)
summarize the following text in a concise way, preserving the key points:
{{ pipein_text }}
Running the Pipeline
python -m ai_task.run_tasks summarize.aiText Classification
This example shows how to create a pipeline that classifies a text document into predefined categories.
Configuration File (classify.ai)
name: "Text Classification"
description: "Classifies a text document into categories"
pipe:
- type: function
function: aisource
params:
file: "data/article.txt"
- type: llm
tmpl: "classify"
model: "claude-3-7-sonnet-latest"
- type: function
function: airesult
params:
file: "data/results/classification.json"
format: "json"Template File (templates/classify.tmpl)
classify the following text into one of these categories: Technology, Science, Politics, Business, Entertainment, Sports, Health.
Return your answer as a JSON object with the following structure:
{
"category": "The category name",
"confidence": "A number between 0 and 1 indicating your confidence",
"explanation": "A brief explanation of why you chose this category"
}
Text to classify:
{{ pipein_text }}
Running the Pipeline
python -m ai_task.run_tasks classify.aiQuestion Answering
This example demonstrates how to create a pipeline that answers questions based on a provided text.
Configuration File (qa.ai)
name: "Question Answering"
description: "Answers questions based on a provided text"
pipe:
- type: function
function: aisource
params:
file: "data/context.txt"
- type: function
function: aiinput
params:
prompt: "What question would you like to ask about the text?"
- type: llm
tmpl: "qa"
model: "claude-3-7-sonnet-latest"
- type: function
function: airesult
params:
file: "data/results/answer.txt"
format: "text"Template File (templates/qa.tmpl)
Answer the following question based only on the provided context. If the answer is not in the context, say "I don't know".
Context:
{{ pipein_text }}
Question:
{{ user_question }}
Running the Pipeline
python -m ai_task.run_tasks qa.aiMulti-Step Processing
This example shows how to create a pipeline with multiple processing steps.
Configuration File (process.ai)
name: "Multi-Step Processing"
description: "Processes a text document in multiple steps"
pipe:
- type: function
function: aisource
params:
file: "data/article.txt"
- type: llm
tmpl: "extract_entities"
model: "claude-3-7-sonnet-latest"
- type: function
function: aijson
params:
key: "entities"
- type: llm
tmpl: "analyze_entities"
model: "claude-3-7-sonnet-latest"
- type: function
function: airesult
params:
file: "data/results/analysis.txt"
format: "text"Template Files
templates/extract_entities.tmpl
Extract all named entities (people, organizations, locations) from the following text.
Return your answer as a JSON array of objects, where each object has the following structure:
{
"name": "The entity name",
"type": "person|organization|location",
"mentions": [list of positions where the entity is mentioned]
}
Text:
{{ pipein_text }}
templates/analyze_entities.tmpl
Analyze the relationships between the following entities extracted from a text:
{{ entities }}
Provide a summary of how these entities are related to each other based on the text.
Running the Pipeline
python -m ai_task.run_tasks process.aiNext Steps
Now that you’ve seen some basic examples, you can: