From 6deff3b929281d7c373d674d0aa627c27fbc13f4 Mon Sep 17 00:00:00 2001 From: Adrian Ariton Date: Thu, 16 Nov 2023 12:40:42 +0200 Subject: [PATCH] added more info, configs and a shell script --- README.md | 8 +++++ book/chattutor_setup/chattutor.config.js | 29 ++++++++++++----- book/chattutor_setup/chattutor.min.js | 14 ++------- build.sh | 40 ++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 20 deletions(-) create mode 100755 build.sh diff --git a/README.md b/README.md index 067a78c..142d4e4 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,14 @@ navigate to that directory and start a simple Python server: python -m http.server ``` +## Building and adding chattutor + +Check out the README.md file in chattutor_setup folder, +or simply run + +```sh +./build.sh``` + ## Development The majority of this book is written as Jupyter notebooks. Learn more about diff --git a/book/chattutor_setup/chattutor.config.js b/book/chattutor_setup/chattutor.config.js index eaf64a3..35a6967 100644 --- a/book/chattutor_setup/chattutor.config.js +++ b/book/chattutor_setup/chattutor.config.js @@ -39,14 +39,21 @@ * * COURSE_URL: the base url for the course * - * SERVER_PORT: the port listen to Chattutor - * server if ran locally. Used ONLY for testing - * purposes + * + * RUN_LOCALLY: true if and only if course is tested + * locally. For production it should be false, + * for testing it should be true. + * + * IS_STATIC: true if ran statically on a index.html + * file, false if ran on a server, either local or online + * Usually true for jupyter books */ +const RUN_LOCALLY = true; +const TEST_MODE = false; +const IS_STATIC = true; + const EMBEDDING_COLLECTION_NAME = "photonicsbootcamp12"; -const TEST_MODE = true; -const COURSE_URL = "https://byucamacholab.github.io/Photonics-Bootcamp" -const SERVER_PORT = 5000 +const COURSE_URL = "https://byucamacholab.github.io/Photonics-Bootcamp" /** * --------------- TESTING CONFIGS ---------------- * ChatTutor can be embedded on default applications @@ -61,9 +68,15 @@ const SERVER_PORT = 5000 * * This configuration is ONLY used for testing and * will have no weight in production mode - * (TEST_MODE = false) + * (RUN_LOCALLY = false) + * + * SERVER_PORT: the port listen to Chattutor + * server if ran locally. Used ONLY for testing + * purposes (TEST_MODE = false) */ -const BUILT_WITH = "JUPYTER-NOTEBOOK" +const BUILT_WITH = "JUPYTER-NOTEBOOK" +const SERVER_PORT = 5000 + /** * JUPYTER-NOTEBOOK Specific configurations. */ diff --git a/book/chattutor_setup/chattutor.min.js b/book/chattutor_setup/chattutor.min.js index 596135e..5ed40e2 100644 --- a/book/chattutor_setup/chattutor.min.js +++ b/book/chattutor_setup/chattutor.min.js @@ -1,16 +1,6 @@ // Configures UI const embed_mode = true; - -// Constants for embed mode and UI elements - -// import {lightMode, darkMode, setProperties} from "./constants.js"; -// import {alert} from "./nicealert.js" -// import { clearFileInput } from "./fileupload.js"; -// import { JSONparse } from "./jsonparse.js"; -// import { chattutor_embed } from "./chattutor.html.js"; -// import { setFromDoc, clearFromDoc } from "./from_doc_ext.js"; - let headers = new Headers(); headers.append('Content-Type', 'application/json'); @@ -45,7 +35,7 @@ var conversation = []; var original_file = ""; let lastMessageId = null; var stopGeneration = false -let selectedModel = "gpt-3.5-turbo" //document.getElementById('modelDropdown').value +let selectedModel = "gpt-3.5-turbo" function setupEmbedMode_URL() { @@ -59,7 +49,7 @@ function setupEmbedMode_URL() { }) path = window.location.pathname - if (BUILT_WITH == "JUPYTER-NOTEBOOK" && TEST_MODE == true) { + if (BUILT_WITH == "JUPYTER-NOTEBOOK" && RUN_LOCALLY == true && IS_STATIC == true) { const BUILD_HTML_JUPYTER_NOTEBOOK_FOLDER = "_build/html" ind = path.indexOf(BUILD_HTML_JUPYTER_NOTEBOOK_FOLDER); end = ind + BUILD_HTML_JUPYTER_NOTEBOOK_FOLDER.length; diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..db4dccc --- /dev/null +++ b/build.sh @@ -0,0 +1,40 @@ +#!/bin/bash +jupyter-book build --all book +python3 ./book/chattutor_setup/install.py +bold=$(tput bold) +normal=$(tput sgr0) +GREEN='\033[1;32m' +NC='\033[0m' # No Color +echo " +" +printf "${GREEN}===============================================================================${NC} + +The course is now built and ${bold}chattutor ${normal}is added to it. + +• To bypass CORS issue when testing on a local server/ + static page (if ${bold}TEST_MODE ${normal}is set to false in + ${bold}chattutor.config.js${normal}), start chrome with --disable-security + option: + +Examples: + +• ${bold}MACOS${normal}: + $ open -n -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --user-data-dir="/tmp/chrome_dev_test" --disable-web-security + +• ${bold}LINUX${normal}: + $ google-chrome --disable-web-security + + (*) If you need access to local files for dev purposes like AJAX or JSON, you can use --allow-file-access-from-files flag. +" +echo " +• ${bold}WINDOWS${normal}: + $ "C:\Program Files\Google\Chrome\Application\chrome.exe" --disable-web-security --disable-gpu --user-data-dir=%LOCALAPPDATA%\Google\chromeTemp + + +! Since Chrome 22+ you will get an error message that says: + +⚠ You are using an unsupported command-line flag: --disable-web-security. Stability and security will suffer. +" +echo " +However you can just ignore that message while developing. +" \ No newline at end of file