Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Session 1.3: AI Assistant in Jupyter

DSC ScaDS.AI, Leipzig University

JupyterLab / Jupyter Notebooks offers several options for integrating and using AI assistants that can help us with programming and data analysis tasks.

For our training sessions, we want to use the AI assistant bia-bob, which is provided via a Python package.

In this notebook, we will look at the advanced use of the AI assistant, especially its adaption to specific domains via a system prompt.

Import and Initialize the AI Assistant

# Import os to read env vars
import os
# Import bia-bob as bob and additional helper functions
from bia_bob import bob, available_models, fix, doc

bob.initialize(
    endpoint=os.getenv('ENDPOINT_URL'),
    model="mini",
)

System Prompt and Behavior

The basic behavior of an AI assistant (the underlying LLM) can be controlled via a so-called system prompt. A system prompt is a specific instruction to the AI assistant / LLM to control its behavior, tone, or style, or provide more domain specific context.

# Import the default bia-bob system prompt
from bia_bob import DEFAULT_SYSTEM_PROMPT
print(DEFAULT_SYSTEM_PROMPT[:640])

You are a extremely talented bioimage analyst and you use Python to solve your tasks unless stated otherwise.
If there are several ways to solve the task, chose the option with the least amount of code.    

## Python specific instructions

When writing python code, you can only use those libraries: {libraries}.
If you create images, show the results and save them in variables for later reuse.
{reusable_variables}
NEVER overwrite the values of the variables and functions that are available.

## Python specific code snippets

If the user asks for those simple tasks, use these code snippets.

{additional_snippets}
{builtin_snippets}

You can define and provide your own system prompt:

bob.initialize(
    system_prompt="""
    You are an excellent Python programmer who always 
    puts a smiley comment at the end of an answer.
    """
)
%bob Generate Python code: a for-loop that prints the numbers from 0 to 10.
Loading...
for i in range(11):  # range(11) yields 0, 1, ..., 10
    print(i)
# :)

You can reset the AI Assistant to the default system prompts like this:

bob.initialize(system_prompt=DEFAULT_SYSTEM_PROMPT)

You may also define a system prompt for a more tailored behavior fitting your specific domain, Data Stewardship.

And we may even ask our AI assistant to do this for us:

%%bob
Write me a short but precise system prompt in markdown format used for an AI assistant in Data Stewardship.
The goal is to have an assistant for both the institutional and project-specific Data Steward domain.
It uses Python or R for data exploration and validation tasks and helps drating Data Management Plans.
The assistant shall make use of according Python and R packages.
Store the prompts as multi-line string in the variable `SYSTEM_PROMPT_DATA_STEWARD`.
SYSTEM_PROMPT_DATA_STEWARD = """# System Prompt: Data Stewardship Assistant

You are an expert AI assistant for institutional and project‑specific data stewardship. Your responsibilities include:

- Drafting comprehensive **Data Management Plans (DMPs)** that meet funder and institutional policies.
- Assisting with data discovery, profiling, cleaning, and validation using **Python** (`pandas`, `numpy`, `pyjanitor`, `great_expectations`, `scipy`) and **R** (`tidyverse`, `data.table`, `validate`, `readr`).
- Recommending appropriate file formats, metadata standards (e.g., **Dublin Core**, **DataCite**, **ISO 19115**, **FAIR** principles) and preservation strategies.
- Providing concise, runnable code snippets (Jupyter‑compatible Python cells or reproducible R scripts) with brief comments for exploration, quality checks, and transformation.
- Advising on data documentation, access control, licensing, and ethical considerations (privacy, GDPR, consent).

**Response guidelines**
1. Identify whether the request is institutional or project‑specific and note any constraints.
2. Suggest the most suitable tools/packages for the task.
3. Return clean, executable code with minimal but clear comments.
4. Cite relevant standards or guidelines when appropriate."""
print(SYSTEM_PROMPT_DATA_STEWARD)
# System Prompt: Data Stewardship Assistant

You are an expert AI assistant for institutional and project‑specific data stewardship. Your responsibilities include:

- Drafting comprehensive **Data Management Plans (DMPs)** that meet funder and institutional policies.
- Assisting with data discovery, profiling, cleaning, and validation using **Python** (`pandas`, `numpy`, `pyjanitor`, `great_expectations`, `scipy`) and **R** (`tidyverse`, `data.table`, `validate`, `readr`).
- Recommending appropriate file formats, metadata standards (e.g., **Dublin Core**, **DataCite**, **ISO 19115**, **FAIR** principles) and preservation strategies.
- Providing concise, runnable code snippets (Jupyter‑compatible Python cells or reproducible R scripts) with brief comments for exploration, quality checks, and transformation.
- Advising on data documentation, access control, licensing, and ethical considerations (privacy, GDPR, consent).

**Response guidelines**
1. Identify whether the request is institutional or project‑specific and note any constraints.
2. Suggest the most suitable tools/packages for the task.
3. Return clean, executable code with minimal but clear comments.
4. Cite relevant standards or guidelines when appropriate.

Great! Let’s just use this and ask our AI assistant:

bob.initialize(system_prompt=SYSTEM_PROMPT_DATA_STEWARD)
%bob Who are you ?
Loading...

Reusable Data Steward System Prompt and Initialization

We can now elaborate a more detailed system prompt that includes specific domain knowledge and comprehensive instructions for the AI assistant, and save it as an additional environment variable in our secrets file.

When we initialize our AI assistant for future use, we can include this system prompt directly.

Here you find a complete template for the according import and initialization of bia-bob, which now uses a detailed Data Steward system prompt provided with the env var SYSTEM_PROMPT_DATA_STEWARD stored in the secrets file:

# Import os to read env vars
import os
# Import bob and helper functions
from bia_bob import bob, available_models, fix, doc
# Initialize assistant, reads API key from env var automatically
bob.initialize(
    # read endpoint URL from env var
    endpoint=os.getenv('ENDPOINT_URL'),
    # select an available model for your purpose
    model="mini",
    # read system prompt from env var
    system_prompt=os.getenv('SYSTEM_PROMPT_DATA_STEWARD'),
)
%bob Who are you ? The long version
Loading...

Use the Data Steward Assistant

Now that we have a proper AI assistant with data steward knowledge at hand, it can be used to assist with related tasks and answer specific questions. You may ask your assistant to, e.g., explain what a DMP is.

# TODO