From 6dff506d39fb24381f6bc928cbbaed61c82c2b88 Mon Sep 17 00:00:00 2001 From: Cedric Vidal Date: Wed, 8 May 2024 08:02:09 +0200 Subject: [PATCH] RAFT DevContainer for GitHub Codespaces (#379) This PR adds support for a GitHub Codespaces Dev Container for the `raft` sub-project: - Dev Container config `RAFT` with direnv with shell hooks - Adds `Open in GitHub Codespaces` badge to README.md pre-configured with `RAFT` config - post-create script creates env using the python venv module and points direnv at it - Upgrades pip and installs requirements Note: The Dev Container configuration can also be used locally in VS Code in addition to remotely in GitHub Codespaces. This PR is similar to #351 but targets the `raft` sub project. Co-authored-by: Shishir Patil <30296397+ShishirPatil@users.noreply.github.com> --- .devcontainer/raft/Dockerfile | 4 ++++ .devcontainer/raft/devcontainer.json | 32 ++++++++++++++++++++++++++++ .devcontainer/raft/post-create.sh | 16 ++++++++++++++ raft/.envrc | 3 +++ raft/.gitignore | 1 + raft/README.md | 8 +++++++ 6 files changed, 64 insertions(+) create mode 100644 .devcontainer/raft/Dockerfile create mode 100644 .devcontainer/raft/devcontainer.json create mode 100755 .devcontainer/raft/post-create.sh create mode 100644 raft/.envrc create mode 100644 raft/.gitignore diff --git a/.devcontainer/raft/Dockerfile b/.devcontainer/raft/Dockerfile new file mode 100644 index 0000000000..2b90bfef29 --- /dev/null +++ b/.devcontainer/raft/Dockerfile @@ -0,0 +1,4 @@ +FROM mcr.microsoft.com/devcontainers/python:1-3.10 + +RUN curl -sfL https://direnv.net/install.sh | bash && \ + echo 'eval "$(direnv hook bash)"' >> /etc/bash.bashrc diff --git a/.devcontainer/raft/devcontainer.json b/.devcontainer/raft/devcontainer.json new file mode 100644 index 0000000000..b3d6455f96 --- /dev/null +++ b/.devcontainer/raft/devcontainer.json @@ -0,0 +1,32 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/python +{ + "name": "RAFT", + + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "build": { + // Path is relative to the devcontainer.json file. + "dockerfile": "Dockerfile" + }, + + // Features to add to the dev container. More info: https://containers.dev/features. + "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "sh ${containerWorkspaceFolder}/.devcontainer/raft/post-create.sh", + + // Configure tool-specific properties. + "customizations": { + "codespaces": { + "openFiles": [ + "raft/README.md" + ] + } + } + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.devcontainer/raft/post-create.sh b/.devcontainer/raft/post-create.sh new file mode 100755 index 0000000000..3c6667cd40 --- /dev/null +++ b/.devcontainer/raft/post-create.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +cd raft + +echo "Allowing raft direnv" +direnv allow + +echo "Creating virtual environment" +python3 -m venv .venv +. ./.venv/bin/activate + +echo "Upgrading pip" +pip install --upgrade pip + +echo "Installing requirements" +pip install -r requirements.txt diff --git a/raft/.envrc b/raft/.envrc new file mode 100644 index 0000000000..9690fa1153 --- /dev/null +++ b/raft/.envrc @@ -0,0 +1,3 @@ +# Tell direnv to use pre configured venv +export VIRTUAL_ENV=./.venv +layout python diff --git a/raft/.gitignore b/raft/.gitignore new file mode 100644 index 0000000000..21d0b898ff --- /dev/null +++ b/raft/.gitignore @@ -0,0 +1 @@ +.venv/ diff --git a/raft/README.md b/raft/README.md index 2d406fa364..7e4e3e817e 100644 --- a/raft/README.md +++ b/raft/README.md @@ -4,6 +4,14 @@ RAFT is a recipe to adapting LLMs to domain-specific RAG. You can learn more in The input data from the user can be either a general text document (pdf, json, or txt) for general QA or an API documentation in the API Zoo JSONL format for API calling. +## Dev environment with Codespaces + +[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/ShishirPatil/gorilla/tree/codespaces?devcontainer_path=.devcontainer%2Fraft%2Fdevcontainer.json) + +Everything is setup automatically in the dev container, open a terminal into the `raft` folder: + +Note: The `raft` virtual env will be activated in your shell when entering into the `raft` folder. + ## Install Dependencies Dependencies can be installed using the following command: