Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DOCSGPT_API_KEY='add-agent-key'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.env
!.env.example
.gradio/
__pycache__/
.ipynb_checkpoints/
.DS_Store
.venv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Use Python 3.12 slim (already has Python and pip).
FROM python:3.12-slim

# Avoid interactive prompts during apt operations.
ENV DEBIAN_FRONTEND=noninteractive

# Install CA certificates (needed for HTTPS).
RUN apt-get update && apt-get install -y \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Install project specific packages.
RUN mkdir -p /install
COPY requirements.txt /install/requirements.txt
RUN pip install --upgrade pip && \
pip install --no-cache-dir jupyterlab jupyterlab_vim jupytext -r /install/requirements.txt

# Config.
COPY etc_sudoers /install/
COPY etc_sudoers /etc/sudoers
COPY bashrc /root/.bashrc

# Report package versions.
COPY version.sh /install/
RUN /install/version.sh 2>&1 | tee version.log

# Jupyter.
EXPOSE 8888

CMD ["/bin/bash"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use Python 3.12 slim (already has Python and pip).
FROM python:3.12-slim

# Avoid interactive prompts during apt operations.
ENV DEBIAN_FRONTEND=noninteractive

# Install CA certificates (needed for HTTPS).
RUN apt-get update && apt-get install -y \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Install project specific packages.
RUN mkdir -p /install
COPY requirements.txt /install/requirements.txt
RUN pip install --upgrade pip && \
pip install --no-cache-dir jupyterlab jupyterlab_vim jupytext -r /install/requirements.txt

# Config.
COPY etc_sudoers /install/
COPY etc_sudoers /etc/sudoers
COPY bashrc /root/.bashrc

# Report package versions.
COPY version.sh /install/
RUN /install/version.sh 2>&1 | tee version.log

# Jupyter.
EXPOSE 8888
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND noninteractive

# Install system utilities and Python in a single layer.
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
sudo \
curl \
git \
build-essential \
python3 \
python3-pip \
python3-dev \
python3-venv \
&& rm -rf /var/lib/apt/lists/*

# Create virtual environment.
RUN python3 -m venv /opt/venv

# Make the venv the default Python.
ENV PATH="/opt/venv/bin:$PATH"

# Install project specific packages.
RUN mkdir /install
COPY requirements.txt /install/requirements.txt
RUN pip install --upgrade pip && \
pip install --no-cache-dir jupyterlab jupyterlab_vim jupytext -r /install/requirements.txt

# Config.
COPY etc_sudoers /install/
COPY etc_sudoers /etc/sudoers
COPY bashrc /root/.bashrc

# Report package versions.
COPY version.sh /install/
RUN /install/version.sh 2>&1 | tee version.log

# Jupyter.
EXPOSE 8888
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND noninteractive

# Install system utilities and Python in a single layer.
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
sudo \
curl \
git \
build-essential \
python3 \
python3-pip \
python3-dev \
python3-venv \
libgomp1 \
g++ \
&& rm -rf /var/lib/apt/lists/*

# Install uv for package management.
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.local/bin:$PATH"

# Install project specific packages using uv.
COPY pyproject.toml uv.lock /app/
WORKDIR /app
RUN uv sync
ENV PATH="/app/.venv/bin:$PATH"

# Install Jupyter.
RUN pip install --upgrade pip && \
pip install --no-cache-dir jupyterlab jupyterlab_vim jupytext

# Copy project files.
COPY . /app

RUN mkdir /install

# Config.
COPY etc_sudoers /install/
COPY etc_sudoers /etc/sudoers
COPY bashrc /root/.bashrc

# Report package versions.
COPY version.sh /install/
RUN /install/version.sh 2>&1 | tee version.log

# Jupyter.
EXPOSE 8888
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# DocsGPT Tutorial — Intelligent Documentation Assistant

DocsGPT is an open-source, RAG-based AI platform (15k+ GitHub stars) that
retrieves relevant document chunks and passes them to a language model to
generate grounded answers. This tutorial builds a complete documentation
assistant on top of the DocsGPT Cloud API — covering summarisation, FAQ
generation, evaluation, multi-language output, streaming, and an interactive UI.

## Quick Start

```bash
cd tutorials/docsgpt
cp .env.example .env # add your agent key to .env
./docker_build.sh # build the Docker image
./docker_jupyter.sh # launch Jupyter Lab at localhost:8888
```

Get your Agent key: https://app.docsgpt.cloud → Settings → Agents → Create New

Open **http://localhost:8888** and work through the notebooks in order:

1. **`docsgpt.API.ipynb`** (20 min) — Walks through every real DocsGPT Cloud
endpoint with raw HTTP calls and `docsgpt_utils` wrapper calls side by side:
`/api/answer`, `/stream`, `/api/store_attachment`, `/api/task_status`.
Also covers multi-turn conversation, SSE streaming, and the file attachment flow.

2. **`docsgpt.example.ipynb`** (25 min) — End-to-end documentation assistant:
loads data from three real datasets (Awesome ML, Stack Overflow, The Pile),
summarises each document, generates FAQs, evaluates output with ROUGE + BLEU,
produces multi-language output in 9 languages, and launches an interactive
Gradio UI.


## Key files

| File | Purpose |
|------|---------|
| `docsgpt_utils.py` | All reusable functions and API wrappers |
| `docsgpt.API.ipynb` + `.py` | API walkthrough (Jupytext paired) |
| `docsgpt.example.ipynb` + `.py` | Full application (Jupytext paired) |
| `Dockerfile` + `docker_*.sh` | Container setup and management |
| `requirements.txt` | Pinned Python dependencies |
| `.env.example` | Template for API key configuration |

See [project template README](project_template_README.md) for full
Docker usage details.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set -o vi
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#!/usr/bin/env python

"""
Copy Docker-related files from the source directory to a destination directory.

This script copies all Docker configuration and utility files from
class_project/project_template/ to a specified destination directory.

Usage examples:
# Copy all files to a target directory.
> ./copy_docker_files.py --dst_dir /path/to/destination

# Copy with verbose logging.
> ./copy_docker_files.py --dst_dir /path/to/destination -v DEBUG

Import as:

import class_project.project_template.copy_docker_files as cpdccodo
"""

import argparse
import logging
import os
from typing import List

import helpers.hdbg as hdbg
import helpers.hio as hio
import helpers.hparser as hparser
import helpers.hsystem as hsystem

_LOG = logging.getLogger(__name__)

# #############################################################################
# Constants
# #############################################################################

# List of files to copy from the source directory.
_FILES_TO_COPY = [
"bashrc",
"docker_bash.sh",
"docker_build.sh",
"docker_clean.sh",
"docker_cmd.sh",
"docker_exec.sh",
"docker_jupyter.sh",
"docker_name.sh",
"docker_push.sh",
"etc_sudoers",
"install_jupyter_extensions.sh",
"run_jupyter.sh"
"version.sh",
]


# #############################################################################
# Helper functions
# #############################################################################


def _get_source_dir() -> str:
"""
Get the absolute path to the source directory containing Docker files.

:return: absolute path to class_project/project_template/
"""
# Get the directory where this script is located.
script_dir = os.path.dirname(os.path.abspath(__file__))
_LOG.debug("Script directory='%s'", script_dir)
return script_dir


def _copy_files(
*,
src_dir: str,
dst_dir: str,
files: List[str],
) -> None:
"""
Copy specified files from source directory to destination directory.

:param src_dir: source directory path
:param dst_dir: destination directory path
:param files: list of filenames to copy
"""
# Verify source directory exists.
hdbg.dassert_dir_exists(src_dir, "Source directory does not exist:", src_dir)
# Create destination directory if it doesn't exist.
hio.create_dir(dst_dir, incremental=True)
_LOG.info("Copying %d files from '%s' to '%s'", len(files), src_dir, dst_dir)
# Copy each file.
copied_count = 0
for filename in files:
src_path = os.path.join(src_dir, filename)
dst_path = os.path.join(dst_dir, filename)
# Verify source file exists.
hdbg.dassert_path_exists(
src_path, "Source file does not exist:", src_path
)
# Copy the file using cp -a to preserve all permissions and attributes.
_LOG.debug("Copying '%s' -> '%s'", src_path, dst_path)
cmd = f"cp -a {src_path} {dst_path}"
hsystem.system(cmd)
copied_count += 1
#
_LOG.info("Successfully copied %d files", copied_count)


# #############################################################################


def _parse() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
"--dst_dir",
action="store",
required=True,
help="Destination directory where files will be copied",
)
hparser.add_verbosity_arg(parser)
return parser


def _main(parser: argparse.ArgumentParser) -> None:
args = parser.parse_args()
hdbg.init_logger(verbosity=args.log_level, use_exec_path=True)
# Get source directory.
src_dir = _get_source_dir()
# Copy files to destination.
_copy_files(
src_dir=src_dir,
dst_dir=args.dst_dir,
files=_FILES_TO_COPY,
)


if __name__ == "__main__":
_main(_parse())
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# """
# This script launches a Docker container with an interactive bash shell for
# development.
# """

# Exit immediately if any command exits with a non-zero status.
set -e

# Import the utility functions from the project template.
GIT_ROOT=$(git rev-parse --show-toplevel)
source $GIT_ROOT/class_project/project_template/utils.sh

# Parse default args (-h, -v) and enable set -x if -v is passed.
parse_default_args "$@"

# Load Docker configuration variables for this script.
get_docker_vars_script ${BASH_SOURCE[0]}
source $DOCKER_NAME
print_docker_vars

# List the available Docker images matching the expected image name.
run "docker image ls $FULL_IMAGE_NAME"

# Configure and run the Docker container with interactive bash shell.
# - Container is removed automatically on exit (--rm)
# - Interactive mode with TTY allocation (-ti)
# - Port forwarding for Jupyter or other services
# - Git root mounted to /git_root inside container
CONTAINER_NAME=${IMAGE_NAME}_bash
PORT=
DOCKER_CMD=$(get_docker_bash_command)
DOCKER_CMD_OPTS=$(get_docker_bash_options $CONTAINER_NAME $PORT)
run "$DOCKER_CMD $DOCKER_CMD_OPTS $FULL_IMAGE_NAME"
Loading