├── LICENSE ├── README.md ├── chatgpt ├── ChatGPT Demo.ipynb ├── ChatGPT_Demo_v2.ipynb ├── ChatGPT_Flask_Demo │ └── ChatGPT_Flask_Demo │ │ ├── ChatGPT_Flask_Demo.pyproj │ │ ├── ChatGPT_Flask_Demo.pyproj.user │ │ ├── ChatGPT_Flask_Demo.sln │ │ ├── ChatGPT_Flask_Demo │ │ ├── __init__.py │ │ ├── static │ │ │ ├── content │ │ │ │ ├── bootstrap.min.css │ │ │ │ └── style.css │ │ │ └── scripts │ │ │ │ ├── bootstrap.min.js │ │ │ │ └── jquery-1.10.2.min.js │ │ └── templates │ │ │ └── index.html │ │ ├── obj │ │ └── Any CPU │ │ │ └── Debug │ │ │ └── ChatGPT_Flask_Demo.pyproj.FileListAbsolute.txt │ │ └── runserver.py └── ChatGPT_Flask_Demo_v2 │ ├── ChatGPT_Flask_Demo.pyproj │ ├── ChatGPT_Flask_Demo.pyproj.user │ ├── ChatGPT_Flask_Demo.sln │ ├── ChatGPT_Flask_Demo │ ├── __init__.py │ ├── static │ │ ├── content │ │ │ ├── bootstrap.min.css │ │ │ └── style.css │ │ └── scripts │ │ │ ├── bootstrap.min.js │ │ │ └── jquery-1.10.2.min.js │ └── templates │ │ └── index.html │ └── runserver.py ├── embeddings_search ├── Context-based-search-Version2.ipynb ├── Context-based-search-med.ipynb ├── Context-based-search-mini.ipynb └── Embeddings-docx.ipynb └── tokenization ├── tokenizer.ipynb └── tokenizer_flask ├── Tokenizer_Demo.pyproj ├── Tokenizer_Demo.sln ├── Tokenizer_Demo ├── __init__.py ├── static │ ├── content │ │ ├── bootstrap.min.css │ │ └── style.css │ └── scripts │ │ ├── bootstrap.min.js │ │ └── jquery-1.10.2.min.js └── templates │ └── index.html ├── __init__.py ├── obj └── Any CPU │ ├── Debug │ └── Tokenizer_Demo.pyproj.FileListAbsolute.txt │ └── Release │ └── _WPPLastBuildInfo.txt ├── runserver.py ├── static ├── content │ ├── bootstrap.min.css │ └── style.css └── scripts │ ├── bootstrap.min.js │ └── jquery-1.10.2.min.js └── templates └── index.html /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Tinkering with Deep Learning & AI 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tinkering with Deep Learning & AI 2 | 3 | All of the code here corresponds to various videos I have released on my [youtube channel](https://www.youtube.com/channel/UCq_JMAyEmsmq1PUMpZRjFVg). 4 | 5 | - [Visualizing OpenAI tokenization with tiktoken](https://youtu.be/Oxyg5I167b0) 6 | 7 | - [Azure OpenAI GPT-4 Tutorial](https://www.youtube.com/watch?v=uCKH8bmPgFs) 8 | 9 | - [Intro to Azure OpenAI & ChatGPT](https://youtu.be/jskenvwlnAI) 10 | 11 | - [OpenAI's New ChatGPT API (gpt-3.5.turbo) Handling token limits](https://youtu.be/xkCzP4-YoNA) 12 | 13 | - [Getting started with OpenAI's ChatGPT API](https://youtu.be/0l4UDn1p7gM) 14 | 15 | - [OpenAI v2 Embeddings & Search with .docx files](https://youtu.be/H9nXtUkGL-U) 16 | 17 | - [OpenAI v2 Embeddings](https://youtu.be/fODk-alDqWw) 18 | 19 | - [OpenAI v2 Embeddings Part II](https://youtu.be/oQdgyGywfr4) 20 | 21 | - [Azure OpenAI embeddings](https://youtu.be/PSLO-yM6eFY) This video is outdated - checkout the [official Microsoft docs](https://learn.microsoft.com/azure/cognitive-services/openai/tutorials/embeddings?tabs=command-line) for a better updated tutorial. 22 | -------------------------------------------------------------------------------- /chatgpt/ChatGPT Demo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "63c04e81-7deb-44b3-87ec-656acafdbbb2", 7 | "metadata": {}, 8 | "outputs": [ 9 | { 10 | "name": "stdout", 11 | "output_type": "stream", 12 | "text": [ 13 | "{\n", 14 | " \"choices\": [\n", 15 | " {\n", 16 | " \"finish_reason\": \"stop\",\n", 17 | " \"index\": 0,\n", 18 | " \"message\": {\n", 19 | " \"content\": \"The 2020 World Series was played at a neutral site due to the COVID-19 pandemic. The series was played at Globe Life Field in Arlington, Texas.\",\n", 20 | " \"role\": \"assistant\"\n", 21 | " }\n", 22 | " }\n", 23 | " ],\n", 24 | " \"created\": 1677730003,\n", 25 | " \"id\": \"chatcmpl-6pUVHp1WFbYlwmhh4HLB9a2tSLFNL\",\n", 26 | " \"model\": \"gpt-3.5-turbo-0301\",\n", 27 | " \"object\": \"chat.completion\",\n", 28 | " \"usage\": {\n", 29 | " \"completion_tokens\": 35,\n", 30 | " \"prompt_tokens\": 56,\n", 31 | " \"total_tokens\": 91\n", 32 | " }\n", 33 | "}\n", 34 | "The 2020 World Series was played at a neutral site due to the COVID-19 pandemic. The series was played at Globe Life Field in Arlington, Texas.\n" 35 | ] 36 | } 37 | ], 38 | "source": [ 39 | "import openai\n", 40 | "import os\n", 41 | "openai.api_key = os.getenv(\"OPENAI_API_KEY\") \n", 42 | "openai.organization = os.getenv(\"OPENAI_ORGANIZATION\") \n", 43 | "\n", 44 | "response = openai.ChatCompletion.create(\n", 45 | " model=\"gpt-3.5-turbo\",\n", 46 | " messages=[\n", 47 | " {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n", 48 | " {\"role\": \"user\", \"content\": \"Who won the world series in 2020?\"},\n", 49 | " {\"role\": \"assistant\", \"content\": \"The Los Angeles Dodgers won the World Series in 2020.\"},\n", 50 | " {\"role\": \"user\", \"content\": \"Where was it played?\"}\n", 51 | " ]\n", 52 | ")\n", 53 | "\n", 54 | "print(response)\n", 55 | "\n", 56 | "print(response['choices'][0]['message']['content'])" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": null, 62 | "id": "71fd5fcf-7e9c-419d-97e0-df7de46aaa4c", 63 | "metadata": {}, 64 | "outputs": [], 65 | "source": [ 66 | "import os\n", 67 | "import openai\n", 68 | "openai.api_key = os.getenv(\"OPENAI_API_KEY\") \n", 69 | "openai.organization = os.getenv(\"OPENAI_ORGANIZATION\") \n", 70 | "\n", 71 | "conversation=[{\"role\": \"system\", \"content\": \"You are a helpful assistant.\"}]\n", 72 | "\n", 73 | "while(True):\n", 74 | " user_input = input(\"\") \n", 75 | " conversation.append({\"role\": \"user\", \"content\": user_input})\n", 76 | "\n", 77 | " response = openai.ChatCompletion.create(\n", 78 | " model=\"gpt-3.5-turbo\",\n", 79 | " messages = conversation\n", 80 | " )\n", 81 | "\n", 82 | " conversation.append({\"role\": \"assistant\", \"content\": response['choices'][0]['message']['content']})\n", 83 | " print(\"\\n\" + response['choices'][0]['message']['content'] + \"\\n\")" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": null, 89 | "id": "b7ccd77a-49fe-44a2-90e9-568b5e4b66f5", 90 | "metadata": {}, 91 | "outputs": [], 92 | "source": [ 93 | "import os\n", 94 | "import openai\n", 95 | "openai.api_key = os.getenv(\"OPENAI_API_KEY\") \n", 96 | "openai.organization = os.getenv(\"OPENAI_ORGANIZATION\") \n", 97 | "\n", 98 | "conversation=[{\"role\": \"system\", \"content\": \"You are a helpful assistant.\"}]\n", 99 | "\n", 100 | "while(True):\n", 101 | " user_input = input(\"\") \n", 102 | " conversation.append({\"role\": \"user\", \"content\": user_input})\n", 103 | "\n", 104 | " response = openai.ChatCompletion.create(\n", 105 | " model=\"gpt-3.5-turbo\",\n", 106 | " messages = conversation,\n", 107 | " temperature=2,\n", 108 | " max_tokens=250,\n", 109 | " top_p=0.9\n", 110 | " )\n", 111 | "\n", 112 | " conversation.append({\"role\": \"assistant\", \"content\": response['choices'][0]['message']['content']})\n", 113 | " print(\"\\n\" + response['choices'][0]['message']['content'] + \"\\n\")" 114 | ] 115 | } 116 | ], 117 | "metadata": { 118 | "kernelspec": { 119 | "display_name": "Python 3 (ipykernel)", 120 | "language": "python", 121 | "name": "python3" 122 | }, 123 | "language_info": { 124 | "codemirror_mode": { 125 | "name": "ipython", 126 | "version": 3 127 | }, 128 | "file_extension": ".py", 129 | "mimetype": "text/x-python", 130 | "name": "python", 131 | "nbconvert_exporter": "python", 132 | "pygments_lexer": "ipython3", 133 | "version": "3.11.1" 134 | } 135 | }, 136 | "nbformat": 4, 137 | "nbformat_minor": 5 138 | } 139 | -------------------------------------------------------------------------------- /chatgpt/ChatGPT_Demo_v2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "id": "6f697a72-7758-42ae-9d29-f91bb575f689", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "#pip install tiktoken --upgrade\n", 11 | "# If you have the old version of titoken you will need to run the command above to upgrade to the latest version\n", 12 | "import tiktoken\n", 13 | "import openai\n", 14 | "import os\n", 15 | "openai.api_key = os.getenv(\"OPENAI_API_KEY\") \n", 16 | "openai.organization = os.getenv(\"OPENAI_ORGANIZATION\") \n", 17 | "\n", 18 | "system_message = {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"}\n", 19 | "max_response_tokens = 250\n", 20 | "token_limit= 4096\n", 21 | "conversation=[]\n", 22 | "conversation.append(system_message)\n", 23 | "\n", 24 | "def num_tokens_from_messages(messages, model=\"gpt-3.5-turbo-0301\"):\n", 25 | " encoding = tiktoken.encoding_for_model(model)\n", 26 | " num_tokens = 0\n", 27 | " for message in messages:\n", 28 | " num_tokens += 4 # every message follows {role/name}\\n{content}\\n\n", 29 | " for key, value in message.items():\n", 30 | " num_tokens += len(encoding.encode(value))\n", 31 | " if key == \"name\": # if there's a name, the role is omitted\n", 32 | " num_tokens += -1 # role is always required and always 1 token\n", 33 | " num_tokens += 2 # every reply is primed with assistant\n", 34 | " return num_tokens\n", 35 | "\n", 36 | "while(True):\n", 37 | " user_input = input(\"\") \n", 38 | " conversation.append({\"role\": \"user\", \"content\": user_input})\n", 39 | " conv_history_tokens = num_tokens_from_messages(conversation)\n", 40 | " print(f\"Conversation history token count: {conv_history_tokens}\")\n", 41 | " conv_length= len(conversation)\n", 42 | " half = int(conv_length/2)\n", 43 | " if (conv_history_tokens+max_response_tokens >= token_limit):\n", 44 | " conversation = conversation[half:]\n", 45 | " conversation.insert(0,system_message)\n", 46 | " print(f\"Conversation length: {conv_length}\")\n", 47 | "\n", 48 | " response = openai.ChatCompletion.create(\n", 49 | " model=\"gpt-3.5-turbo\",\n", 50 | " messages = conversation,\n", 51 | " temperature=.7,\n", 52 | " max_tokens=max_response_tokens,\n", 53 | " )\n", 54 | "\n", 55 | " conversation.append({\"role\": \"assistant\", \"content\": response['choices'][0]['message']['content']})\n", 56 | " print(\"\\n\" + response['choices'][0]['message']['content'] + \"\\n\")\n", 57 | " post_response=num_tokens_from_messages(conversation)\n", 58 | " print(f\"Post response token count: {post_response}\")" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": null, 64 | "id": "350e0692-3c3a-4720-b63c-6923f9b97981", 65 | "metadata": {}, 66 | "outputs": [], 67 | "source": [ 68 | "print(conversation)" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "id": "89ec5ad9-51d4-4e3b-959f-b6a31b41e838", 75 | "metadata": {}, 76 | "outputs": [], 77 | "source": [ 78 | "#pip install tiktoken --upgrade\n", 79 | "\n", 80 | "import tiktoken\n", 81 | "import openai\n", 82 | "import os\n", 83 | "\n", 84 | "openai.api_key = os.getenv(\"OPENAI_API_KEY\") \n", 85 | "openai.organization = os.getenv(\"OPENAI_ORGANIZATION\") \n", 86 | "\n", 87 | "system_message = {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"}\n", 88 | "max_response_tokens = 250\n", 89 | "token_limit= 4096\n", 90 | "conversation=[]\n", 91 | "conversation.append(system_message)\n", 92 | "\n", 93 | "def num_tokens_from_messages(messages, model=\"gpt-3.5-turbo-0301\"):\n", 94 | " encoding = tiktoken.encoding_for_model(model)\n", 95 | " num_tokens = 0\n", 96 | " for message in messages:\n", 97 | " num_tokens += 4 # every message follows {role/name}\\n{content}\\n\n", 98 | " for key, value in message.items():\n", 99 | " num_tokens += len(encoding.encode(value))\n", 100 | " if key == \"name\": # if there's a name, the role is omitted\n", 101 | " num_tokens += -1 # role is always required and always 1 token\n", 102 | " num_tokens += 2 # every reply is primed with assistant\n", 103 | " return num_tokens\n", 104 | "\n", 105 | "while(True):\n", 106 | " user_input = input(\"\") \n", 107 | " conversation.append({\"role\": \"user\", \"content\": user_input})\n", 108 | " conv_history_tokens = num_tokens_from_messages(conversation)\n", 109 | "\n", 110 | " while (conv_history_tokens+max_response_tokens >= token_limit):\n", 111 | " del conversation[1]\n", 112 | " conv_history_tokens = num_tokens_from_messages(conversation)\n", 113 | " \n", 114 | " response = openai.ChatCompletion.create(\n", 115 | " model=\"gpt-3.5-turbo\",\n", 116 | " messages = conversation,\n", 117 | " temperature=.7,\n", 118 | " max_tokens=max_response_tokens,\n", 119 | " )\n", 120 | "\n", 121 | " conversation.append({\"role\": \"assistant\", \"content\": response['choices'][0]['message']['content']})\n", 122 | " print(\"\\n\" + response['choices'][0]['message']['content'] + \"\\n\")\n" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": null, 128 | "id": "21905d09-c6fd-4450-b2c5-8b0e8978e852", 129 | "metadata": {}, 130 | "outputs": [], 131 | "source": [] 132 | } 133 | ], 134 | "metadata": { 135 | "kernelspec": { 136 | "display_name": "Python 3 (ipykernel)", 137 | "language": "python", 138 | "name": "python3" 139 | }, 140 | "language_info": { 141 | "codemirror_mode": { 142 | "name": "ipython", 143 | "version": 3 144 | }, 145 | "file_extension": ".py", 146 | "mimetype": "text/x-python", 147 | "name": "python", 148 | "nbconvert_exporter": "python", 149 | "pygments_lexer": "ipython3", 150 | "version": "3.11.1" 151 | } 152 | }, 153 | "nbformat": 4, 154 | "nbformat_minor": 5 155 | } 156 | -------------------------------------------------------------------------------- /chatgpt/ChatGPT_Flask_Demo/ChatGPT_Flask_Demo/ChatGPT_Flask_Demo.pyproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10.0 5 | Debug 6 | 2.0 7 | 1e90585c-8cac-4d28-861b-6d2f22acd5df 8 | . 9 | {789894c7-04a9-4a11-a6b5-3f4435165112};{1b580a1a-fdb3-4b32-83e1-6407eb2722e6};{349c5851-65df-11da-9384-00065b846f21};{888888a0-9f3d-457c-b088-3a5042f75d52} 10 | runserver.py 11 | 12 | 13 | . 14 | Web launcher 15 | http://localhost 16 | . 17 | true 18 | ChatGPT_Flask_Demo 19 | ChatGPT_Flask_Demo 20 | 21 | 22 | true 23 | false 24 | 25 | 26 | true 27 | false 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | True 59 | True 60 | http://localhost 61 | False 62 | 63 | 64 | 65 | 66 | 67 | 68 | CurrentPage 69 | True 70 | False 71 | False 72 | False 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | False 82 | False 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /chatgpt/ChatGPT_Flask_Demo/ChatGPT_Flask_Demo/ChatGPT_Flask_Demo.pyproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug|Any CPU 5 | 6 | -------------------------------------------------------------------------------- /chatgpt/ChatGPT_Flask_Demo/ChatGPT_Flask_Demo/ChatGPT_Flask_Demo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.32014.148 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "ChatGPT_Flask_Demo", "ChatGPT_Flask_Demo.pyproj", "{1E90585C-8CAC-4D28-861B-6D2F22ACD5DF}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {1E90585C-8CAC-4D28-861B-6D2F22ACD5DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {1E90585C-8CAC-4D28-861B-6D2F22ACD5DF}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {1E90585C-8CAC-4D28-861B-6D2F22ACD5DF}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {1E90585C-8CAC-4D28-861B-6D2F22ACD5DF}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {7F03A7D3-1F97-4218-9B42-D0BBA334EA6B} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /chatgpt/ChatGPT_Flask_Demo/ChatGPT_Flask_Demo/ChatGPT_Flask_Demo/__init__.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, request 2 | import os 3 | import openai 4 | openai.api_key = os.getenv("OPENAI_API_KEY") 5 | openai.organization = os.getenv("OPENAI_ORGANIZATION") 6 | 7 | conversation=[{"role": "system", "content": "You are a helpful assistant."}] 8 | 9 | app = Flask(__name__) 10 | 11 | #define app routes 12 | @app.route("/") 13 | def index(): 14 | return render_template("index.html") 15 | 16 | @app.route("/get") 17 | def completion_response(): 18 | user_input = request.args.get('msg') 19 | conversation.append({"role": "user", "content": user_input}) 20 | response = openai.ChatCompletion.create( 21 | model="gpt-3.5-turbo", 22 | messages = conversation, 23 | temperature=1, 24 | max_tokens=250, 25 | top_p=0.9 26 | ) 27 | 28 | conversation.append({"role": "assistant", "content": response['choices'][0]['message']['content']}) 29 | return str(response['choices'][0]['message']['content']) 30 | 31 | if __name__ == "__main__": 32 | app.run() -------------------------------------------------------------------------------- /chatgpt/ChatGPT_Flask_Demo/ChatGPT_Flask_Demo/ChatGPT_Flask_Demo/static/content/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #454654; 3 | } 4 | 5 | .userText { 6 | color: white; 7 | font-family: 'Segoe UI'; 8 | font-size: 14px; 9 | text-align: right; 10 | line-height: 30px; 11 | } 12 | 13 | .userText span { 14 | background-color: #009688; 15 | padding: 10px; 16 | border-radius: 2px; 17 | } 18 | 19 | .assistantText { 20 | color: white; 21 | font-family: 'Segoe UI'; 22 | font-size: 14px; 23 | text-align: left; 24 | line-height: 30px; 25 | } 26 | 27 | .assistantText span { 28 | background-color: #343541; 29 | padding: 10px; 30 | border-radius: 2px; 31 | } 32 | -------------------------------------------------------------------------------- /chatgpt/ChatGPT_Flask_Demo/ChatGPT_Flask_Demo/ChatGPT_Flask_Demo/static/scripts/bootstrap.min.js: -------------------------------------------------------------------------------- 1 | /* NUGET: BEGIN LICENSE TEXT 2 | * 3 | * Microsoft grants you the right to use these script files for the sole 4 | * purpose of either: (i) interacting through your browser with the Microsoft 5 | * website or online service, subject to the applicable licensing or use 6 | * terms; or (ii) using the files as included with a Microsoft product subject 7 | * to that product's license terms. Microsoft reserves all other rights to the 8 | * files not expressly granted by Microsoft, whether by implication, estoppel 9 | * or otherwise. Insofar as a script file is dual licensed under GPL, 10 | * Microsoft neither took the code under GPL nor distributes it thereunder but 11 | * under the terms set out in this paragraph. All notices and licenses 12 | * below are for informational purposes only. 13 | * 14 | * NUGET: END LICENSE TEXT */ 15 | 16 | /** 17 | * bootstrap.js v3.0.0 by @fat and @mdo 18 | * Copyright 2013 Twitter Inc. 19 | * http://www.apache.org/licenses/LICENSE-2.0 20 | */ 21 | if(!jQuery)throw new Error("Bootstrap requires jQuery");+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]}}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one(a.support.transition.end,function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b()})}(window.jQuery),+function(a){"use strict";var b='[data-dismiss="alert"]',c=function(c){a(c).on("click",b,this.close)};c.prototype.close=function(b){function c(){f.trigger("closed.bs.alert").remove()}var d=a(this),e=d.attr("data-target");e||(e=d.attr("href"),e=e&&e.replace(/.*(?=#[^\s]*$)/,""));var f=a(e);b&&b.preventDefault(),f.length||(f=d.hasClass("alert")?d:d.parent()),f.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(f.removeClass("in"),a.support.transition&&f.hasClass("fade")?f.one(a.support.transition.end,c).emulateTransitionEnd(150):c())};var d=a.fn.alert;a.fn.alert=function(b){return this.each(function(){var d=a(this),e=d.data("bs.alert");e||d.data("bs.alert",e=new c(this)),"string"==typeof b&&e[b].call(d)})},a.fn.alert.Constructor=c,a.fn.alert.noConflict=function(){return a.fn.alert=d,this},a(document).on("click.bs.alert.data-api",b,c.prototype.close)}(window.jQuery),+function(a){"use strict";var b=function(c,d){this.$element=a(c),this.options=a.extend({},b.DEFAULTS,d)};b.DEFAULTS={loadingText:"loading..."},b.prototype.setState=function(a){var b="disabled",c=this.$element,d=c.is("input")?"val":"html",e=c.data();a+="Text",e.resetText||c.data("resetText",c[d]()),c[d](e[a]||this.options[a]),setTimeout(function(){"loadingText"==a?c.addClass(b).attr(b,b):c.removeClass(b).removeAttr(b)},0)},b.prototype.toggle=function(){var a=this.$element.closest('[data-toggle="buttons"]');if(a.length){var b=this.$element.find("input").prop("checked",!this.$element.hasClass("active")).trigger("change");"radio"===b.prop("type")&&a.find(".active").removeClass("active")}this.$element.toggleClass("active")};var c=a.fn.button;a.fn.button=function(c){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof c&&c;e||d.data("bs.button",e=new b(this,f)),"toggle"==c?e.toggle():c&&e.setState(c)})},a.fn.button.Constructor=b,a.fn.button.noConflict=function(){return a.fn.button=c,this},a(document).on("click.bs.button.data-api","[data-toggle^=button]",function(b){var c=a(b.target);c.hasClass("btn")||(c=c.closest(".btn")),c.button("toggle"),b.preventDefault()})}(window.jQuery),+function(a){"use strict";var b=function(b,c){this.$element=a(b),this.$indicators=this.$element.find(".carousel-indicators"),this.options=c,this.paused=this.sliding=this.interval=this.$active=this.$items=null,"hover"==this.options.pause&&this.$element.on("mouseenter",a.proxy(this.pause,this)).on("mouseleave",a.proxy(this.cycle,this))};b.DEFAULTS={interval:5e3,pause:"hover",wrap:!0},b.prototype.cycle=function(b){return b||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(a.proxy(this.next,this),this.options.interval)),this},b.prototype.getActiveIndex=function(){return this.$active=this.$element.find(".item.active"),this.$items=this.$active.parent().children(),this.$items.index(this.$active)},b.prototype.to=function(b){var c=this,d=this.getActiveIndex();return b>this.$items.length-1||0>b?void 0:this.sliding?this.$element.one("slid",function(){c.to(b)}):d==b?this.pause().cycle():this.slide(b>d?"next":"prev",a(this.$items[b]))},b.prototype.pause=function(b){return b||(this.paused=!0),this.$element.find(".next, .prev").length&&a.support.transition.end&&(this.$element.trigger(a.support.transition.end),this.cycle(!0)),this.interval=clearInterval(this.interval),this},b.prototype.next=function(){return this.sliding?void 0:this.slide("next")},b.prototype.prev=function(){return this.sliding?void 0:this.slide("prev")},b.prototype.slide=function(b,c){var d=this.$element.find(".item.active"),e=c||d[b](),f=this.interval,g="next"==b?"left":"right",h="next"==b?"first":"last",i=this;if(!e.length){if(!this.options.wrap)return;e=this.$element.find(".item")[h]()}this.sliding=!0,f&&this.pause();var j=a.Event("slide.bs.carousel",{relatedTarget:e[0],direction:g});if(!e.hasClass("active")){if(this.$indicators.length&&(this.$indicators.find(".active").removeClass("active"),this.$element.one("slid",function(){var b=a(i.$indicators.children()[i.getActiveIndex()]);b&&b.addClass("active")})),a.support.transition&&this.$element.hasClass("slide")){if(this.$element.trigger(j),j.isDefaultPrevented())return;e.addClass(b),e[0].offsetWidth,d.addClass(g),e.addClass(g),d.one(a.support.transition.end,function(){e.removeClass([b,g].join(" ")).addClass("active"),d.removeClass(["active",g].join(" ")),i.sliding=!1,setTimeout(function(){i.$element.trigger("slid")},0)}).emulateTransitionEnd(600)}else{if(this.$element.trigger(j),j.isDefaultPrevented())return;d.removeClass("active"),e.addClass("active"),this.sliding=!1,this.$element.trigger("slid")}return f&&this.cycle(),this}};var c=a.fn.carousel;a.fn.carousel=function(c){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},b.DEFAULTS,d.data(),"object"==typeof c&&c),g="string"==typeof c?c:f.slide;e||d.data("bs.carousel",e=new b(this,f)),"number"==typeof c?e.to(c):g?e[g]():f.interval&&e.pause().cycle()})},a.fn.carousel.Constructor=b,a.fn.carousel.noConflict=function(){return a.fn.carousel=c,this},a(document).on("click.bs.carousel.data-api","[data-slide], [data-slide-to]",function(b){var c,d=a(this),e=a(d.attr("data-target")||(c=d.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,"")),f=a.extend({},e.data(),d.data()),g=d.attr("data-slide-to");g&&(f.interval=!1),e.carousel(f),(g=d.attr("data-slide-to"))&&e.data("bs.carousel").to(g),b.preventDefault()}),a(window).on("load",function(){a('[data-ride="carousel"]').each(function(){var b=a(this);b.carousel(b.data())})})}(window.jQuery),+function(a){"use strict";var b=function(c,d){this.$element=a(c),this.options=a.extend({},b.DEFAULTS,d),this.transitioning=null,this.options.parent&&(this.$parent=a(this.options.parent)),this.options.toggle&&this.toggle()};b.DEFAULTS={toggle:!0},b.prototype.dimension=function(){var a=this.$element.hasClass("width");return a?"width":"height"},b.prototype.show=function(){if(!this.transitioning&&!this.$element.hasClass("in")){var b=a.Event("show.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.$parent&&this.$parent.find("> .panel > .in");if(c&&c.length){var d=c.data("bs.collapse");if(d&&d.transitioning)return;c.collapse("hide"),d||c.data("bs.collapse",null)}var e=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[e](0),this.transitioning=1;var f=function(){this.$element.removeClass("collapsing").addClass("in")[e]("auto"),this.transitioning=0,this.$element.trigger("shown.bs.collapse")};if(!a.support.transition)return f.call(this);var g=a.camelCase(["scroll",e].join("-"));this.$element.one(a.support.transition.end,a.proxy(f,this)).emulateTransitionEnd(350)[e](this.$element[0][g])}}},b.prototype.hide=function(){if(!this.transitioning&&this.$element.hasClass("in")){var b=a.Event("hide.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.dimension();this.$element[c](this.$element[c]())[0].offsetHeight,this.$element.addClass("collapsing").removeClass("collapse").removeClass("in"),this.transitioning=1;var d=function(){this.transitioning=0,this.$element.trigger("hidden.bs.collapse").removeClass("collapsing").addClass("collapse")};return a.support.transition?(this.$element[c](0).one(a.support.transition.end,a.proxy(d,this)).emulateTransitionEnd(350),void 0):d.call(this)}}},b.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()};var c=a.fn.collapse;a.fn.collapse=function(c){return this.each(function(){var d=a(this),e=d.data("bs.collapse"),f=a.extend({},b.DEFAULTS,d.data(),"object"==typeof c&&c);e||d.data("bs.collapse",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.collapse.Constructor=b,a.fn.collapse.noConflict=function(){return a.fn.collapse=c,this},a(document).on("click.bs.collapse.data-api","[data-toggle=collapse]",function(b){var c,d=a(this),e=d.attr("data-target")||b.preventDefault()||(c=d.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,""),f=a(e),g=f.data("bs.collapse"),h=g?"toggle":d.data(),i=d.attr("data-parent"),j=i&&a(i);g&&g.transitioning||(j&&j.find('[data-toggle=collapse][data-parent="'+i+'"]').not(d).addClass("collapsed"),d[f.hasClass("in")?"addClass":"removeClass"]("collapsed")),f.collapse(h)})}(window.jQuery),+function(a){"use strict";function b(){a(d).remove(),a(e).each(function(b){var d=c(a(this));d.hasClass("open")&&(d.trigger(b=a.Event("hide.bs.dropdown")),b.isDefaultPrevented()||d.removeClass("open").trigger("hidden.bs.dropdown"))})}function c(b){var c=b.attr("data-target");c||(c=b.attr("href"),c=c&&/#/.test(c)&&c.replace(/.*(?=#[^\s]*$)/,""));var d=c&&a(c);return d&&d.length?d:b.parent()}var d=".dropdown-backdrop",e="[data-toggle=dropdown]",f=function(b){a(b).on("click.bs.dropdown",this.toggle)};f.prototype.toggle=function(d){var e=a(this);if(!e.is(".disabled, :disabled")){var f=c(e),g=f.hasClass("open");if(b(),!g){if("ontouchstart"in document.documentElement&&!f.closest(".navbar-nav").length&&a(''}),b.prototype=a.extend({},a.fn.tooltip.Constructor.prototype),b.prototype.constructor=b,b.prototype.getDefaults=function(){return b.DEFAULTS},b.prototype.setContent=function(){var a=this.tip(),b=this.getTitle(),c=this.getContent();a.find(".popover-title")[this.options.html?"html":"text"](b),a.find(".popover-content")[this.options.html?"html":"text"](c),a.removeClass("fade top bottom left right in"),a.find(".popover-title").html()||a.find(".popover-title").hide()},b.prototype.hasContent=function(){return this.getTitle()||this.getContent()},b.prototype.getContent=function(){var a=this.$element,b=this.options;return a.attr("data-content")||("function"==typeof b.content?b.content.call(a[0]):b.content)},b.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")},b.prototype.tip=function(){return this.$tip||(this.$tip=a(this.options.template)),this.$tip};var c=a.fn.popover;a.fn.popover=function(c){return this.each(function(){var d=a(this),e=d.data("bs.popover"),f="object"==typeof c&&c;e||d.data("bs.popover",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.popover.Constructor=b,a.fn.popover.noConflict=function(){return a.fn.popover=c,this}}(window.jQuery),+function(a){"use strict";function b(c,d){var e,f=a.proxy(this.process,this);this.$element=a(c).is("body")?a(window):a(c),this.$body=a("body"),this.$scrollElement=this.$element.on("scroll.bs.scroll-spy.data-api",f),this.options=a.extend({},b.DEFAULTS,d),this.selector=(this.options.target||(e=a(c).attr("href"))&&e.replace(/.*(?=#[^\s]+$)/,"")||"")+" .nav li > a",this.offsets=a([]),this.targets=a([]),this.activeTarget=null,this.refresh(),this.process()}b.DEFAULTS={offset:10},b.prototype.refresh=function(){var b=this.$element[0]==window?"offset":"position";this.offsets=a([]),this.targets=a([]);var c=this;this.$body.find(this.selector).map(function(){var d=a(this),e=d.data("target")||d.attr("href"),f=/^#\w/.test(e)&&a(e);return f&&f.length&&[[f[b]().top+(!a.isWindow(c.$scrollElement.get(0))&&c.$scrollElement.scrollTop()),e]]||null}).sort(function(a,b){return a[0]-b[0]}).each(function(){c.offsets.push(this[0]),c.targets.push(this[1])})},b.prototype.process=function(){var a,b=this.$scrollElement.scrollTop()+this.options.offset,c=this.$scrollElement[0].scrollHeight||this.$body[0].scrollHeight,d=c-this.$scrollElement.height(),e=this.offsets,f=this.targets,g=this.activeTarget;if(b>=d)return g!=(a=f.last()[0])&&this.activate(a);for(a=e.length;a--;)g!=f[a]&&b>=e[a]&&(!e[a+1]||b<=e[a+1])&&this.activate(f[a])},b.prototype.activate=function(b){this.activeTarget=b,a(this.selector).parents(".active").removeClass("active");var c=this.selector+'[data-target="'+b+'"],'+this.selector+'[href="'+b+'"]',d=a(c).parents("li").addClass("active");d.parent(".dropdown-menu").length&&(d=d.closest("li.dropdown").addClass("active")),d.trigger("activate")};var c=a.fn.scrollspy;a.fn.scrollspy=function(c){return this.each(function(){var d=a(this),e=d.data("bs.scrollspy"),f="object"==typeof c&&c;e||d.data("bs.scrollspy",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.scrollspy.Constructor=b,a.fn.scrollspy.noConflict=function(){return a.fn.scrollspy=c,this},a(window).on("load",function(){a('[data-spy="scroll"]').each(function(){var b=a(this);b.scrollspy(b.data())})})}(window.jQuery),+function(a){"use strict";var b=function(b){this.element=a(b)};b.prototype.show=function(){var b=this.element,c=b.closest("ul:not(.dropdown-menu)"),d=b.attr("data-target");if(d||(d=b.attr("href"),d=d&&d.replace(/.*(?=#[^\s]*$)/,"")),!b.parent("li").hasClass("active")){var e=c.find(".active:last a")[0],f=a.Event("show.bs.tab",{relatedTarget:e});if(b.trigger(f),!f.isDefaultPrevented()){var g=a(d);this.activate(b.parent("li"),c),this.activate(g,g.parent(),function(){b.trigger({type:"shown.bs.tab",relatedTarget:e})})}}},b.prototype.activate=function(b,c,d){function e(){f.removeClass("active").find("> .dropdown-menu > .active").removeClass("active"),b.addClass("active"),g?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu")&&b.closest("li.dropdown").addClass("active"),d&&d()}var f=c.find("> .active"),g=d&&a.support.transition&&f.hasClass("fade");g?f.one(a.support.transition.end,e).emulateTransitionEnd(150):e(),f.removeClass("in")};var c=a.fn.tab;a.fn.tab=function(c){return this.each(function(){var d=a(this),e=d.data("bs.tab");e||d.data("bs.tab",e=new b(this)),"string"==typeof c&&e[c]()})},a.fn.tab.Constructor=b,a.fn.tab.noConflict=function(){return a.fn.tab=c,this},a(document).on("click.bs.tab.data-api",'[data-toggle="tab"], [data-toggle="pill"]',function(b){b.preventDefault(),a(this).tab("show")})}(window.jQuery),+function(a){"use strict";var b=function(c,d){this.options=a.extend({},b.DEFAULTS,d),this.$window=a(window).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(c),this.affixed=this.unpin=null,this.checkPosition()};b.RESET="affix affix-top affix-bottom",b.DEFAULTS={offset:0},b.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},b.prototype.checkPosition=function(){if(this.$element.is(":visible")){var c=a(document).height(),d=this.$window.scrollTop(),e=this.$element.offset(),f=this.options.offset,g=f.top,h=f.bottom;"object"!=typeof f&&(h=g=f),"function"==typeof g&&(g=f.top()),"function"==typeof h&&(h=f.bottom());var i=null!=this.unpin&&d+this.unpin<=e.top?!1:null!=h&&e.top+this.$element.height()>=c-h?"bottom":null!=g&&g>=d?"top":!1;this.affixed!==i&&(this.unpin&&this.$element.css("top",""),this.affixed=i,this.unpin="bottom"==i?e.top-d:null,this.$element.removeClass(b.RESET).addClass("affix"+(i?"-"+i:"")),"bottom"==i&&this.$element.offset({top:document.body.offsetHeight-h-this.$element.height()}))}};var c=a.fn.affix;a.fn.affix=function(c){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof c&&c;e||d.data("bs.affix",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.affix.Constructor=b,a.fn.affix.noConflict=function(){return a.fn.affix=c,this},a(window).on("load",function(){a('[data-spy="affix"]').each(function(){var b=a(this),c=b.data();c.offset=c.offset||{},c.offsetBottom&&(c.offset.bottom=c.offsetBottom),c.offsetTop&&(c.offset.top=c.offsetTop),b.affix(c)})})}(window.jQuery); -------------------------------------------------------------------------------- /chatgpt/ChatGPT_Flask_Demo/ChatGPT_Flask_Demo/ChatGPT_Flask_Demo/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | 30 | 31 |
32 |
33 |
34 | 58 |
59 | 60 | -------------------------------------------------------------------------------- /chatgpt/ChatGPT_Flask_Demo/ChatGPT_Flask_Demo/obj/Any CPU/Debug/ChatGPT_Flask_Demo.pyproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpsConfig/OpenAI_Lab/1bcfe66ad79277e1d83ae1288db9b59b525c9053/chatgpt/ChatGPT_Flask_Demo/ChatGPT_Flask_Demo/obj/Any CPU/Debug/ChatGPT_Flask_Demo.pyproj.FileListAbsolute.txt -------------------------------------------------------------------------------- /chatgpt/ChatGPT_Flask_Demo/ChatGPT_Flask_Demo/runserver.py: -------------------------------------------------------------------------------- 1 | """ 2 | This script runs the ChatGPT_Flask_Demo application using a development server. 3 | """ 4 | 5 | from os import environ 6 | from ChatGPT_Flask_Demo import app 7 | 8 | if __name__ == '__main__': 9 | HOST = environ.get('SERVER_HOST', 'localhost') 10 | try: 11 | PORT = int(environ.get('SERVER_PORT', '5555')) 12 | except ValueError: 13 | PORT = 5555 14 | app.run(HOST, PORT) 15 | -------------------------------------------------------------------------------- /chatgpt/ChatGPT_Flask_Demo_v2/ChatGPT_Flask_Demo.pyproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10.0 5 | Debug 6 | 2.0 7 | 1e90585c-8cac-4d28-861b-6d2f22acd5df 8 | . 9 | {789894c7-04a9-4a11-a6b5-3f4435165112};{1b580a1a-fdb3-4b32-83e1-6407eb2722e6};{349c5851-65df-11da-9384-00065b846f21};{888888a0-9f3d-457c-b088-3a5042f75d52} 10 | runserver.py 11 | 12 | 13 | . 14 | Web launcher 15 | http://localhost 16 | . 17 | true 18 | ChatGPT_Flask_Demo 19 | ChatGPT_Flask_Demo 20 | 21 | 22 | true 23 | false 24 | 25 | 26 | true 27 | false 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | True 59 | True 60 | http://localhost 61 | False 62 | 63 | 64 | 65 | 66 | 67 | 68 | CurrentPage 69 | True 70 | False 71 | False 72 | False 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | False 82 | False 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /chatgpt/ChatGPT_Flask_Demo_v2/ChatGPT_Flask_Demo.pyproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug|Any CPU 5 | 6 | -------------------------------------------------------------------------------- /chatgpt/ChatGPT_Flask_Demo_v2/ChatGPT_Flask_Demo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.32014.148 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "ChatGPT_Flask_Demo", "ChatGPT_Flask_Demo.pyproj", "{1E90585C-8CAC-4D28-861B-6D2F22ACD5DF}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {1E90585C-8CAC-4D28-861B-6D2F22ACD5DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {1E90585C-8CAC-4D28-861B-6D2F22ACD5DF}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {1E90585C-8CAC-4D28-861B-6D2F22ACD5DF}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {1E90585C-8CAC-4D28-861B-6D2F22ACD5DF}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {7F03A7D3-1F97-4218-9B42-D0BBA334EA6B} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /chatgpt/ChatGPT_Flask_Demo_v2/ChatGPT_Flask_Demo/__init__.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, request 2 | import os 3 | import openai 4 | import tiktoken 5 | 6 | openai.api_key = os.getenv("OPENAI_API_KEY") 7 | openai.organization = os.getenv("OPENAI_ORGANIZATION") 8 | 9 | system_message = {"role": "system", "content": "You are a helpful assistant."} 10 | max_response_tokens = 250 11 | token_limit= 4096 12 | conversation=[] 13 | conversation.append(system_message) 14 | 15 | def num_tokens_from_messages(messages, model="gpt-3.5-turbo-0301"): 16 | encoding = tiktoken.encoding_for_model(model) 17 | num_tokens = 0 18 | for message in messages: 19 | num_tokens += 4 # every message follows {role/name}\n{content}\n 20 | for key, value in message.items(): 21 | num_tokens += len(encoding.encode(value)) 22 | if key == "name": # if there's a name, the role is omitted 23 | num_tokens += -1 # role is always required and always 1 token 24 | num_tokens += 2 # every reply is primed with assistant 25 | return num_tokens 26 | 27 | app = Flask(__name__) 28 | 29 | #define app routes 30 | @app.route("/") 31 | def index(): 32 | return render_template("index.html") 33 | 34 | @app.route("/get") 35 | def completion_response(): 36 | global conversation 37 | user_input = request.args.get('msg') 38 | conversation.append({"role": "user", "content": user_input}) 39 | conv_history_tokens = num_tokens_from_messages(conversation) 40 | 41 | while (conv_history_tokens+max_response_tokens >= token_limit): 42 | del conversation[1] 43 | conv_history_tokens = num_tokens_from_messages(conversation) 44 | 45 | response = openai.ChatCompletion.create( 46 | model="gpt-3.5-turbo", 47 | messages = conversation, 48 | temperature=1, 49 | max_tokens=max_response_tokens, 50 | top_p=0.9 51 | ) 52 | 53 | conversation.append({"role": "assistant", "content": response['choices'][0]['message']['content']}) 54 | return str(response['choices'][0]['message']['content']) 55 | 56 | if __name__ == "__main__": 57 | app.run() -------------------------------------------------------------------------------- /chatgpt/ChatGPT_Flask_Demo_v2/ChatGPT_Flask_Demo/static/content/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #454654; 3 | } 4 | 5 | .userText { 6 | color: white; 7 | font-family: 'Segoe UI'; 8 | font-size: 14px; 9 | text-align: right; 10 | line-height: 30px; 11 | } 12 | 13 | .userText span { 14 | background-color: #009688; 15 | padding: 10px; 16 | border-radius: 2px; 17 | } 18 | 19 | .assistantText { 20 | color: white; 21 | font-family: 'Segoe UI'; 22 | font-size: 14px; 23 | text-align: left; 24 | line-height: 30px; 25 | } 26 | 27 | .assistantText span { 28 | background-color: #343541; 29 | padding: 10px; 30 | border-radius: 2px; 31 | } 32 | -------------------------------------------------------------------------------- /chatgpt/ChatGPT_Flask_Demo_v2/ChatGPT_Flask_Demo/static/scripts/bootstrap.min.js: -------------------------------------------------------------------------------- 1 | /* NUGET: BEGIN LICENSE TEXT 2 | * 3 | * Microsoft grants you the right to use these script files for the sole 4 | * purpose of either: (i) interacting through your browser with the Microsoft 5 | * website or online service, subject to the applicable licensing or use 6 | * terms; or (ii) using the files as included with a Microsoft product subject 7 | * to that product's license terms. Microsoft reserves all other rights to the 8 | * files not expressly granted by Microsoft, whether by implication, estoppel 9 | * or otherwise. Insofar as a script file is dual licensed under GPL, 10 | * Microsoft neither took the code under GPL nor distributes it thereunder but 11 | * under the terms set out in this paragraph. All notices and licenses 12 | * below are for informational purposes only. 13 | * 14 | * NUGET: END LICENSE TEXT */ 15 | 16 | /** 17 | * bootstrap.js v3.0.0 by @fat and @mdo 18 | * Copyright 2013 Twitter Inc. 19 | * http://www.apache.org/licenses/LICENSE-2.0 20 | */ 21 | if(!jQuery)throw new Error("Bootstrap requires jQuery");+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]}}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one(a.support.transition.end,function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b()})}(window.jQuery),+function(a){"use strict";var b='[data-dismiss="alert"]',c=function(c){a(c).on("click",b,this.close)};c.prototype.close=function(b){function c(){f.trigger("closed.bs.alert").remove()}var d=a(this),e=d.attr("data-target");e||(e=d.attr("href"),e=e&&e.replace(/.*(?=#[^\s]*$)/,""));var f=a(e);b&&b.preventDefault(),f.length||(f=d.hasClass("alert")?d:d.parent()),f.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(f.removeClass("in"),a.support.transition&&f.hasClass("fade")?f.one(a.support.transition.end,c).emulateTransitionEnd(150):c())};var d=a.fn.alert;a.fn.alert=function(b){return this.each(function(){var d=a(this),e=d.data("bs.alert");e||d.data("bs.alert",e=new c(this)),"string"==typeof b&&e[b].call(d)})},a.fn.alert.Constructor=c,a.fn.alert.noConflict=function(){return a.fn.alert=d,this},a(document).on("click.bs.alert.data-api",b,c.prototype.close)}(window.jQuery),+function(a){"use strict";var b=function(c,d){this.$element=a(c),this.options=a.extend({},b.DEFAULTS,d)};b.DEFAULTS={loadingText:"loading..."},b.prototype.setState=function(a){var b="disabled",c=this.$element,d=c.is("input")?"val":"html",e=c.data();a+="Text",e.resetText||c.data("resetText",c[d]()),c[d](e[a]||this.options[a]),setTimeout(function(){"loadingText"==a?c.addClass(b).attr(b,b):c.removeClass(b).removeAttr(b)},0)},b.prototype.toggle=function(){var a=this.$element.closest('[data-toggle="buttons"]');if(a.length){var b=this.$element.find("input").prop("checked",!this.$element.hasClass("active")).trigger("change");"radio"===b.prop("type")&&a.find(".active").removeClass("active")}this.$element.toggleClass("active")};var c=a.fn.button;a.fn.button=function(c){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof c&&c;e||d.data("bs.button",e=new b(this,f)),"toggle"==c?e.toggle():c&&e.setState(c)})},a.fn.button.Constructor=b,a.fn.button.noConflict=function(){return a.fn.button=c,this},a(document).on("click.bs.button.data-api","[data-toggle^=button]",function(b){var c=a(b.target);c.hasClass("btn")||(c=c.closest(".btn")),c.button("toggle"),b.preventDefault()})}(window.jQuery),+function(a){"use strict";var b=function(b,c){this.$element=a(b),this.$indicators=this.$element.find(".carousel-indicators"),this.options=c,this.paused=this.sliding=this.interval=this.$active=this.$items=null,"hover"==this.options.pause&&this.$element.on("mouseenter",a.proxy(this.pause,this)).on("mouseleave",a.proxy(this.cycle,this))};b.DEFAULTS={interval:5e3,pause:"hover",wrap:!0},b.prototype.cycle=function(b){return b||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(a.proxy(this.next,this),this.options.interval)),this},b.prototype.getActiveIndex=function(){return this.$active=this.$element.find(".item.active"),this.$items=this.$active.parent().children(),this.$items.index(this.$active)},b.prototype.to=function(b){var c=this,d=this.getActiveIndex();return b>this.$items.length-1||0>b?void 0:this.sliding?this.$element.one("slid",function(){c.to(b)}):d==b?this.pause().cycle():this.slide(b>d?"next":"prev",a(this.$items[b]))},b.prototype.pause=function(b){return b||(this.paused=!0),this.$element.find(".next, .prev").length&&a.support.transition.end&&(this.$element.trigger(a.support.transition.end),this.cycle(!0)),this.interval=clearInterval(this.interval),this},b.prototype.next=function(){return this.sliding?void 0:this.slide("next")},b.prototype.prev=function(){return this.sliding?void 0:this.slide("prev")},b.prototype.slide=function(b,c){var d=this.$element.find(".item.active"),e=c||d[b](),f=this.interval,g="next"==b?"left":"right",h="next"==b?"first":"last",i=this;if(!e.length){if(!this.options.wrap)return;e=this.$element.find(".item")[h]()}this.sliding=!0,f&&this.pause();var j=a.Event("slide.bs.carousel",{relatedTarget:e[0],direction:g});if(!e.hasClass("active")){if(this.$indicators.length&&(this.$indicators.find(".active").removeClass("active"),this.$element.one("slid",function(){var b=a(i.$indicators.children()[i.getActiveIndex()]);b&&b.addClass("active")})),a.support.transition&&this.$element.hasClass("slide")){if(this.$element.trigger(j),j.isDefaultPrevented())return;e.addClass(b),e[0].offsetWidth,d.addClass(g),e.addClass(g),d.one(a.support.transition.end,function(){e.removeClass([b,g].join(" ")).addClass("active"),d.removeClass(["active",g].join(" ")),i.sliding=!1,setTimeout(function(){i.$element.trigger("slid")},0)}).emulateTransitionEnd(600)}else{if(this.$element.trigger(j),j.isDefaultPrevented())return;d.removeClass("active"),e.addClass("active"),this.sliding=!1,this.$element.trigger("slid")}return f&&this.cycle(),this}};var c=a.fn.carousel;a.fn.carousel=function(c){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},b.DEFAULTS,d.data(),"object"==typeof c&&c),g="string"==typeof c?c:f.slide;e||d.data("bs.carousel",e=new b(this,f)),"number"==typeof c?e.to(c):g?e[g]():f.interval&&e.pause().cycle()})},a.fn.carousel.Constructor=b,a.fn.carousel.noConflict=function(){return a.fn.carousel=c,this},a(document).on("click.bs.carousel.data-api","[data-slide], [data-slide-to]",function(b){var c,d=a(this),e=a(d.attr("data-target")||(c=d.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,"")),f=a.extend({},e.data(),d.data()),g=d.attr("data-slide-to");g&&(f.interval=!1),e.carousel(f),(g=d.attr("data-slide-to"))&&e.data("bs.carousel").to(g),b.preventDefault()}),a(window).on("load",function(){a('[data-ride="carousel"]').each(function(){var b=a(this);b.carousel(b.data())})})}(window.jQuery),+function(a){"use strict";var b=function(c,d){this.$element=a(c),this.options=a.extend({},b.DEFAULTS,d),this.transitioning=null,this.options.parent&&(this.$parent=a(this.options.parent)),this.options.toggle&&this.toggle()};b.DEFAULTS={toggle:!0},b.prototype.dimension=function(){var a=this.$element.hasClass("width");return a?"width":"height"},b.prototype.show=function(){if(!this.transitioning&&!this.$element.hasClass("in")){var b=a.Event("show.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.$parent&&this.$parent.find("> .panel > .in");if(c&&c.length){var d=c.data("bs.collapse");if(d&&d.transitioning)return;c.collapse("hide"),d||c.data("bs.collapse",null)}var e=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[e](0),this.transitioning=1;var f=function(){this.$element.removeClass("collapsing").addClass("in")[e]("auto"),this.transitioning=0,this.$element.trigger("shown.bs.collapse")};if(!a.support.transition)return f.call(this);var g=a.camelCase(["scroll",e].join("-"));this.$element.one(a.support.transition.end,a.proxy(f,this)).emulateTransitionEnd(350)[e](this.$element[0][g])}}},b.prototype.hide=function(){if(!this.transitioning&&this.$element.hasClass("in")){var b=a.Event("hide.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.dimension();this.$element[c](this.$element[c]())[0].offsetHeight,this.$element.addClass("collapsing").removeClass("collapse").removeClass("in"),this.transitioning=1;var d=function(){this.transitioning=0,this.$element.trigger("hidden.bs.collapse").removeClass("collapsing").addClass("collapse")};return a.support.transition?(this.$element[c](0).one(a.support.transition.end,a.proxy(d,this)).emulateTransitionEnd(350),void 0):d.call(this)}}},b.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()};var c=a.fn.collapse;a.fn.collapse=function(c){return this.each(function(){var d=a(this),e=d.data("bs.collapse"),f=a.extend({},b.DEFAULTS,d.data(),"object"==typeof c&&c);e||d.data("bs.collapse",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.collapse.Constructor=b,a.fn.collapse.noConflict=function(){return a.fn.collapse=c,this},a(document).on("click.bs.collapse.data-api","[data-toggle=collapse]",function(b){var c,d=a(this),e=d.attr("data-target")||b.preventDefault()||(c=d.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,""),f=a(e),g=f.data("bs.collapse"),h=g?"toggle":d.data(),i=d.attr("data-parent"),j=i&&a(i);g&&g.transitioning||(j&&j.find('[data-toggle=collapse][data-parent="'+i+'"]').not(d).addClass("collapsed"),d[f.hasClass("in")?"addClass":"removeClass"]("collapsed")),f.collapse(h)})}(window.jQuery),+function(a){"use strict";function b(){a(d).remove(),a(e).each(function(b){var d=c(a(this));d.hasClass("open")&&(d.trigger(b=a.Event("hide.bs.dropdown")),b.isDefaultPrevented()||d.removeClass("open").trigger("hidden.bs.dropdown"))})}function c(b){var c=b.attr("data-target");c||(c=b.attr("href"),c=c&&/#/.test(c)&&c.replace(/.*(?=#[^\s]*$)/,""));var d=c&&a(c);return d&&d.length?d:b.parent()}var d=".dropdown-backdrop",e="[data-toggle=dropdown]",f=function(b){a(b).on("click.bs.dropdown",this.toggle)};f.prototype.toggle=function(d){var e=a(this);if(!e.is(".disabled, :disabled")){var f=c(e),g=f.hasClass("open");if(b(),!g){if("ontouchstart"in document.documentElement&&!f.closest(".navbar-nav").length&&a(''}),b.prototype=a.extend({},a.fn.tooltip.Constructor.prototype),b.prototype.constructor=b,b.prototype.getDefaults=function(){return b.DEFAULTS},b.prototype.setContent=function(){var a=this.tip(),b=this.getTitle(),c=this.getContent();a.find(".popover-title")[this.options.html?"html":"text"](b),a.find(".popover-content")[this.options.html?"html":"text"](c),a.removeClass("fade top bottom left right in"),a.find(".popover-title").html()||a.find(".popover-title").hide()},b.prototype.hasContent=function(){return this.getTitle()||this.getContent()},b.prototype.getContent=function(){var a=this.$element,b=this.options;return a.attr("data-content")||("function"==typeof b.content?b.content.call(a[0]):b.content)},b.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")},b.prototype.tip=function(){return this.$tip||(this.$tip=a(this.options.template)),this.$tip};var c=a.fn.popover;a.fn.popover=function(c){return this.each(function(){var d=a(this),e=d.data("bs.popover"),f="object"==typeof c&&c;e||d.data("bs.popover",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.popover.Constructor=b,a.fn.popover.noConflict=function(){return a.fn.popover=c,this}}(window.jQuery),+function(a){"use strict";function b(c,d){var e,f=a.proxy(this.process,this);this.$element=a(c).is("body")?a(window):a(c),this.$body=a("body"),this.$scrollElement=this.$element.on("scroll.bs.scroll-spy.data-api",f),this.options=a.extend({},b.DEFAULTS,d),this.selector=(this.options.target||(e=a(c).attr("href"))&&e.replace(/.*(?=#[^\s]+$)/,"")||"")+" .nav li > a",this.offsets=a([]),this.targets=a([]),this.activeTarget=null,this.refresh(),this.process()}b.DEFAULTS={offset:10},b.prototype.refresh=function(){var b=this.$element[0]==window?"offset":"position";this.offsets=a([]),this.targets=a([]);var c=this;this.$body.find(this.selector).map(function(){var d=a(this),e=d.data("target")||d.attr("href"),f=/^#\w/.test(e)&&a(e);return f&&f.length&&[[f[b]().top+(!a.isWindow(c.$scrollElement.get(0))&&c.$scrollElement.scrollTop()),e]]||null}).sort(function(a,b){return a[0]-b[0]}).each(function(){c.offsets.push(this[0]),c.targets.push(this[1])})},b.prototype.process=function(){var a,b=this.$scrollElement.scrollTop()+this.options.offset,c=this.$scrollElement[0].scrollHeight||this.$body[0].scrollHeight,d=c-this.$scrollElement.height(),e=this.offsets,f=this.targets,g=this.activeTarget;if(b>=d)return g!=(a=f.last()[0])&&this.activate(a);for(a=e.length;a--;)g!=f[a]&&b>=e[a]&&(!e[a+1]||b<=e[a+1])&&this.activate(f[a])},b.prototype.activate=function(b){this.activeTarget=b,a(this.selector).parents(".active").removeClass("active");var c=this.selector+'[data-target="'+b+'"],'+this.selector+'[href="'+b+'"]',d=a(c).parents("li").addClass("active");d.parent(".dropdown-menu").length&&(d=d.closest("li.dropdown").addClass("active")),d.trigger("activate")};var c=a.fn.scrollspy;a.fn.scrollspy=function(c){return this.each(function(){var d=a(this),e=d.data("bs.scrollspy"),f="object"==typeof c&&c;e||d.data("bs.scrollspy",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.scrollspy.Constructor=b,a.fn.scrollspy.noConflict=function(){return a.fn.scrollspy=c,this},a(window).on("load",function(){a('[data-spy="scroll"]').each(function(){var b=a(this);b.scrollspy(b.data())})})}(window.jQuery),+function(a){"use strict";var b=function(b){this.element=a(b)};b.prototype.show=function(){var b=this.element,c=b.closest("ul:not(.dropdown-menu)"),d=b.attr("data-target");if(d||(d=b.attr("href"),d=d&&d.replace(/.*(?=#[^\s]*$)/,"")),!b.parent("li").hasClass("active")){var e=c.find(".active:last a")[0],f=a.Event("show.bs.tab",{relatedTarget:e});if(b.trigger(f),!f.isDefaultPrevented()){var g=a(d);this.activate(b.parent("li"),c),this.activate(g,g.parent(),function(){b.trigger({type:"shown.bs.tab",relatedTarget:e})})}}},b.prototype.activate=function(b,c,d){function e(){f.removeClass("active").find("> .dropdown-menu > .active").removeClass("active"),b.addClass("active"),g?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu")&&b.closest("li.dropdown").addClass("active"),d&&d()}var f=c.find("> .active"),g=d&&a.support.transition&&f.hasClass("fade");g?f.one(a.support.transition.end,e).emulateTransitionEnd(150):e(),f.removeClass("in")};var c=a.fn.tab;a.fn.tab=function(c){return this.each(function(){var d=a(this),e=d.data("bs.tab");e||d.data("bs.tab",e=new b(this)),"string"==typeof c&&e[c]()})},a.fn.tab.Constructor=b,a.fn.tab.noConflict=function(){return a.fn.tab=c,this},a(document).on("click.bs.tab.data-api",'[data-toggle="tab"], [data-toggle="pill"]',function(b){b.preventDefault(),a(this).tab("show")})}(window.jQuery),+function(a){"use strict";var b=function(c,d){this.options=a.extend({},b.DEFAULTS,d),this.$window=a(window).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(c),this.affixed=this.unpin=null,this.checkPosition()};b.RESET="affix affix-top affix-bottom",b.DEFAULTS={offset:0},b.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},b.prototype.checkPosition=function(){if(this.$element.is(":visible")){var c=a(document).height(),d=this.$window.scrollTop(),e=this.$element.offset(),f=this.options.offset,g=f.top,h=f.bottom;"object"!=typeof f&&(h=g=f),"function"==typeof g&&(g=f.top()),"function"==typeof h&&(h=f.bottom());var i=null!=this.unpin&&d+this.unpin<=e.top?!1:null!=h&&e.top+this.$element.height()>=c-h?"bottom":null!=g&&g>=d?"top":!1;this.affixed!==i&&(this.unpin&&this.$element.css("top",""),this.affixed=i,this.unpin="bottom"==i?e.top-d:null,this.$element.removeClass(b.RESET).addClass("affix"+(i?"-"+i:"")),"bottom"==i&&this.$element.offset({top:document.body.offsetHeight-h-this.$element.height()}))}};var c=a.fn.affix;a.fn.affix=function(c){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof c&&c;e||d.data("bs.affix",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.affix.Constructor=b,a.fn.affix.noConflict=function(){return a.fn.affix=c,this},a(window).on("load",function(){a('[data-spy="affix"]').each(function(){var b=a(this),c=b.data();c.offset=c.offset||{},c.offsetBottom&&(c.offset.bottom=c.offsetBottom),c.offsetTop&&(c.offset.top=c.offsetTop),b.affix(c)})})}(window.jQuery); -------------------------------------------------------------------------------- /chatgpt/ChatGPT_Flask_Demo_v2/ChatGPT_Flask_Demo/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | 30 | 31 |
32 |
33 |
34 | 58 |
59 | 60 | -------------------------------------------------------------------------------- /chatgpt/ChatGPT_Flask_Demo_v2/runserver.py: -------------------------------------------------------------------------------- 1 | """ 2 | This script runs the ChatGPT_Flask_Demo application using a development server. 3 | """ 4 | 5 | from os import environ 6 | from ChatGPT_Flask_Demo import app 7 | 8 | if __name__ == '__main__': 9 | HOST = environ.get('SERVER_HOST', 'localhost') 10 | try: 11 | PORT = int(environ.get('SERVER_PORT', '5555')) 12 | except ValueError: 13 | PORT = 5555 14 | app.run(HOST, PORT) 15 | -------------------------------------------------------------------------------- /embeddings_search/Context-based-search-med.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "id": "a008e623-4a2e-4818-a711-638a867fd88f", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import os\n", 11 | "import time\n", 12 | "import pandas as pd\n", 13 | "import openai\n", 14 | "import re\n", 15 | "import requests\n", 16 | "import sys\n", 17 | "from num2words import num2words\n", 18 | "import numpy as np\n", 19 | "from openai.embeddings_utils import get_embedding, cosine_similarity\n", 20 | "import tiktoken\n", 21 | "\n", 22 | "openai.api_key = os.getenv(\"OPENAI_API_KEY\") \n", 23 | "openai.organization = os.getenv(\"OPENAI_ORGANIZATION\") \n", 24 | "\n", 25 | "start_time=time.time()\n", 26 | "path ='c:\\\\path_to_your_directory_with_files_to_ingest'\n", 27 | "\n", 28 | "########### This helps takes care of removing metadata\n", 29 | "search_string = \"---\" \n", 30 | "metadata_counter = 0\n", 31 | "############\n", 32 | "d = []\n", 33 | "text=\"\"\n", 34 | "\n", 35 | "for root, directories, files in os.walk(path , topdown=False):\n", 36 | " for file in files:\n", 37 | " if file.lower().endswith(\".md\"):\n", 38 | " name =(os.path.join(root,file))\n", 39 | " f = open(name, \"r\",encoding=\"utf-8\")\n", 40 | " for line in f:\n", 41 | " if line.find(search_string) !=-1 and metadata_counter !=2:\n", 42 | " metadata_counter+=1\n", 43 | " if line.find(search_string) != 0 and metadata_counter==2:\n", 44 | " text +=line\n", 45 | " f.close()\n", 46 | " d.append({'FILE NAME': file ,'CONTENT': text})\n", 47 | " pd.DataFrame(d)\n", 48 | " metadata_counter = 0\n", 49 | " text=\"\"\n", 50 | "end_time = time.time()\n", 51 | "duration = end_time - start_time\n", 52 | "\n", 53 | "print (\"Script Execution: \", duration)" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": null, 59 | "id": "a771194f-f5bb-423e-a75e-ed0873313e2f", 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [ 63 | "df = pd.DataFrame(d)\n", 64 | "df" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": null, 70 | "id": "efca7fd2-d9d4-4422-b133-4803c5769772", 71 | "metadata": {}, 72 | "outputs": [], 73 | "source": [ 74 | "# s is input text\n", 75 | "def normalize_text(s, sep_token = \" \\n \"):\n", 76 | " s = re.sub(r'\\s+', ' ', s).strip()\n", 77 | " s = re.sub(r\". ,\",\"\",s)\n", 78 | " # remove all instances of multiple spaces\n", 79 | " s = s.replace(\"..\",\".\")\n", 80 | " s = s.replace(\". .\",\".\")\n", 81 | " s = s.replace(\"\\n\", \"\")\n", 82 | " s = s.replace(\"#\",\"\")\n", 83 | " s = s.strip()\n", 84 | " \n", 85 | " return s\n", 86 | "\n", 87 | "df['CONTENT'] = df[\"CONTENT\"].apply(lambda x : normalize_text(x))" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "id": "96b2508b-4b0c-417e-b3ff-0bb4ef738dd2", 93 | "metadata": {}, 94 | "source": [ 95 | "| GENERATION |TOKENIZER | MAX INPUT TOKENS| KNOWLEDGE CUTOFF|\n", 96 | "|------------|-------------|-----------------|-----------------|\n", 97 | "| V2 | cl100k_base | 8191 | Sep 2021 |\n", 98 | "| V1 | GPT-2/GPT-3 | 2046 | Aug 2020 |\n", 99 | "\n", 100 | "\n", 101 | "https://beta.openai.com/docs/guides/embeddings/what-are-embeddings\n", 102 | "\n", 103 | "https://openai.com/blog/new-and-improved-embedding-model/" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": null, 109 | "id": "bfe07d0a-ce24-4210-b1ce-a50faed184b5", 110 | "metadata": {}, 111 | "outputs": [], 112 | "source": [ 113 | "tokenizer = tiktoken.get_encoding(\"cl100k_base\")\n", 114 | "df['n_tokens'] = df[\"CONTENT\"].apply(lambda x: len(tokenizer.encode(x)))\n", 115 | "df" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": null, 121 | "id": "93b3f794-d584-4565-8ef5-86e127aed559", 122 | "metadata": {}, 123 | "outputs": [], 124 | "source": [ 125 | "# Based on https://openai.com/api/pricing/ on 01/29/2023\n", 126 | "# If you were using this for approximating pricing with Azure OpenAI adjust the values below with: https://azure.microsoft.com/pricing/details/cognitive-services/openai-service/\n", 127 | "\n", 128 | "#MODEL\tUSAGE\n", 129 | "#Ada v1\t$0.0040 / 1K tokens\n", 130 | "#Babbage v1\t$0.0050 / 1K tokens\n", 131 | "#Curie v1\t$0.0200 / 1K tokens\n", 132 | "#Davinci v1\t$0.2000 / 1K tokens\n", 133 | "\n", 134 | "#MODEL\tUSAGE\n", 135 | "#Ada v2\t$0.0004 / 1K tokens\n", 136 | "#This Ada model, text-embedding-ada-002, is a better and lower cost replacement for our older embedding models. \n", 137 | "\n", 138 | "n_tokens_sum = df['n_tokens'].sum()\n", 139 | "\n", 140 | "ada_v1_embeddings_cost = (n_tokens_sum/1000) *.0040\n", 141 | "babbage_v1_embeddings_cost = (n_tokens_sum/1000) *.0050\n", 142 | "curie_v1_embeddings_cost = (n_tokens_sum/1000) *.02\n", 143 | "davinci_v1_embeddings_cost = (n_tokens_sum/1000) *.2\n", 144 | "\n", 145 | "ada_v2_embeddings_cost = (n_tokens_sum/1000) *.0004\n", 146 | "\n", 147 | "print(\"Number of tokens: \" + str(n_tokens_sum) + \"\\n\")\n", 148 | "\n", 149 | "print(\"MODEL VERSION COST\")\n", 150 | "print(\"-----------------------------------\")\n", 151 | "print(\"Ada\" + \"\\t\\t\" + \"v1\" + \"\\t$\" + '%.8s' % str(ada_v1_embeddings_cost))\n", 152 | "print(\"Babbage\" + \"\\t\\t\" + \"v1\" + \"\\t$\" + '%.8s' % str(babbage_v1_embeddings_cost))\n", 153 | "print(\"Curie\" + \"\\t\\t\" + \"v1\" + \"\\t$\" + '%.8s' % str(curie_v1_embeddings_cost))\n", 154 | "print(\"Davinci\" + \"\\t\\t\" + \"v1\" + \"\\t$\" + '%.8s' % str(davinci_v1_embeddings_cost))\n", 155 | "print(\"Ada\" + \"\\t\\t\" + \"v2\" + \"\\t$\" + '%.8s' %str(ada_v2_embeddings_cost))" 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": null, 161 | "id": "258a9094-98bf-4d47-84a8-ff57ac7f590e", 162 | "metadata": {}, 163 | "outputs": [], 164 | "source": [ 165 | "len(df)" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": null, 171 | "id": "556b1d9c-e904-42d3-9584-dbf9733db562", 172 | "metadata": {}, 173 | "outputs": [], 174 | "source": [ 175 | "df = df[df.n_tokens<3500]\n", 176 | "\n", 177 | "len(df)" 178 | ] 179 | }, 180 | { 181 | "cell_type": "markdown", 182 | "id": "d7a8b721-aaeb-4c7a-a3d0-5edd27a48275", 183 | "metadata": {}, 184 | "source": [ 185 | "# OpenAI Text & Embedding Rate Limits?\n", 186 | "\n", 187 | "Rate limits are enforced at the **organization level, not user level**, based on the specific endpoint used as well as the type of account you have. \n", 188 | "\n", 189 | "Rate limits are measured in two ways: **RPM (requests per minute)** and **TPM (tokens per minute)**. \n", 190 | "\n", 191 | "## TEXT & EMBEDDING\n", 192 | "\n", 193 | "Free trial users •20 RPM •150,000 TPM\n", 194 | "\n", 195 | "Pay-as-you-go users (first 48 hours)\t•60 RPM •250,000 TPM\n", 196 | "\n", 197 | "Pay-as-you-go users (after 48 hours)\t•3,000 RPM •250,000 TPM\n", 198 | "\n", 199 | "https://beta.openai.com/docs/guides/rate-limits/overview" 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": null, 205 | "id": "6c918c32-d166-4ad2-9d81-9c3240f0dd0d", 206 | "metadata": {}, 207 | "outputs": [], 208 | "source": [ 209 | "import time\n", 210 | "from IPython.display import clear_output\n", 211 | "\n", 212 | "request_counter = 0\n", 213 | "total_requests_sent = 0\n", 214 | "rate_limit= 60\n", 215 | "\n", 216 | "def generate_embeddings(text, model=\"text-embedding-ada-002\"):\n", 217 | " global request_counter\n", 218 | " global rate_limit\n", 219 | " global total_requests_sent \n", 220 | " clear_output(wait=True)\n", 221 | " \n", 222 | " if text==\"\":\n", 223 | " text = \"blank\"\n", 224 | " print(\"Blank content field detected\")\n", 225 | " if request_counter < rate_limit:\n", 226 | " request_counter+=1\n", 227 | " total_requests_sent+=1\n", 228 | " print(\"Request counter: \", request_counter)\n", 229 | " print(\"Total requests sent: \", total_requests_sent)\n", 230 | " if request_counter == rate_limit:\n", 231 | " print(\"Sleeping for 60 seconds\")\n", 232 | " time.sleep(60)\n", 233 | " request_counter = 0\n", 234 | " \n", 235 | " return openai.Embedding.create(input = [text], model=model)['data'][0]['embedding']\n", 236 | " \n", 237 | "df['ada_v2_embedding'] = df.CONTENT.apply(lambda x: generate_embeddings(x, model='text-embedding-ada-002'))" 238 | ] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": null, 243 | "id": "3e892a12-c62b-4746-98b9-00642ad20c5d", 244 | "metadata": {}, 245 | "outputs": [], 246 | "source": [ 247 | "df" 248 | ] 249 | }, 250 | { 251 | "cell_type": "code", 252 | "execution_count": null, 253 | "id": "b4468ce5-fe77-4e67-8f23-1fac4e285e6a", 254 | "metadata": {}, 255 | "outputs": [], 256 | "source": [ 257 | "# search embedded docs based on cosine similarity\n", 258 | "\n", 259 | "def get_embedding(text, model=\"text-embedding-ada-002\"):\n", 260 | " return openai.Embedding.create(input = [text], model=model)['data'][0]['embedding']\n", 261 | "\n", 262 | "def search_docs(df, user_query, top_n=3, to_print=True):\n", 263 | " embedding = get_embedding(\n", 264 | " user_query,\n", 265 | " model=\"text-embedding-ada-002\"\n", 266 | " )\n", 267 | " df[\"similarities\"] = df.ada_v2_embedding.apply(lambda x: cosine_similarity(x, embedding))\n", 268 | "\n", 269 | " res = (\n", 270 | " df.sort_values(\"similarities\", ascending=False)\n", 271 | " .head(top_n)\n", 272 | " )\n", 273 | " if to_print:\n", 274 | " display(res)\n", 275 | " return res\n", 276 | "\n", 277 | "question = input(\"How can I help you?\\n\\n\")\n", 278 | "\n", 279 | "res = search_docs(df, question, top_n=3)" 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": null, 285 | "id": "438e5363-b22e-4564-8c21-bd388d3fae8d", 286 | "metadata": {}, 287 | "outputs": [], 288 | "source": [ 289 | "res.CONTENT.values[0]" 290 | ] 291 | }, 292 | { 293 | "cell_type": "code", 294 | "execution_count": null, 295 | "id": "1bdac244-b3ba-4b1c-a8cd-5215e49d3a99", 296 | "metadata": {}, 297 | "outputs": [], 298 | "source": [ 299 | "def search_docs(df, user_query, top_n=3, to_print=True):\n", 300 | " embedding = get_embedding(\n", 301 | " user_query,\n", 302 | " model=\"text-embedding-ada-002\"\n", 303 | " )\n", 304 | " df[\"similarities\"] = df.ada_v2_embedding.apply(lambda x: cosine_similarity(x, embedding))\n", 305 | "\n", 306 | " res = (\n", 307 | " df.sort_values(\"similarities\", ascending=False)\n", 308 | " .head(top_n)\n", 309 | " )\n", 310 | " return res\n", 311 | "\n", 312 | "res = search_docs(df, question, top_n=1)\n", 313 | "\n", 314 | "ai_question = input(\"How can I help you?\\n\\n\")\n", 315 | "context= res.CONTENT.values\n", 316 | "completion_model='text-davinci-003'\n", 317 | "\n", 318 | "initial_prompt = \"The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.\"\n", 319 | "\n", 320 | "combined_prompt = initial_prompt + str(context) + \"Q: \" + ai_question\n", 321 | "response = openai.Completion.create(model=completion_model, prompt=combined_prompt, max_tokens=100)\n", 322 | "ai_response = response['choices'][0]['text'].replace('\\n', '').replace(' .', '.').strip()\n", 323 | "\n", 324 | "print(\"\\n\"+ ai_response)" 325 | ] 326 | }, 327 | { 328 | "cell_type": "code", 329 | "execution_count": null, 330 | "id": "4b0cc12b-8926-4b77-82ea-5fc18ebcf008", 331 | "metadata": {}, 332 | "outputs": [], 333 | "source": [] 334 | } 335 | ], 336 | "metadata": { 337 | "kernelspec": { 338 | "display_name": "Python 3 (ipykernel)", 339 | "language": "python", 340 | "name": "python3" 341 | }, 342 | "language_info": { 343 | "codemirror_mode": { 344 | "name": "ipython", 345 | "version": 3 346 | }, 347 | "file_extension": ".py", 348 | "mimetype": "text/x-python", 349 | "name": "python", 350 | "nbconvert_exporter": "python", 351 | "pygments_lexer": "ipython3", 352 | "version": "3.11.1" 353 | } 354 | }, 355 | "nbformat": 4, 356 | "nbformat_minor": 5 357 | } 358 | -------------------------------------------------------------------------------- /embeddings_search/Context-based-search-mini.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "8ff5221c-0c3e-479f-aca3-90a57595d455", 6 | "metadata": {}, 7 | "source": [ 8 | "# What will this video cover?\n", 9 | "\n", 10 | "- New OpenAI Embeddings model\n", 11 | "- Concrete example with real-world data in the form of markdown documentation.\n", 12 | "- Using embeddings and search with cosine similarity to provide context to a completion call without needing to create a fine-tuned model.\n", 13 | "- Basic process around handling small/medium/largeish datasets\n", 14 | "- Get you thinking about what things cost as you scale and rate limits \n" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "id": "474be77b-3079-4fa8-995b-da6ca5907124", 21 | "metadata": {}, 22 | "outputs": [], 23 | "source": [ 24 | "import os\n", 25 | "import time\n", 26 | "import pandas as pd\n", 27 | "import openai\n", 28 | "import re\n", 29 | "import requests\n", 30 | "import sys\n", 31 | "from num2words import num2words\n", 32 | "import numpy as np\n", 33 | "from openai.embeddings_utils import get_embedding, cosine_similarity\n", 34 | "import tiktoken\n", 35 | "\n", 36 | "openai.api_key = os.getenv(\"OPENAI_API_KEY\") \n", 37 | "openai.organization = os.getenv(\"OPENAI_ORGANIZATION\") \n", 38 | "\n", 39 | "start_time=time.time()\n", 40 | "path ='c:\\\\Path_to_the_directory_with_the_files_you_want_to_ingest' #example: 'c:\\\\openai\\\\test'\n", 41 | "\n", 42 | "########### This helps takes care of removing metadata\n", 43 | "search_string = \"---\" \n", 44 | "metadata_counter = 0\n", 45 | "############\n", 46 | "\n", 47 | "d = []\n", 48 | "text=\"\"\n", 49 | "\n", 50 | "for root, directories, files in os.walk(path , topdown=False):\n", 51 | " for file in files:\n", 52 | " if file.lower().endswith(\".md\"):\n", 53 | " name =(os.path.join(root,file))\n", 54 | " f = open(name, \"r\",encoding=\"utf-8\")\n", 55 | " for line in f:\n", 56 | " if line.find(search_string) !=-1 and metadata_counter !=2:\n", 57 | " metadata_counter+=1\n", 58 | " if line.find(search_string) != 0 and metadata_counter==2:\n", 59 | " text +=line\n", 60 | " f.close()\n", 61 | " d.append({'FILE NAME': file ,'CONTENT': text})\n", 62 | " pd.DataFrame(d)\n", 63 | " metadata_counter = 0\n", 64 | " text=\"\"\n", 65 | "end_time = time.time()\n", 66 | "duration = end_time - start_time\n", 67 | "\n", 68 | "print (\"Cell Run Time: \", duration)" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "id": "6c02e8c3-d125-4a6b-bb45-6901ba699b77", 75 | "metadata": {}, 76 | "outputs": [], 77 | "source": [ 78 | "df = pd.DataFrame(d)\n", 79 | "df" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 17, 85 | "id": "6b6ad67c-524c-427f-aeaf-f52c1c9d6539", 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [ 89 | "# s is input text\n", 90 | "def normalize_text(s, sep_token = \" \\n \"):\n", 91 | " s = re.sub(r'\\s+', ' ', s).strip()\n", 92 | " s = re.sub(r\". ,\",\"\",s)\n", 93 | " # remove all instances of multiple spaces\n", 94 | " s = s.replace(\"..\",\".\")\n", 95 | " s = s.replace(\". .\",\".\")\n", 96 | " s = s.replace(\"\\n\", \"\")\n", 97 | " s = s.replace(\"#\",\"\")\n", 98 | " s = s.strip()\n", 99 | " \n", 100 | " return s\n", 101 | "\n", 102 | "df['CONTENT'] = df[\"CONTENT\"].apply(lambda x : normalize_text(x))" 103 | ] 104 | }, 105 | { 106 | "cell_type": "markdown", 107 | "id": "96b2508b-4b0c-417e-b3ff-0bb4ef738dd2", 108 | "metadata": {}, 109 | "source": [ 110 | "| GENERATION |TOKENIZER | MAX INPUT TOKENS| KNOWLEDGE CUTOFF|\n", 111 | "|------------|-------------|-----------------|-----------------|\n", 112 | "| V2 | cl100k_base | 8191 | Sep 2021 |\n", 113 | "| V1 | GPT-2/GPT-3 | 2046 | Aug 2020 |\n", 114 | "\n", 115 | "\n", 116 | "https://beta.openai.com/docs/guides/embeddings/what-are-embeddings\n", 117 | "\n", 118 | "https://openai.com/blog/new-and-improved-embedding-model/" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": null, 124 | "id": "c73cdf8e-fd02-4398-be26-496f4022a797", 125 | "metadata": {}, 126 | "outputs": [], 127 | "source": [ 128 | "tokenizer = tiktoken.get_encoding(\"cl100k_base\")\n", 129 | "df['n_tokens'] = df[\"CONTENT\"].apply(lambda x: len(tokenizer.encode(x)))\n", 130 | "df" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 19, 136 | "id": "317ba3dd-1d9f-44f7-b8f0-14ff1f8937cf", 137 | "metadata": {}, 138 | "outputs": [ 139 | { 140 | "name": "stdout", 141 | "output_type": "stream", 142 | "text": [ 143 | "Number of tokens: 56017\n", 144 | "\n", 145 | "MODEL VERSION COST\n", 146 | "-----------------------------------\n", 147 | "Ada\t\tv1\t$0.224068\n", 148 | "Babbage\t\tv1\t$0.280085\n", 149 | "Curie\t\tv1\t$1.120340\n", 150 | "Davinci\t\tv1\t$11.20340\n", 151 | "Ada\t\tv2\t$0.022406\n" 152 | ] 153 | } 154 | ], 155 | "source": [ 156 | "# Based on https://openai.com/api/pricing/ on 01/29/2023\n", 157 | "# If you were using this for approximating pricing with Azure OpenAI adjust the values below with: https://azure.microsoft.com/pricing/details/cognitive-services/openai-service/\n", 158 | "\n", 159 | "#MODEL\tUSAGE\n", 160 | "#Ada v1\t$0.0040 / 1K tokens\n", 161 | "#Babbage v1\t$0.0050 / 1K tokens\n", 162 | "#Curie v1\t$0.0200 / 1K tokens\n", 163 | "#Davinci v1\t$0.2000 / 1K tokens\n", 164 | "\n", 165 | "#MODEL\tUSAGE\n", 166 | "#Ada v2\t$0.0004 / 1K tokens\n", 167 | "#This Ada model, text-embedding-ada-002, is a better and lower cost replacement for our older embedding models. \n", 168 | "\n", 169 | "n_tokens_sum = df['n_tokens'].sum()\n", 170 | "\n", 171 | "ada_v1_embeddings_cost = (n_tokens_sum/1000) *.0040\n", 172 | "babbage_v1_embeddings_cost = (n_tokens_sum/1000) *.0050\n", 173 | "curie_v1_embeddings_cost = (n_tokens_sum/1000) *.02\n", 174 | "davinci_v1_embeddings_cost = (n_tokens_sum/1000) *.2\n", 175 | "\n", 176 | "ada_v2_embeddings_cost = (n_tokens_sum/1000) *.0004\n", 177 | "\n", 178 | "print(\"Number of tokens: \" + str(n_tokens_sum) + \"\\n\")\n", 179 | "\n", 180 | "print(\"MODEL VERSION COST\")\n", 181 | "print(\"-----------------------------------\")\n", 182 | "print(\"Ada\" + \"\\t\\t\" + \"v1\" + \"\\t$\" + '%.8s' % str(ada_v1_embeddings_cost))\n", 183 | "print(\"Babbage\" + \"\\t\\t\" + \"v1\" + \"\\t$\" + '%.8s' % str(babbage_v1_embeddings_cost))\n", 184 | "print(\"Curie\" + \"\\t\\t\" + \"v1\" + \"\\t$\" + '%.8s' % str(curie_v1_embeddings_cost))\n", 185 | "print(\"Davinci\" + \"\\t\\t\" + \"v1\" + \"\\t$\" + '%.8s' % str(davinci_v1_embeddings_cost))\n", 186 | "print(\"Ada\" + \"\\t\\t\" + \"v2\" + \"\\t$\" + '%.8s' %str(ada_v2_embeddings_cost))" 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": null, 192 | "id": "f4f54203-0e5f-49c6-be0f-e7a1981f1c86", 193 | "metadata": {}, 194 | "outputs": [], 195 | "source": [ 196 | "def generate_embeddings(text, model=\"text-embedding-ada-002\"):\n", 197 | " return openai.Embedding.create(input = [text], model=model)['data'][0]['embedding']\n", 198 | " \n", 199 | "df['ada_v2_embedding'] = df.CONTENT.apply(lambda x: generate_embeddings(x, model='text-embedding-ada-002'))" 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": null, 205 | "id": "d7c1b5cb-304e-41e3-a4f1-8058dd112c94", 206 | "metadata": {}, 207 | "outputs": [], 208 | "source": [ 209 | "df" 210 | ] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": null, 215 | "id": "7dddc011-ff4d-4c7c-a717-70046957fd81", 216 | "metadata": {}, 217 | "outputs": [], 218 | "source": [ 219 | "# search embedded docs based on cosine similarity\n", 220 | "\n", 221 | "def get_embedding(text, model=\"text-embedding-ada-002\"):\n", 222 | " return openai.Embedding.create(input = [text], model=model)['data'][0]['embedding']\n", 223 | "\n", 224 | "def search_docs(df, user_query, top_n=3, to_print=True):\n", 225 | " embedding = get_embedding(\n", 226 | " user_query,\n", 227 | " model=\"text-embedding-ada-002\"\n", 228 | " )\n", 229 | " df[\"similarities\"] = df.ada_v2_embedding.apply(lambda x: cosine_similarity(x, embedding))\n", 230 | "\n", 231 | " res = (\n", 232 | " df.sort_values(\"similarities\", ascending=False)\n", 233 | " .head(top_n)\n", 234 | " )\n", 235 | " if to_print:\n", 236 | " display(res)\n", 237 | " return res\n", 238 | "\n", 239 | "question = input(\"How can I help you?\\n\\n\")\n", 240 | "\n", 241 | "res = search_docs(df, question, top_n=3)" 242 | ] 243 | }, 244 | { 245 | "cell_type": "code", 246 | "execution_count": null, 247 | "id": "fbd7ae93-b6f3-49e1-84f4-775a9abf5233", 248 | "metadata": {}, 249 | "outputs": [], 250 | "source": [ 251 | "res.CONTENT.values[0]" 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "execution_count": null, 257 | "id": "d1c4876f-f68c-4f5a-9343-c1e2a4444886", 258 | "metadata": {}, 259 | "outputs": [], 260 | "source": [ 261 | "def search_docs(df, user_query, top_n=3, to_print=True):\n", 262 | " embedding = get_embedding(\n", 263 | " user_query,\n", 264 | " model=\"text-embedding-ada-002\"\n", 265 | " )\n", 266 | " df[\"similarities\"] = df.ada_v2_embedding.apply(lambda x: cosine_similarity(x, embedding))\n", 267 | "\n", 268 | " res = (\n", 269 | " df.sort_values(\"similarities\", ascending=False)\n", 270 | " .head(top_n)\n", 271 | " )\n", 272 | " return res\n", 273 | "\n", 274 | "res = search_docs(df, question, top_n=1)\n", 275 | "\n", 276 | "ai_question = input(\"How can I help you?\\n\\n\")\n", 277 | "\n", 278 | "\n", 279 | "context= res.CONTENT.values\n", 280 | "completion_model='text-davinci-003'\n", 281 | "\n", 282 | "initial_prompt = \"The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.\"\n", 283 | "\n", 284 | "combined_prompt = initial_prompt + str(context) + \"Q: \" + ai_question\n", 285 | "response = openai.Completion.create(model=completion_model, prompt=combined_prompt, max_tokens=100)\n", 286 | "ai_response = response['choices'][0]['text'].replace('\\n', '').replace(' .', '.').strip()\n", 287 | "\n", 288 | "print(\"\\n\"+ ai_response)" 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": null, 294 | "id": "6afaa1ec-da70-4d66-8059-c169e9ae4c17", 295 | "metadata": {}, 296 | "outputs": [], 297 | "source": [ 298 | "print(combined_prompt)" 299 | ] 300 | }, 301 | { 302 | "cell_type": "code", 303 | "execution_count": null, 304 | "id": "44cab553-534b-4564-b9b9-7bd63bd2c077", 305 | "metadata": {}, 306 | "outputs": [], 307 | "source": [] 308 | } 309 | ], 310 | "metadata": { 311 | "kernelspec": { 312 | "display_name": "Python 3 (ipykernel)", 313 | "language": "python", 314 | "name": "python3" 315 | }, 316 | "language_info": { 317 | "codemirror_mode": { 318 | "name": "ipython", 319 | "version": 3 320 | }, 321 | "file_extension": ".py", 322 | "mimetype": "text/x-python", 323 | "name": "python", 324 | "nbconvert_exporter": "python", 325 | "pygments_lexer": "ipython3", 326 | "version": "3.11.1" 327 | } 328 | }, 329 | "nbformat": 4, 330 | "nbformat_minor": 5 331 | } 332 | -------------------------------------------------------------------------------- /tokenization/tokenizer_flask/Tokenizer_Demo.pyproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10.0 5 | Debug 6 | 2.0 7 | 1e90585c-8cac-4d28-861b-6d2f22acd5df 8 | 9 | 10 | {789894c7-04a9-4a11-a6b5-3f4435165112};{1b580a1a-fdb3-4b32-83e1-6407eb2722e6};{349c5851-65df-11da-9384-00065b846f21};{888888a0-9f3d-457c-b088-3a5042f75d52} 11 | runserver.py 12 | 13 | 14 | . 15 | Web launcher 16 | http://localhost 17 | . 18 | true 19 | Tokenizer_Demo 20 | ChatGPT_Flask_Demo 21 | 22 | 23 | true 24 | false 25 | 26 | 27 | true 28 | false 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | True 62 | True 63 | http://localhost 64 | False 65 | 66 | 67 | 68 | 69 | 70 | 71 | CurrentPage 72 | True 73 | False 74 | False 75 | False 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | False 85 | False 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /tokenization/tokenizer_flask/Tokenizer_Demo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.32014.148 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "Tokenizer_Demo", "Tokenizer_Demo.pyproj", "{1E90585C-8CAC-4D28-861B-6D2F22ACD5DF}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {1E90585C-8CAC-4D28-861B-6D2F22ACD5DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {1E90585C-8CAC-4D28-861B-6D2F22ACD5DF}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {1E90585C-8CAC-4D28-861B-6D2F22ACD5DF}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {1E90585C-8CAC-4D28-861B-6D2F22ACD5DF}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {7F03A7D3-1F97-4218-9B42-D0BBA334EA6B} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /tokenization/tokenizer_flask/Tokenizer_Demo/__init__.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, request 2 | import tiktoken 3 | import json 4 | 5 | app = Flask(__name__) 6 | 7 | @app.route("/") 8 | def index(): 9 | return render_template("index.html") 10 | 11 | @app.route("/get") 12 | def tokenizer_response(): 13 | tokenizer_value = request.args.get('tokenizer') 14 | tokenizer = tiktoken.get_encoding(tokenizer_value) 15 | token_list = [] 16 | user_input= request.args.get('msg') 17 | encode = tokenizer.encode(user_input) 18 | decode = tokenizer.decode_tokens_bytes(encode) 19 | 20 | for token in decode: 21 | try: 22 | token_list.append(token.decode()) 23 | except UnicodeDecodeError: # Edge case for when unicode character was broken into multiple tokens decode will error out. 24 | token_list.append("�") # Replace the token with the Unicode replacement character 25 | 26 | character_count = sum(len(i) for i in token_list) 27 | length = len(encode) 28 | 29 | quoted_token_list = ["'{}'".format(token) for token in token_list] 30 | 31 | response_data = { 32 | "token_list": quoted_token_list, 33 | "encode": encode, 34 | "length": length, 35 | "character_count": character_count 36 | } 37 | 38 | # Convert the dictionary to a JSON string using json.dumps() 39 | return json.dumps(response_data) 40 | 41 | 42 | 43 | if __name__ == "__main__": 44 | app.run() -------------------------------------------------------------------------------- /tokenization/tokenizer_flask/Tokenizer_Demo/static/content/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #454654; 3 | } 4 | 5 | .userText { 6 | color: white; 7 | font-family: 'Segoe UI'; 8 | font-size: 14px; 9 | text-align: left; 10 | line-height: 30px; 11 | } 12 | 13 | .form-check-label { 14 | color: white; 15 | font-family: 'Segoe UI'; 16 | font-size: 12px; 17 | } 18 | 19 | .highlight { 20 | background-color: yellow; 21 | } 22 | 23 | .card-body { 24 | color: white; 25 | font-family: 'Segoe UI'; 26 | font-size: 30px; 27 | text-align: left; 28 | line-height: 30px; 29 | border: thin; 30 | border-color: aqua 31 | } 32 | 33 | .userText span { 34 | background-color: #27B5EA66; 35 | } 36 | 37 | .tokenizedResults { 38 | color: white; 39 | font-family: 'Segoe UI'; 40 | font-size: 14px; 41 | text-align: left; 42 | line-height: 30px; 43 | } 44 | 45 | 46 | .tokenizedResults span { 47 | padding: 0; 48 | border-radius: 2px; 49 | word-wrap: break-word; 50 | } 51 | 52 | .bg-color-0 { 53 | background-color: #6B40D84D; 54 | display: inline; 55 | } 56 | 57 | .bg-color-1 { 58 | background-color: #68DE7A66; 59 | display: inline; 60 | } 61 | 62 | .bg-color-2 { 63 | background-color: #F4AC3666; 64 | display: inline; 65 | } 66 | 67 | .bg-color-3 { 68 | background-color: #27B5EA66; 69 | display: inline; 70 | } 71 | 72 | .bg-color-4 { 73 | background-color: #Ef414666; 74 | display: inline; 75 | } 76 | 77 | .btn-custom { 78 | width: 100px; 79 | margin-left: 0px; 80 | margin-right: 2px; 81 | } 82 | 83 | 84 | .btn-clear { 85 | background-color: #Ef414666; 86 | color: white; 87 | } 88 | 89 | .tokenizedResults span.bg-color-0, 90 | .tokenizedResults span.bg-color-1, 91 | .tokenizedResults span.bg-color-2, 92 | .tokenizedResults span.bg-color-3, 93 | .tokenizedResults span.bg-color-4 { 94 | padding: 1px 5px; 95 | margin: 0; 96 | } 97 | 98 | .btn-disabled { 99 | background-color: #ccc; 100 | border-color: #ccc; 101 | } 102 | 103 | .tokenizedResults span[data-index]:hover { 104 | transform: scale(2); 105 | position: relative; 106 | display: inline-block; 107 | z-index: 1; 108 | } 109 | 110 | -------------------------------------------------------------------------------- /tokenization/tokenizer_flask/Tokenizer_Demo/static/scripts/bootstrap.min.js: -------------------------------------------------------------------------------- 1 | /* NUGET: BEGIN LICENSE TEXT 2 | * 3 | * Microsoft grants you the right to use these script files for the sole 4 | * purpose of either: (i) interacting through your browser with the Microsoft 5 | * website or online service, subject to the applicable licensing or use 6 | * terms; or (ii) using the files as included with a Microsoft product subject 7 | * to that product's license terms. Microsoft reserves all other rights to the 8 | * files not expressly granted by Microsoft, whether by implication, estoppel 9 | * or otherwise. Insofar as a script file is dual licensed under GPL, 10 | * Microsoft neither took the code under GPL nor distributes it thereunder but 11 | * under the terms set out in this paragraph. All notices and licenses 12 | * below are for informational purposes only. 13 | * 14 | * NUGET: END LICENSE TEXT */ 15 | 16 | /** 17 | * bootstrap.js v3.0.0 by @fat and @mdo 18 | * Copyright 2013 Twitter Inc. 19 | * http://www.apache.org/licenses/LICENSE-2.0 20 | */ 21 | if(!jQuery)throw new Error("Bootstrap requires jQuery");+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]}}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one(a.support.transition.end,function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b()})}(window.jQuery),+function(a){"use strict";var b='[data-dismiss="alert"]',c=function(c){a(c).on("click",b,this.close)};c.prototype.close=function(b){function c(){f.trigger("closed.bs.alert").remove()}var d=a(this),e=d.attr("data-target");e||(e=d.attr("href"),e=e&&e.replace(/.*(?=#[^\s]*$)/,""));var f=a(e);b&&b.preventDefault(),f.length||(f=d.hasClass("alert")?d:d.parent()),f.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(f.removeClass("in"),a.support.transition&&f.hasClass("fade")?f.one(a.support.transition.end,c).emulateTransitionEnd(150):c())};var d=a.fn.alert;a.fn.alert=function(b){return this.each(function(){var d=a(this),e=d.data("bs.alert");e||d.data("bs.alert",e=new c(this)),"string"==typeof b&&e[b].call(d)})},a.fn.alert.Constructor=c,a.fn.alert.noConflict=function(){return a.fn.alert=d,this},a(document).on("click.bs.alert.data-api",b,c.prototype.close)}(window.jQuery),+function(a){"use strict";var b=function(c,d){this.$element=a(c),this.options=a.extend({},b.DEFAULTS,d)};b.DEFAULTS={loadingText:"loading..."},b.prototype.setState=function(a){var b="disabled",c=this.$element,d=c.is("input")?"val":"html",e=c.data();a+="Text",e.resetText||c.data("resetText",c[d]()),c[d](e[a]||this.options[a]),setTimeout(function(){"loadingText"==a?c.addClass(b).attr(b,b):c.removeClass(b).removeAttr(b)},0)},b.prototype.toggle=function(){var a=this.$element.closest('[data-toggle="buttons"]');if(a.length){var b=this.$element.find("input").prop("checked",!this.$element.hasClass("active")).trigger("change");"radio"===b.prop("type")&&a.find(".active").removeClass("active")}this.$element.toggleClass("active")};var c=a.fn.button;a.fn.button=function(c){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof c&&c;e||d.data("bs.button",e=new b(this,f)),"toggle"==c?e.toggle():c&&e.setState(c)})},a.fn.button.Constructor=b,a.fn.button.noConflict=function(){return a.fn.button=c,this},a(document).on("click.bs.button.data-api","[data-toggle^=button]",function(b){var c=a(b.target);c.hasClass("btn")||(c=c.closest(".btn")),c.button("toggle"),b.preventDefault()})}(window.jQuery),+function(a){"use strict";var b=function(b,c){this.$element=a(b),this.$indicators=this.$element.find(".carousel-indicators"),this.options=c,this.paused=this.sliding=this.interval=this.$active=this.$items=null,"hover"==this.options.pause&&this.$element.on("mouseenter",a.proxy(this.pause,this)).on("mouseleave",a.proxy(this.cycle,this))};b.DEFAULTS={interval:5e3,pause:"hover",wrap:!0},b.prototype.cycle=function(b){return b||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(a.proxy(this.next,this),this.options.interval)),this},b.prototype.getActiveIndex=function(){return this.$active=this.$element.find(".item.active"),this.$items=this.$active.parent().children(),this.$items.index(this.$active)},b.prototype.to=function(b){var c=this,d=this.getActiveIndex();return b>this.$items.length-1||0>b?void 0:this.sliding?this.$element.one("slid",function(){c.to(b)}):d==b?this.pause().cycle():this.slide(b>d?"next":"prev",a(this.$items[b]))},b.prototype.pause=function(b){return b||(this.paused=!0),this.$element.find(".next, .prev").length&&a.support.transition.end&&(this.$element.trigger(a.support.transition.end),this.cycle(!0)),this.interval=clearInterval(this.interval),this},b.prototype.next=function(){return this.sliding?void 0:this.slide("next")},b.prototype.prev=function(){return this.sliding?void 0:this.slide("prev")},b.prototype.slide=function(b,c){var d=this.$element.find(".item.active"),e=c||d[b](),f=this.interval,g="next"==b?"left":"right",h="next"==b?"first":"last",i=this;if(!e.length){if(!this.options.wrap)return;e=this.$element.find(".item")[h]()}this.sliding=!0,f&&this.pause();var j=a.Event("slide.bs.carousel",{relatedTarget:e[0],direction:g});if(!e.hasClass("active")){if(this.$indicators.length&&(this.$indicators.find(".active").removeClass("active"),this.$element.one("slid",function(){var b=a(i.$indicators.children()[i.getActiveIndex()]);b&&b.addClass("active")})),a.support.transition&&this.$element.hasClass("slide")){if(this.$element.trigger(j),j.isDefaultPrevented())return;e.addClass(b),e[0].offsetWidth,d.addClass(g),e.addClass(g),d.one(a.support.transition.end,function(){e.removeClass([b,g].join(" ")).addClass("active"),d.removeClass(["active",g].join(" ")),i.sliding=!1,setTimeout(function(){i.$element.trigger("slid")},0)}).emulateTransitionEnd(600)}else{if(this.$element.trigger(j),j.isDefaultPrevented())return;d.removeClass("active"),e.addClass("active"),this.sliding=!1,this.$element.trigger("slid")}return f&&this.cycle(),this}};var c=a.fn.carousel;a.fn.carousel=function(c){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},b.DEFAULTS,d.data(),"object"==typeof c&&c),g="string"==typeof c?c:f.slide;e||d.data("bs.carousel",e=new b(this,f)),"number"==typeof c?e.to(c):g?e[g]():f.interval&&e.pause().cycle()})},a.fn.carousel.Constructor=b,a.fn.carousel.noConflict=function(){return a.fn.carousel=c,this},a(document).on("click.bs.carousel.data-api","[data-slide], [data-slide-to]",function(b){var c,d=a(this),e=a(d.attr("data-target")||(c=d.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,"")),f=a.extend({},e.data(),d.data()),g=d.attr("data-slide-to");g&&(f.interval=!1),e.carousel(f),(g=d.attr("data-slide-to"))&&e.data("bs.carousel").to(g),b.preventDefault()}),a(window).on("load",function(){a('[data-ride="carousel"]').each(function(){var b=a(this);b.carousel(b.data())})})}(window.jQuery),+function(a){"use strict";var b=function(c,d){this.$element=a(c),this.options=a.extend({},b.DEFAULTS,d),this.transitioning=null,this.options.parent&&(this.$parent=a(this.options.parent)),this.options.toggle&&this.toggle()};b.DEFAULTS={toggle:!0},b.prototype.dimension=function(){var a=this.$element.hasClass("width");return a?"width":"height"},b.prototype.show=function(){if(!this.transitioning&&!this.$element.hasClass("in")){var b=a.Event("show.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.$parent&&this.$parent.find("> .panel > .in");if(c&&c.length){var d=c.data("bs.collapse");if(d&&d.transitioning)return;c.collapse("hide"),d||c.data("bs.collapse",null)}var e=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[e](0),this.transitioning=1;var f=function(){this.$element.removeClass("collapsing").addClass("in")[e]("auto"),this.transitioning=0,this.$element.trigger("shown.bs.collapse")};if(!a.support.transition)return f.call(this);var g=a.camelCase(["scroll",e].join("-"));this.$element.one(a.support.transition.end,a.proxy(f,this)).emulateTransitionEnd(350)[e](this.$element[0][g])}}},b.prototype.hide=function(){if(!this.transitioning&&this.$element.hasClass("in")){var b=a.Event("hide.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.dimension();this.$element[c](this.$element[c]())[0].offsetHeight,this.$element.addClass("collapsing").removeClass("collapse").removeClass("in"),this.transitioning=1;var d=function(){this.transitioning=0,this.$element.trigger("hidden.bs.collapse").removeClass("collapsing").addClass("collapse")};return a.support.transition?(this.$element[c](0).one(a.support.transition.end,a.proxy(d,this)).emulateTransitionEnd(350),void 0):d.call(this)}}},b.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()};var c=a.fn.collapse;a.fn.collapse=function(c){return this.each(function(){var d=a(this),e=d.data("bs.collapse"),f=a.extend({},b.DEFAULTS,d.data(),"object"==typeof c&&c);e||d.data("bs.collapse",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.collapse.Constructor=b,a.fn.collapse.noConflict=function(){return a.fn.collapse=c,this},a(document).on("click.bs.collapse.data-api","[data-toggle=collapse]",function(b){var c,d=a(this),e=d.attr("data-target")||b.preventDefault()||(c=d.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,""),f=a(e),g=f.data("bs.collapse"),h=g?"toggle":d.data(),i=d.attr("data-parent"),j=i&&a(i);g&&g.transitioning||(j&&j.find('[data-toggle=collapse][data-parent="'+i+'"]').not(d).addClass("collapsed"),d[f.hasClass("in")?"addClass":"removeClass"]("collapsed")),f.collapse(h)})}(window.jQuery),+function(a){"use strict";function b(){a(d).remove(),a(e).each(function(b){var d=c(a(this));d.hasClass("open")&&(d.trigger(b=a.Event("hide.bs.dropdown")),b.isDefaultPrevented()||d.removeClass("open").trigger("hidden.bs.dropdown"))})}function c(b){var c=b.attr("data-target");c||(c=b.attr("href"),c=c&&/#/.test(c)&&c.replace(/.*(?=#[^\s]*$)/,""));var d=c&&a(c);return d&&d.length?d:b.parent()}var d=".dropdown-backdrop",e="[data-toggle=dropdown]",f=function(b){a(b).on("click.bs.dropdown",this.toggle)};f.prototype.toggle=function(d){var e=a(this);if(!e.is(".disabled, :disabled")){var f=c(e),g=f.hasClass("open");if(b(),!g){if("ontouchstart"in document.documentElement&&!f.closest(".navbar-nav").length&&a(''}),b.prototype=a.extend({},a.fn.tooltip.Constructor.prototype),b.prototype.constructor=b,b.prototype.getDefaults=function(){return b.DEFAULTS},b.prototype.setContent=function(){var a=this.tip(),b=this.getTitle(),c=this.getContent();a.find(".popover-title")[this.options.html?"html":"text"](b),a.find(".popover-content")[this.options.html?"html":"text"](c),a.removeClass("fade top bottom left right in"),a.find(".popover-title").html()||a.find(".popover-title").hide()},b.prototype.hasContent=function(){return this.getTitle()||this.getContent()},b.prototype.getContent=function(){var a=this.$element,b=this.options;return a.attr("data-content")||("function"==typeof b.content?b.content.call(a[0]):b.content)},b.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")},b.prototype.tip=function(){return this.$tip||(this.$tip=a(this.options.template)),this.$tip};var c=a.fn.popover;a.fn.popover=function(c){return this.each(function(){var d=a(this),e=d.data("bs.popover"),f="object"==typeof c&&c;e||d.data("bs.popover",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.popover.Constructor=b,a.fn.popover.noConflict=function(){return a.fn.popover=c,this}}(window.jQuery),+function(a){"use strict";function b(c,d){var e,f=a.proxy(this.process,this);this.$element=a(c).is("body")?a(window):a(c),this.$body=a("body"),this.$scrollElement=this.$element.on("scroll.bs.scroll-spy.data-api",f),this.options=a.extend({},b.DEFAULTS,d),this.selector=(this.options.target||(e=a(c).attr("href"))&&e.replace(/.*(?=#[^\s]+$)/,"")||"")+" .nav li > a",this.offsets=a([]),this.targets=a([]),this.activeTarget=null,this.refresh(),this.process()}b.DEFAULTS={offset:10},b.prototype.refresh=function(){var b=this.$element[0]==window?"offset":"position";this.offsets=a([]),this.targets=a([]);var c=this;this.$body.find(this.selector).map(function(){var d=a(this),e=d.data("target")||d.attr("href"),f=/^#\w/.test(e)&&a(e);return f&&f.length&&[[f[b]().top+(!a.isWindow(c.$scrollElement.get(0))&&c.$scrollElement.scrollTop()),e]]||null}).sort(function(a,b){return a[0]-b[0]}).each(function(){c.offsets.push(this[0]),c.targets.push(this[1])})},b.prototype.process=function(){var a,b=this.$scrollElement.scrollTop()+this.options.offset,c=this.$scrollElement[0].scrollHeight||this.$body[0].scrollHeight,d=c-this.$scrollElement.height(),e=this.offsets,f=this.targets,g=this.activeTarget;if(b>=d)return g!=(a=f.last()[0])&&this.activate(a);for(a=e.length;a--;)g!=f[a]&&b>=e[a]&&(!e[a+1]||b<=e[a+1])&&this.activate(f[a])},b.prototype.activate=function(b){this.activeTarget=b,a(this.selector).parents(".active").removeClass("active");var c=this.selector+'[data-target="'+b+'"],'+this.selector+'[href="'+b+'"]',d=a(c).parents("li").addClass("active");d.parent(".dropdown-menu").length&&(d=d.closest("li.dropdown").addClass("active")),d.trigger("activate")};var c=a.fn.scrollspy;a.fn.scrollspy=function(c){return this.each(function(){var d=a(this),e=d.data("bs.scrollspy"),f="object"==typeof c&&c;e||d.data("bs.scrollspy",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.scrollspy.Constructor=b,a.fn.scrollspy.noConflict=function(){return a.fn.scrollspy=c,this},a(window).on("load",function(){a('[data-spy="scroll"]').each(function(){var b=a(this);b.scrollspy(b.data())})})}(window.jQuery),+function(a){"use strict";var b=function(b){this.element=a(b)};b.prototype.show=function(){var b=this.element,c=b.closest("ul:not(.dropdown-menu)"),d=b.attr("data-target");if(d||(d=b.attr("href"),d=d&&d.replace(/.*(?=#[^\s]*$)/,"")),!b.parent("li").hasClass("active")){var e=c.find(".active:last a")[0],f=a.Event("show.bs.tab",{relatedTarget:e});if(b.trigger(f),!f.isDefaultPrevented()){var g=a(d);this.activate(b.parent("li"),c),this.activate(g,g.parent(),function(){b.trigger({type:"shown.bs.tab",relatedTarget:e})})}}},b.prototype.activate=function(b,c,d){function e(){f.removeClass("active").find("> .dropdown-menu > .active").removeClass("active"),b.addClass("active"),g?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu")&&b.closest("li.dropdown").addClass("active"),d&&d()}var f=c.find("> .active"),g=d&&a.support.transition&&f.hasClass("fade");g?f.one(a.support.transition.end,e).emulateTransitionEnd(150):e(),f.removeClass("in")};var c=a.fn.tab;a.fn.tab=function(c){return this.each(function(){var d=a(this),e=d.data("bs.tab");e||d.data("bs.tab",e=new b(this)),"string"==typeof c&&e[c]()})},a.fn.tab.Constructor=b,a.fn.tab.noConflict=function(){return a.fn.tab=c,this},a(document).on("click.bs.tab.data-api",'[data-toggle="tab"], [data-toggle="pill"]',function(b){b.preventDefault(),a(this).tab("show")})}(window.jQuery),+function(a){"use strict";var b=function(c,d){this.options=a.extend({},b.DEFAULTS,d),this.$window=a(window).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(c),this.affixed=this.unpin=null,this.checkPosition()};b.RESET="affix affix-top affix-bottom",b.DEFAULTS={offset:0},b.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},b.prototype.checkPosition=function(){if(this.$element.is(":visible")){var c=a(document).height(),d=this.$window.scrollTop(),e=this.$element.offset(),f=this.options.offset,g=f.top,h=f.bottom;"object"!=typeof f&&(h=g=f),"function"==typeof g&&(g=f.top()),"function"==typeof h&&(h=f.bottom());var i=null!=this.unpin&&d+this.unpin<=e.top?!1:null!=h&&e.top+this.$element.height()>=c-h?"bottom":null!=g&&g>=d?"top":!1;this.affixed!==i&&(this.unpin&&this.$element.css("top",""),this.affixed=i,this.unpin="bottom"==i?e.top-d:null,this.$element.removeClass(b.RESET).addClass("affix"+(i?"-"+i:"")),"bottom"==i&&this.$element.offset({top:document.body.offsetHeight-h-this.$element.height()}))}};var c=a.fn.affix;a.fn.affix=function(c){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof c&&c;e||d.data("bs.affix",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.affix.Constructor=b,a.fn.affix.noConflict=function(){return a.fn.affix=c,this},a(window).on("load",function(){a('[data-spy="affix"]').each(function(){var b=a(this),c=b.data();c.offset=c.offset||{},c.offsetBottom&&(c.offset.bottom=c.offsetBottom),c.offsetTop&&(c.offset.top=c.offsetTop),b.affix(c)})})}(window.jQuery); -------------------------------------------------------------------------------- /tokenization/tokenizer_flask/Tokenizer_Demo/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Token Count
21 |

{{length}}

22 |
23 |
24 |
25 |
26 |
27 |
28 |
Character Count
29 |

{{ character_count }}

30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | 205 | 206 | -------------------------------------------------------------------------------- /tokenization/tokenizer_flask/__init__.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, request 2 | import tiktoken 3 | import json 4 | 5 | app = Flask(__name__) 6 | 7 | @app.route("/") 8 | def index(): 9 | return render_template("index.html") 10 | 11 | @app.route("/get") 12 | def tokenizer_response(): 13 | 14 | 15 | tokenizer_value = request.args.get('tokenizer') # Get the tokenizer value from the request 16 | tokenizer = tiktoken.get_encoding(tokenizer_value) # Use the tokenizer value when getting the tokenizer 17 | count = 0 18 | token_list = [] 19 | user_input= request.args.get('msg') 20 | encode = tokenizer.encode(user_input) 21 | decode = tokenizer.decode_tokens_bytes(encode) 22 | 23 | for token in decode: 24 | try: 25 | token_list.append(token.decode()) 26 | except UnicodeDecodeError: 27 | token_list.append("�") # Replace the token with the Unicode replacement character 28 | 29 | character_count = sum(len(i) for i in token_list) 30 | length = len(encode) 31 | 32 | # Convert token_list items to strings surrounded by single quotes 33 | quoted_token_list = ["'{}'".format(token) for token in token_list] 34 | 35 | # Create a dictionary containing the desired values 36 | response_data = { 37 | "token_list": quoted_token_list, 38 | "encode": encode, 39 | "length": length, 40 | "character_count": character_count 41 | } 42 | 43 | # Convert the dictionary to a JSON string using json.dumps() 44 | return json.dumps(response_data) 45 | 46 | 47 | 48 | if __name__ == "__main__": 49 | app.run() -------------------------------------------------------------------------------- /tokenization/tokenizer_flask/obj/Any CPU/Debug/Tokenizer_Demo.pyproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpsConfig/OpenAI_Lab/1bcfe66ad79277e1d83ae1288db9b59b525c9053/tokenization/tokenizer_flask/obj/Any CPU/Debug/Tokenizer_Demo.pyproj.FileListAbsolute.txt -------------------------------------------------------------------------------- /tokenization/tokenizer_flask/obj/Any CPU/Release/_WPPLastBuildInfo.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpsConfig/OpenAI_Lab/1bcfe66ad79277e1d83ae1288db9b59b525c9053/tokenization/tokenizer_flask/obj/Any CPU/Release/_WPPLastBuildInfo.txt -------------------------------------------------------------------------------- /tokenization/tokenizer_flask/runserver.py: -------------------------------------------------------------------------------- 1 | from os import environ 2 | from Tokenizer_Demo import app 3 | 4 | if __name__ == '__main__': 5 | HOST = environ.get('SERVER_HOST', 'localhost') 6 | try: 7 | PORT = int(environ.get('SERVER_PORT', '5555')) 8 | except ValueError: 9 | PORT = 5555 10 | app.run(HOST, PORT) 11 | -------------------------------------------------------------------------------- /tokenization/tokenizer_flask/static/content/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #454654; 3 | } 4 | 5 | .userText { 6 | color: white; 7 | font-family: 'Segoe UI'; 8 | font-size: 14px; 9 | text-align: left; 10 | line-height: 30px; 11 | } 12 | 13 | .form-check-label { 14 | color: white; 15 | font-family: 'Segoe UI'; 16 | font-size: 12px; 17 | } 18 | 19 | .highlight { 20 | background-color: yellow; 21 | } 22 | 23 | .card-body { 24 | color: white; 25 | font-family: 'Segoe UI'; 26 | font-size: 30px; 27 | text-align: left; 28 | line-height: 30px; 29 | border: thin; 30 | border-color: aqua 31 | } 32 | 33 | .userText span { 34 | background-color: #27B5EA66; 35 | } 36 | 37 | .tokenizedResults { 38 | color: white; 39 | font-family: 'Segoe UI'; 40 | font-size: 14px; 41 | text-align: left; 42 | line-height: 30px; 43 | } 44 | 45 | 46 | .tokenizedResults span { 47 | padding: 0; 48 | border-radius: 2px; 49 | word-wrap: break-word; 50 | } 51 | 52 | .bg-color-0 { 53 | background-color: #6B40D84D; 54 | display: inline; 55 | } 56 | 57 | .bg-color-1 { 58 | background-color: #68DE7A66; 59 | display: inline; 60 | } 61 | 62 | .bg-color-2 { 63 | background-color: #F4AC3666; 64 | display: inline; 65 | } 66 | 67 | .bg-color-3 { 68 | background-color: #27B5EA66; 69 | display: inline; 70 | } 71 | 72 | .bg-color-4 { 73 | background-color: #Ef414666; 74 | display: inline; 75 | } 76 | 77 | .btn-custom { 78 | width: 100px; 79 | margin-left: 0px; 80 | margin-right: 2px; 81 | } 82 | 83 | 84 | .btn-clear { 85 | background-color: #Ef414666; 86 | color: white; 87 | } 88 | 89 | .tokenizedResults span.bg-color-0, 90 | .tokenizedResults span.bg-color-1, 91 | .tokenizedResults span.bg-color-2, 92 | .tokenizedResults span.bg-color-3, 93 | .tokenizedResults span.bg-color-4 { 94 | padding: 1px 5px; 95 | margin: 0; 96 | } 97 | 98 | .btn-disabled { 99 | background-color: #ccc; 100 | border-color: #ccc; 101 | } -------------------------------------------------------------------------------- /tokenization/tokenizer_flask/static/scripts/bootstrap.min.js: -------------------------------------------------------------------------------- 1 | /* NUGET: BEGIN LICENSE TEXT 2 | * 3 | * Microsoft grants you the right to use these script files for the sole 4 | * purpose of either: (i) interacting through your browser with the Microsoft 5 | * website or online service, subject to the applicable licensing or use 6 | * terms; or (ii) using the files as included with a Microsoft product subject 7 | * to that product's license terms. Microsoft reserves all other rights to the 8 | * files not expressly granted by Microsoft, whether by implication, estoppel 9 | * or otherwise. Insofar as a script file is dual licensed under GPL, 10 | * Microsoft neither took the code under GPL nor distributes it thereunder but 11 | * under the terms set out in this paragraph. All notices and licenses 12 | * below are for informational purposes only. 13 | * 14 | * NUGET: END LICENSE TEXT */ 15 | 16 | /** 17 | * bootstrap.js v3.0.0 by @fat and @mdo 18 | * Copyright 2013 Twitter Inc. 19 | * http://www.apache.org/licenses/LICENSE-2.0 20 | */ 21 | if(!jQuery)throw new Error("Bootstrap requires jQuery");+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]}}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one(a.support.transition.end,function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b()})}(window.jQuery),+function(a){"use strict";var b='[data-dismiss="alert"]',c=function(c){a(c).on("click",b,this.close)};c.prototype.close=function(b){function c(){f.trigger("closed.bs.alert").remove()}var d=a(this),e=d.attr("data-target");e||(e=d.attr("href"),e=e&&e.replace(/.*(?=#[^\s]*$)/,""));var f=a(e);b&&b.preventDefault(),f.length||(f=d.hasClass("alert")?d:d.parent()),f.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(f.removeClass("in"),a.support.transition&&f.hasClass("fade")?f.one(a.support.transition.end,c).emulateTransitionEnd(150):c())};var d=a.fn.alert;a.fn.alert=function(b){return this.each(function(){var d=a(this),e=d.data("bs.alert");e||d.data("bs.alert",e=new c(this)),"string"==typeof b&&e[b].call(d)})},a.fn.alert.Constructor=c,a.fn.alert.noConflict=function(){return a.fn.alert=d,this},a(document).on("click.bs.alert.data-api",b,c.prototype.close)}(window.jQuery),+function(a){"use strict";var b=function(c,d){this.$element=a(c),this.options=a.extend({},b.DEFAULTS,d)};b.DEFAULTS={loadingText:"loading..."},b.prototype.setState=function(a){var b="disabled",c=this.$element,d=c.is("input")?"val":"html",e=c.data();a+="Text",e.resetText||c.data("resetText",c[d]()),c[d](e[a]||this.options[a]),setTimeout(function(){"loadingText"==a?c.addClass(b).attr(b,b):c.removeClass(b).removeAttr(b)},0)},b.prototype.toggle=function(){var a=this.$element.closest('[data-toggle="buttons"]');if(a.length){var b=this.$element.find("input").prop("checked",!this.$element.hasClass("active")).trigger("change");"radio"===b.prop("type")&&a.find(".active").removeClass("active")}this.$element.toggleClass("active")};var c=a.fn.button;a.fn.button=function(c){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof c&&c;e||d.data("bs.button",e=new b(this,f)),"toggle"==c?e.toggle():c&&e.setState(c)})},a.fn.button.Constructor=b,a.fn.button.noConflict=function(){return a.fn.button=c,this},a(document).on("click.bs.button.data-api","[data-toggle^=button]",function(b){var c=a(b.target);c.hasClass("btn")||(c=c.closest(".btn")),c.button("toggle"),b.preventDefault()})}(window.jQuery),+function(a){"use strict";var b=function(b,c){this.$element=a(b),this.$indicators=this.$element.find(".carousel-indicators"),this.options=c,this.paused=this.sliding=this.interval=this.$active=this.$items=null,"hover"==this.options.pause&&this.$element.on("mouseenter",a.proxy(this.pause,this)).on("mouseleave",a.proxy(this.cycle,this))};b.DEFAULTS={interval:5e3,pause:"hover",wrap:!0},b.prototype.cycle=function(b){return b||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(a.proxy(this.next,this),this.options.interval)),this},b.prototype.getActiveIndex=function(){return this.$active=this.$element.find(".item.active"),this.$items=this.$active.parent().children(),this.$items.index(this.$active)},b.prototype.to=function(b){var c=this,d=this.getActiveIndex();return b>this.$items.length-1||0>b?void 0:this.sliding?this.$element.one("slid",function(){c.to(b)}):d==b?this.pause().cycle():this.slide(b>d?"next":"prev",a(this.$items[b]))},b.prototype.pause=function(b){return b||(this.paused=!0),this.$element.find(".next, .prev").length&&a.support.transition.end&&(this.$element.trigger(a.support.transition.end),this.cycle(!0)),this.interval=clearInterval(this.interval),this},b.prototype.next=function(){return this.sliding?void 0:this.slide("next")},b.prototype.prev=function(){return this.sliding?void 0:this.slide("prev")},b.prototype.slide=function(b,c){var d=this.$element.find(".item.active"),e=c||d[b](),f=this.interval,g="next"==b?"left":"right",h="next"==b?"first":"last",i=this;if(!e.length){if(!this.options.wrap)return;e=this.$element.find(".item")[h]()}this.sliding=!0,f&&this.pause();var j=a.Event("slide.bs.carousel",{relatedTarget:e[0],direction:g});if(!e.hasClass("active")){if(this.$indicators.length&&(this.$indicators.find(".active").removeClass("active"),this.$element.one("slid",function(){var b=a(i.$indicators.children()[i.getActiveIndex()]);b&&b.addClass("active")})),a.support.transition&&this.$element.hasClass("slide")){if(this.$element.trigger(j),j.isDefaultPrevented())return;e.addClass(b),e[0].offsetWidth,d.addClass(g),e.addClass(g),d.one(a.support.transition.end,function(){e.removeClass([b,g].join(" ")).addClass("active"),d.removeClass(["active",g].join(" ")),i.sliding=!1,setTimeout(function(){i.$element.trigger("slid")},0)}).emulateTransitionEnd(600)}else{if(this.$element.trigger(j),j.isDefaultPrevented())return;d.removeClass("active"),e.addClass("active"),this.sliding=!1,this.$element.trigger("slid")}return f&&this.cycle(),this}};var c=a.fn.carousel;a.fn.carousel=function(c){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},b.DEFAULTS,d.data(),"object"==typeof c&&c),g="string"==typeof c?c:f.slide;e||d.data("bs.carousel",e=new b(this,f)),"number"==typeof c?e.to(c):g?e[g]():f.interval&&e.pause().cycle()})},a.fn.carousel.Constructor=b,a.fn.carousel.noConflict=function(){return a.fn.carousel=c,this},a(document).on("click.bs.carousel.data-api","[data-slide], [data-slide-to]",function(b){var c,d=a(this),e=a(d.attr("data-target")||(c=d.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,"")),f=a.extend({},e.data(),d.data()),g=d.attr("data-slide-to");g&&(f.interval=!1),e.carousel(f),(g=d.attr("data-slide-to"))&&e.data("bs.carousel").to(g),b.preventDefault()}),a(window).on("load",function(){a('[data-ride="carousel"]').each(function(){var b=a(this);b.carousel(b.data())})})}(window.jQuery),+function(a){"use strict";var b=function(c,d){this.$element=a(c),this.options=a.extend({},b.DEFAULTS,d),this.transitioning=null,this.options.parent&&(this.$parent=a(this.options.parent)),this.options.toggle&&this.toggle()};b.DEFAULTS={toggle:!0},b.prototype.dimension=function(){var a=this.$element.hasClass("width");return a?"width":"height"},b.prototype.show=function(){if(!this.transitioning&&!this.$element.hasClass("in")){var b=a.Event("show.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.$parent&&this.$parent.find("> .panel > .in");if(c&&c.length){var d=c.data("bs.collapse");if(d&&d.transitioning)return;c.collapse("hide"),d||c.data("bs.collapse",null)}var e=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[e](0),this.transitioning=1;var f=function(){this.$element.removeClass("collapsing").addClass("in")[e]("auto"),this.transitioning=0,this.$element.trigger("shown.bs.collapse")};if(!a.support.transition)return f.call(this);var g=a.camelCase(["scroll",e].join("-"));this.$element.one(a.support.transition.end,a.proxy(f,this)).emulateTransitionEnd(350)[e](this.$element[0][g])}}},b.prototype.hide=function(){if(!this.transitioning&&this.$element.hasClass("in")){var b=a.Event("hide.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.dimension();this.$element[c](this.$element[c]())[0].offsetHeight,this.$element.addClass("collapsing").removeClass("collapse").removeClass("in"),this.transitioning=1;var d=function(){this.transitioning=0,this.$element.trigger("hidden.bs.collapse").removeClass("collapsing").addClass("collapse")};return a.support.transition?(this.$element[c](0).one(a.support.transition.end,a.proxy(d,this)).emulateTransitionEnd(350),void 0):d.call(this)}}},b.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()};var c=a.fn.collapse;a.fn.collapse=function(c){return this.each(function(){var d=a(this),e=d.data("bs.collapse"),f=a.extend({},b.DEFAULTS,d.data(),"object"==typeof c&&c);e||d.data("bs.collapse",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.collapse.Constructor=b,a.fn.collapse.noConflict=function(){return a.fn.collapse=c,this},a(document).on("click.bs.collapse.data-api","[data-toggle=collapse]",function(b){var c,d=a(this),e=d.attr("data-target")||b.preventDefault()||(c=d.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,""),f=a(e),g=f.data("bs.collapse"),h=g?"toggle":d.data(),i=d.attr("data-parent"),j=i&&a(i);g&&g.transitioning||(j&&j.find('[data-toggle=collapse][data-parent="'+i+'"]').not(d).addClass("collapsed"),d[f.hasClass("in")?"addClass":"removeClass"]("collapsed")),f.collapse(h)})}(window.jQuery),+function(a){"use strict";function b(){a(d).remove(),a(e).each(function(b){var d=c(a(this));d.hasClass("open")&&(d.trigger(b=a.Event("hide.bs.dropdown")),b.isDefaultPrevented()||d.removeClass("open").trigger("hidden.bs.dropdown"))})}function c(b){var c=b.attr("data-target");c||(c=b.attr("href"),c=c&&/#/.test(c)&&c.replace(/.*(?=#[^\s]*$)/,""));var d=c&&a(c);return d&&d.length?d:b.parent()}var d=".dropdown-backdrop",e="[data-toggle=dropdown]",f=function(b){a(b).on("click.bs.dropdown",this.toggle)};f.prototype.toggle=function(d){var e=a(this);if(!e.is(".disabled, :disabled")){var f=c(e),g=f.hasClass("open");if(b(),!g){if("ontouchstart"in document.documentElement&&!f.closest(".navbar-nav").length&&a(''}),b.prototype=a.extend({},a.fn.tooltip.Constructor.prototype),b.prototype.constructor=b,b.prototype.getDefaults=function(){return b.DEFAULTS},b.prototype.setContent=function(){var a=this.tip(),b=this.getTitle(),c=this.getContent();a.find(".popover-title")[this.options.html?"html":"text"](b),a.find(".popover-content")[this.options.html?"html":"text"](c),a.removeClass("fade top bottom left right in"),a.find(".popover-title").html()||a.find(".popover-title").hide()},b.prototype.hasContent=function(){return this.getTitle()||this.getContent()},b.prototype.getContent=function(){var a=this.$element,b=this.options;return a.attr("data-content")||("function"==typeof b.content?b.content.call(a[0]):b.content)},b.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")},b.prototype.tip=function(){return this.$tip||(this.$tip=a(this.options.template)),this.$tip};var c=a.fn.popover;a.fn.popover=function(c){return this.each(function(){var d=a(this),e=d.data("bs.popover"),f="object"==typeof c&&c;e||d.data("bs.popover",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.popover.Constructor=b,a.fn.popover.noConflict=function(){return a.fn.popover=c,this}}(window.jQuery),+function(a){"use strict";function b(c,d){var e,f=a.proxy(this.process,this);this.$element=a(c).is("body")?a(window):a(c),this.$body=a("body"),this.$scrollElement=this.$element.on("scroll.bs.scroll-spy.data-api",f),this.options=a.extend({},b.DEFAULTS,d),this.selector=(this.options.target||(e=a(c).attr("href"))&&e.replace(/.*(?=#[^\s]+$)/,"")||"")+" .nav li > a",this.offsets=a([]),this.targets=a([]),this.activeTarget=null,this.refresh(),this.process()}b.DEFAULTS={offset:10},b.prototype.refresh=function(){var b=this.$element[0]==window?"offset":"position";this.offsets=a([]),this.targets=a([]);var c=this;this.$body.find(this.selector).map(function(){var d=a(this),e=d.data("target")||d.attr("href"),f=/^#\w/.test(e)&&a(e);return f&&f.length&&[[f[b]().top+(!a.isWindow(c.$scrollElement.get(0))&&c.$scrollElement.scrollTop()),e]]||null}).sort(function(a,b){return a[0]-b[0]}).each(function(){c.offsets.push(this[0]),c.targets.push(this[1])})},b.prototype.process=function(){var a,b=this.$scrollElement.scrollTop()+this.options.offset,c=this.$scrollElement[0].scrollHeight||this.$body[0].scrollHeight,d=c-this.$scrollElement.height(),e=this.offsets,f=this.targets,g=this.activeTarget;if(b>=d)return g!=(a=f.last()[0])&&this.activate(a);for(a=e.length;a--;)g!=f[a]&&b>=e[a]&&(!e[a+1]||b<=e[a+1])&&this.activate(f[a])},b.prototype.activate=function(b){this.activeTarget=b,a(this.selector).parents(".active").removeClass("active");var c=this.selector+'[data-target="'+b+'"],'+this.selector+'[href="'+b+'"]',d=a(c).parents("li").addClass("active");d.parent(".dropdown-menu").length&&(d=d.closest("li.dropdown").addClass("active")),d.trigger("activate")};var c=a.fn.scrollspy;a.fn.scrollspy=function(c){return this.each(function(){var d=a(this),e=d.data("bs.scrollspy"),f="object"==typeof c&&c;e||d.data("bs.scrollspy",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.scrollspy.Constructor=b,a.fn.scrollspy.noConflict=function(){return a.fn.scrollspy=c,this},a(window).on("load",function(){a('[data-spy="scroll"]').each(function(){var b=a(this);b.scrollspy(b.data())})})}(window.jQuery),+function(a){"use strict";var b=function(b){this.element=a(b)};b.prototype.show=function(){var b=this.element,c=b.closest("ul:not(.dropdown-menu)"),d=b.attr("data-target");if(d||(d=b.attr("href"),d=d&&d.replace(/.*(?=#[^\s]*$)/,"")),!b.parent("li").hasClass("active")){var e=c.find(".active:last a")[0],f=a.Event("show.bs.tab",{relatedTarget:e});if(b.trigger(f),!f.isDefaultPrevented()){var g=a(d);this.activate(b.parent("li"),c),this.activate(g,g.parent(),function(){b.trigger({type:"shown.bs.tab",relatedTarget:e})})}}},b.prototype.activate=function(b,c,d){function e(){f.removeClass("active").find("> .dropdown-menu > .active").removeClass("active"),b.addClass("active"),g?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu")&&b.closest("li.dropdown").addClass("active"),d&&d()}var f=c.find("> .active"),g=d&&a.support.transition&&f.hasClass("fade");g?f.one(a.support.transition.end,e).emulateTransitionEnd(150):e(),f.removeClass("in")};var c=a.fn.tab;a.fn.tab=function(c){return this.each(function(){var d=a(this),e=d.data("bs.tab");e||d.data("bs.tab",e=new b(this)),"string"==typeof c&&e[c]()})},a.fn.tab.Constructor=b,a.fn.tab.noConflict=function(){return a.fn.tab=c,this},a(document).on("click.bs.tab.data-api",'[data-toggle="tab"], [data-toggle="pill"]',function(b){b.preventDefault(),a(this).tab("show")})}(window.jQuery),+function(a){"use strict";var b=function(c,d){this.options=a.extend({},b.DEFAULTS,d),this.$window=a(window).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(c),this.affixed=this.unpin=null,this.checkPosition()};b.RESET="affix affix-top affix-bottom",b.DEFAULTS={offset:0},b.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},b.prototype.checkPosition=function(){if(this.$element.is(":visible")){var c=a(document).height(),d=this.$window.scrollTop(),e=this.$element.offset(),f=this.options.offset,g=f.top,h=f.bottom;"object"!=typeof f&&(h=g=f),"function"==typeof g&&(g=f.top()),"function"==typeof h&&(h=f.bottom());var i=null!=this.unpin&&d+this.unpin<=e.top?!1:null!=h&&e.top+this.$element.height()>=c-h?"bottom":null!=g&&g>=d?"top":!1;this.affixed!==i&&(this.unpin&&this.$element.css("top",""),this.affixed=i,this.unpin="bottom"==i?e.top-d:null,this.$element.removeClass(b.RESET).addClass("affix"+(i?"-"+i:"")),"bottom"==i&&this.$element.offset({top:document.body.offsetHeight-h-this.$element.height()}))}};var c=a.fn.affix;a.fn.affix=function(c){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof c&&c;e||d.data("bs.affix",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.affix.Constructor=b,a.fn.affix.noConflict=function(){return a.fn.affix=c,this},a(window).on("load",function(){a('[data-spy="affix"]').each(function(){var b=a(this),c=b.data();c.offset=c.offset||{},c.offsetBottom&&(c.offset.bottom=c.offsetBottom),c.offsetTop&&(c.offset.top=c.offsetTop),b.affix(c)})})}(window.jQuery); -------------------------------------------------------------------------------- /tokenization/tokenizer_flask/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Token Count
21 |

{{length}}

22 |
23 |
24 |
25 |
26 |
27 |
28 |
Character Count
29 |

{{ character_count }}

30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | 46 |
47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 | 187 | 188 | --------------------------------------------------------------------------------