Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor pykoi into base, huggingface, rag, and rlhf #53

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions example/chatbot/chatbot_in_jupyter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,20 @@
"current_directory = os.getcwd()\n",
"sys.path.append(\".\")\n",
"sys.path.append(\"..\")\n",
"sys.path.append(\"../..\")\n",
"\n",
"import pykoi as pk"
"sys.path.append(\"../..\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6a907bb3",
"metadata": {},
"outputs": [],
"source": [
"from pykoi import Application\n",
"from pykoi.chat import ModelFactory\n",
"from pykoi.chat import QuestionAnswerDatabase\n",
"from pykoi.component import Chatbot"
]
},
{
Expand All @@ -31,7 +42,7 @@
"api_key = \"\"\n",
"\n",
"# Creating an OpenAI model\n",
"model = pk.ModelFactory.create_model(model_source=\"openai\", api_key=api_key)"
"model = ModelFactory.create_model(model_source=\"openai\", api_key=api_key)"
]
},
{
Expand All @@ -41,10 +52,10 @@
"metadata": {},
"outputs": [],
"source": [
"database = pk.QuestionAnswerDatabase(debug=True)\n",
"chatbot = pk.Chatbot(model=model, feedback=\"vote\")\n",
"database = QuestionAnswerDatabase(debug=True)\n",
"chatbot = Chatbot(model=model, feedback=\"vote\")\n",
"\n",
"app = pk.Application(debug=False, share=False)\n",
"app = Application(debug=False, share=False)\n",
"app.add_component(chatbot)"
]
},
Expand Down Expand Up @@ -76,7 +87,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.17"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
299 changes: 183 additions & 116 deletions example/chatbot/demo_launch_app_api.ipynb

Large diffs are not rendered by default.

226 changes: 36 additions & 190 deletions example/chatbot/demo_launch_app_gpu.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,39 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/home/ec2-user/SageMaker/pykoi\n"
]
}
],
"outputs": [],
"source": [
"%reload_ext autoreload\n",
"%autoreload 2\n",
"# %reload_ext autoreload\n",
"# %autoreload 2\n",
"\n",
"import os\n",
"import sys\n",
"# import os\n",
"# import sys\n",
"\n",
"# Add the root folder to the module search path\n",
"# Get the current directory\n",
"current_directory = os.getcwd()\n",
"# # Add the root folder to the module search path\n",
"# # Get the current directory\n",
"# current_directory = os.getcwd()\n",
"\n",
"# Move two levels up (go to the parent directory of the parent directory)\n",
"two_levels_up_directory = os.path.dirname(os.path.dirname(current_directory))\n",
"# # Move two levels up (go to the parent directory of the parent directory)\n",
"# two_levels_up_directory = os.path.dirname(os.path.dirname(current_directory))\n",
"\n",
"print(two_levels_up_directory)\n",
"# print(two_levels_up_directory)\n",
"\n",
"sys.path.append(two_levels_up_directory)"
"# sys.path.append(two_levels_up_directory)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/ec2-user/anaconda3/envs/0731a/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
}
],
"outputs": [],
"source": [
"## pip install ipykernel\n",
"import pykoi"
"from pykoi import Application\n",
"from pykoi.chat import ModelFactory\n",
"from pykoi.chat import QuestionAnswerDatabase\n",
"from pykoi.component import Chatbot, Dashboard"
]
},
{
Expand All @@ -62,42 +48,20 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"qa_database = pykoi.QuestionAnswerDatabase()"
"qa_database = QuestionAnswerDatabase()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[HuggingfaceModel] loading model...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Loading checkpoint shards: 100%|██████████| 2/2 [00:23<00:00, 11.75s/it]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[HuggingfaceModel] loading tokenizer...\n"
]
}
],
"outputs": [],
"source": [
"model = pykoi.ModelFactory.create_model(\n",
"model = ModelFactory.create_model(\n",
" model_source=\"huggingface\", \n",
" pretrained_model_name_or_path=\"tiiuae/falcon-7b\",\n",
" trust_remote_code=True, ## TODO: set as default\n",
Expand All @@ -107,11 +71,11 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"chatbot = pykoi.Chatbot(model=model, feedback=\"vote\")"
"chatbot = Chatbot(model=model, feedback=\"vote\")"
]
},
{
Expand All @@ -133,7 +97,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -150,7 +114,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -161,65 +125,11 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"t=2023-08-01T04:26:32+0000 lvl=warn msg=\"ngrok config file found at legacy location, move to XDG location\" xdg_path=/home/ec2-user/.config/ngrok/ngrok.yml legacy_path=/home/ec2-user/.ngrok2/ngrok.yml\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Public URL: NgrokTunnel: \"https://d7cd-34-209-105-222.ngrok-free.app\" -> \"http://localhost:34349\"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO: Started server process [21474]\n",
"INFO: Waiting for application startup.\n",
"INFO: Application startup complete.\n",
"INFO: Uvicorn running on http://127.0.0.1:34349 (Press CTRL+C to quit)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"INFO: 76.21.76.39:0 - \"GET / HTTP/1.1\" 200 OK\n",
"INFO: 76.21.76.39:0 - \"GET /assets/index-fc1a91e8.js HTTP/1.1\" 200 OK\n",
"INFO: 76.21.76.39:0 - \"GET /assets/index-f75c1c12.css HTTP/1.1\" 200 OK\n",
"INFO: 76.21.76.39:0 - \"GET /components HTTP/1.1\" 200 OK\n",
"INFO: 76.21.76.39:0 - \"GET /vite.svg HTTP/1.1\" 200 OK\n",
"INFO: 76.21.76.39:0 - \"GET /chat/qa_table/retrieve HTTP/1.1\" 404 Not Found\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO: Shutting down\n",
"INFO: Waiting for application shutdown.\n",
"INFO: Application shutdown complete.\n",
"INFO: Finished server process [21474]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Stopping server...\n"
]
}
],
"outputs": [],
"source": [
"app = pykoi.Application(debug=False, share=True)\n",
"app = Application(debug=False, share=True)\n",
"app.add_component(chatbot)\n",
"app.run()"
]
Expand All @@ -235,77 +145,20 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"qa_dashboard = pykoi.Dashboard(database=qa_database)"
"qa_dashboard = Dashboard(database=qa_database)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"t=2023-08-01T04:27:23+0000 lvl=warn msg=\"ngrok config file found at legacy location, move to XDG location\" xdg_path=/home/ec2-user/.config/ngrok/ngrok.yml legacy_path=/home/ec2-user/.ngrok2/ngrok.yml\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Public URL: NgrokTunnel: \"https://82f5-34-209-105-222.ngrok-free.app\" -> \"http://localhost:37933\"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO: Started server process [21474]\n",
"INFO: Waiting for application startup.\n",
"INFO: Application startup complete.\n",
"INFO: Uvicorn running on http://127.0.0.1:37933 (Press CTRL+C to quit)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"INFO: 76.21.76.39:0 - \"GET / HTTP/1.1\" 200 OK\n",
"INFO: 76.21.76.39:0 - \"GET /assets/index-fc1a91e8.js HTTP/1.1\" 200 OK\n",
"INFO: 76.21.76.39:0 - \"GET /assets/index-f75c1c12.css HTTP/1.1\" 200 OK\n",
"INFO: 76.21.76.39:0 - \"GET /components HTTP/1.1\" 200 OK\n",
"INFO: 76.21.76.39:0 - \"GET /vite.svg HTTP/1.1\" 200 OK\n",
"INFO: 76.21.76.39:0 - \"GET /chat/qa_table/retrieve HTTP/1.1\" 200 OK\n",
"INFO: 76.21.76.39:0 - \"GET /chat/qa_table/retrieve HTTP/1.1\" 200 OK\n",
"INFO: 76.21.76.39:0 - \"GET /chat/qa_table/retrieve HTTP/1.1\" 200 OK\n",
"INFO: 76.21.76.39:0 - \"GET /chat/qa_table/retrieve HTTP/1.1\" 200 OK\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO: Shutting down\n",
"INFO: Waiting for application shutdown.\n",
"INFO: Application shutdown complete.\n",
"INFO: Finished server process [21474]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Stopping server...\n"
]
}
],
"outputs": [],
"source": [
"app = pykoi.Application(debug=False, share=True)\n",
"app = Application(debug=False, share=True)\n",
"app.add_component(chatbot)\n",
"app.add_component(qa_dashboard)\n",
"app.run()\n"
Expand All @@ -331,13 +184,6 @@
" <img src=\"../image/chatbot_dashboard_trim_2x.gif\" width=\"75%\" height=\"75%\" />\n",
"</p>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading