{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "408379d2", "metadata": {}, "outputs": [], "source": [ "# !pip install langchain openai chromadb tiktoken pypdf panel" ] }, { "cell_type": "code", "execution_count": 2, "id": "fd6b0369", "metadata": {}, "outputs": [], "source": [ "# pip install --upgrade langchain" ] }, { "cell_type": "code", "execution_count": 1, "id": "7ad8054f", "metadata": {}, "outputs": [], "source": [ "## import libraries\n", "import os \n", "from langchain.llms import OpenAI\n", "from langchain.chains import RetrievalQA\n", "from langchain.document_loaders import TextLoader\n", "from langchain.document_loaders import PyPDFLoader\n", "from langchain.indexes import VectorstoreIndexCreator\n", "from langchain.text_splitter import CharacterTextSplitter\n", "from langchain.embeddings import OpenAIEmbeddings\n", "from langchain.vectorstores import Chroma\n", "import panel as pn\n", "import tempfile" ] }, { "cell_type": "code", "execution_count": 2, "id": "00374e26", "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "(function(root) {\n", " function now() {\n", " return new Date();\n", " }\n", "\n", " var force = true;\n", "\n", " if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n", " root._bokeh_onload_callbacks = [];\n", " root._bokeh_is_loading = undefined;\n", " }\n", "\n", " if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n", " root._bokeh_timeout = Date.now() + 5000;\n", " root._bokeh_failed_load = false;\n", " }\n", "\n", " function run_callbacks() {\n", " try {\n", " root._bokeh_onload_callbacks.forEach(function(callback) {\n", " if (callback != null)\n", " callback();\n", " });\n", " } finally {\n", " delete root._bokeh_onload_callbacks\n", " }\n", " console.debug(\"Bokeh: all callbacks have finished\");\n", " }\n", "\n", " function load_libs(css_urls, js_urls, js_modules, callback) {\n", " if (css_urls == null) css_urls = [];\n", " if (js_urls == null) js_urls = [];\n", " if (js_modules == null) js_modules = [];\n", "\n", " root._bokeh_onload_callbacks.push(callback);\n", " if (root._bokeh_is_loading > 0) {\n", " console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", " return null;\n", " }\n", " if (js_urls.length === 0 && js_modules.length === 0) {\n", " run_callbacks();\n", " return null;\n", " }\n", " console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", "\n", " function on_load() {\n", " root._bokeh_is_loading--;\n", " if (root._bokeh_is_loading === 0) {\n", " console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n", " run_callbacks()\n", " }\n", " }\n", "\n", " function on_error() {\n", " console.error(\"failed to load \" + url);\n", " }\n", "\n", " for (var i = 0; i < css_urls.length; i++) {\n", " var url = css_urls[i];\n", " const element = document.createElement(\"link\");\n", " element.onload = on_load;\n", " element.onerror = on_error;\n", " element.rel = \"stylesheet\";\n", " element.type = \"text/css\";\n", " element.href = url;\n", " console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n", " document.body.appendChild(element);\n", " }\n", "\n", " var skip = [];\n", " if (window.requirejs) {\n", " window.requirejs.config({'packages': {}, 'paths': {'Quill': 'https://cdn.quilljs.com/1.3.6/quill', 'gridstack': 'https://cdn.jsdelivr.net/npm/gridstack@4.2.5/dist/gridstack-h5', 'notyf': 'https://cdn.jsdelivr.net/npm/notyf@3/notyf.min'}, 'shim': {'gridstack': {'exports': 'GridStack'}}});\n", " require([\"Quill\"], function(Quill) {\n", "\twindow.Quill = Quill\n", "\ton_load()\n", " })\n", " require([\"gridstack\"], function(GridStack) {\n", "\twindow.GridStack = GridStack\n", "\ton_load()\n", " })\n", " require([\"notyf\"], function() {\n", "\ton_load()\n", " })\n", " root._bokeh_is_loading = css_urls.length + 3;\n", " } else {\n", " root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length;\n", " } if (((window['Quill'] !== undefined) && (!(window['Quill'] instanceof HTMLElement))) || window.requirejs) {\n", " var urls = ['https://cdn.holoviz.org/panel/0.14.3/dist/bundled/quillinput/1.3.6/quill.js'];\n", " for (var i = 0; i < urls.length; i++) {\n", " skip.push(urls[i])\n", " }\n", " } if (((window['GridStack'] !== undefined) && (!(window['GridStack'] instanceof HTMLElement))) || window.requirejs) {\n", " var urls = ['https://cdn.holoviz.org/panel/0.14.3/dist/bundled/gridstack/gridstack@4.2.5/dist/gridstack-h5.js'];\n", " for (var i = 0; i < urls.length; i++) {\n", " skip.push(urls[i])\n", " }\n", " } if (((window['Notyf'] !== undefined) && (!(window['Notyf'] instanceof HTMLElement))) || window.requirejs) {\n", " var urls = ['https://cdn.holoviz.org/panel/0.14.3/dist/bundled/notificationarea/notyf@3/notyf.min.js'];\n", " for (var i = 0; i < urls.length; i++) {\n", " skip.push(urls[i])\n", " }\n", " } for (var i = 0; i < js_urls.length; i++) {\n", " var url = js_urls[i];\n", " if (skip.indexOf(url) >= 0) {\n", "\tif (!window.requirejs) {\n", "\t on_load();\n", "\t}\n", "\tcontinue;\n", " }\n", " var element = document.createElement('script');\n", " element.onload = on_load;\n", " element.onerror = on_error;\n", " element.async = false;\n", " element.src = url;\n", " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", " document.head.appendChild(element);\n", " }\n", " for (var i = 0; i < js_modules.length; i++) {\n", " var url = js_modules[i];\n", " if (skip.indexOf(url) >= 0) {\n", "\tif (!window.requirejs) {\n", "\t on_load();\n", "\t}\n", "\tcontinue;\n", " }\n", " var element = document.createElement('script');\n", " element.onload = on_load;\n", " element.onerror = on_error;\n", " element.async = false;\n", " element.src = url;\n", " element.type = \"module\";\n", " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", " document.head.appendChild(element);\n", " }\n", " if (!js_urls.length && !js_modules.length) {\n", " on_load()\n", " }\n", " };\n", "\n", " function inject_raw_css(css) {\n", " const element = document.createElement(\"style\");\n", " element.appendChild(document.createTextNode(css));\n", " document.body.appendChild(element);\n", " }\n", "\n", " var js_urls = [\"https://cdn.holoviz.org/panel/0.14.3/dist/bundled/quillinput/1.3.6/quill.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.3.min.js\", \"https://unpkg.com/@holoviz/panel@0.14.3/dist/panel.min.js\"];\n", " var js_modules = [];\n", " var css_urls = [\"https://cdn.holoviz.org/panel/0.14.3/dist/bundled/quillinput/1.3.6/quill.bubble.css\", \"https://cdn.holoviz.org/panel/0.14.3/dist/bundled/quillinput/1.3.6/quill.snow.css\", \"https://cdn.holoviz.org/panel/0.14.3/dist/css/alerts.css\", \"https://cdn.holoviz.org/panel/0.14.3/dist/css/card.css\", \"https://cdn.holoviz.org/panel/0.14.3/dist/css/dataframe.css\", \"https://cdn.holoviz.org/panel/0.14.3/dist/css/debugger.css\", \"https://cdn.holoviz.org/panel/0.14.3/dist/css/json.css\", \"https://cdn.holoviz.org/panel/0.14.3/dist/css/loading.css\", \"https://cdn.holoviz.org/panel/0.14.3/dist/css/markdown.css\", \"https://cdn.holoviz.org/panel/0.14.3/dist/css/widgets.css\"];\n", " var inline_js = [ function(Bokeh) {\n", " inject_raw_css(\"\\n .bk.pn-loading.arc:before {\\n background-image: url(\\\"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHN0eWxlPSJtYXJnaW46IGF1dG87IGJhY2tncm91bmQ6IG5vbmU7IGRpc3BsYXk6IGJsb2NrOyBzaGFwZS1yZW5kZXJpbmc6IGF1dG87IiB2aWV3Qm94PSIwIDAgMTAwIDEwMCIgcHJlc2VydmVBc3BlY3RSYXRpbz0ieE1pZFlNaWQiPiAgPGNpcmNsZSBjeD0iNTAiIGN5PSI1MCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjYzNjM2MzIiBzdHJva2Utd2lkdGg9IjEwIiByPSIzNSIgc3Ryb2tlLWRhc2hhcnJheT0iMTY0LjkzMzYxNDMxMzQ2NDE1IDU2Ljk3Nzg3MTQzNzgyMTM4Ij4gICAgPGFuaW1hdGVUcmFuc2Zvcm0gYXR0cmlidXRlTmFtZT0idHJhbnNmb3JtIiB0eXBlPSJyb3RhdGUiIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIiBkdXI9IjFzIiB2YWx1ZXM9IjAgNTAgNTA7MzYwIDUwIDUwIiBrZXlUaW1lcz0iMDsxIj48L2FuaW1hdGVUcmFuc2Zvcm0+ICA8L2NpcmNsZT48L3N2Zz4=\\\");\\n background-size: auto calc(min(50%, 400px));\\n }\\n \");\n", " }, function(Bokeh) {\n", " Bokeh.set_log_level(\"info\");\n", " },\n", "function(Bokeh) {} // ensure no trailing comma for IE\n", " ];\n", "\n", " function run_inline_js() {\n", " if ((root.Bokeh !== undefined) || (force === true)) {\n", " for (var i = 0; i < inline_js.length; i++) {\n", " inline_js[i].call(root, root.Bokeh);\n", " }} else if (Date.now() < root._bokeh_timeout) {\n", " setTimeout(run_inline_js, 100);\n", " } else if (!root._bokeh_failed_load) {\n", " console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n", " root._bokeh_failed_load = true;\n", " }\n", " }\n", "\n", " if (root._bokeh_is_loading === 0) {\n", " console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", " run_inline_js();\n", " } else {\n", " load_libs(css_urls, js_urls, js_modules, function() {\n", " console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n", " run_inline_js();\n", " });\n", " }\n", "}(window));" ], "application/vnd.holoviews_load.v0+json": "(function(root) {\n function now() {\n return new Date();\n }\n\n var force = true;\n\n if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n root._bokeh_onload_callbacks = [];\n root._bokeh_is_loading = undefined;\n }\n\n if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) {\n if (callback != null)\n callback();\n });\n } finally {\n delete root._bokeh_onload_callbacks\n }\n console.debug(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(css_urls, js_urls, js_modules, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n if (js_modules == null) js_modules = [];\n\n root._bokeh_onload_callbacks.push(callback);\n if (root._bokeh_is_loading > 0) {\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n }\n if (js_urls.length === 0 && js_modules.length === 0) {\n run_callbacks();\n return null;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n\n function on_load() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n run_callbacks()\n }\n }\n\n function on_error() {\n console.error(\"failed to load \" + url);\n }\n\n for (var i = 0; i < css_urls.length; i++) {\n var url = css_urls[i];\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error;\n element.rel = \"stylesheet\";\n element.type = \"text/css\";\n element.href = url;\n console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n document.body.appendChild(element);\n }\n\n var skip = [];\n if (window.requirejs) {\n window.requirejs.config({'packages': {}, 'paths': {'Quill': 'https://cdn.quilljs.com/1.3.6/quill', 'gridstack': 'https://cdn.jsdelivr.net/npm/gridstack@4.2.5/dist/gridstack-h5', 'notyf': 'https://cdn.jsdelivr.net/npm/notyf@3/notyf.min'}, 'shim': {'gridstack': {'exports': 'GridStack'}}});\n require([\"Quill\"], function(Quill) {\n\twindow.Quill = Quill\n\ton_load()\n })\n require([\"gridstack\"], function(GridStack) {\n\twindow.GridStack = GridStack\n\ton_load()\n })\n require([\"notyf\"], function() {\n\ton_load()\n })\n root._bokeh_is_loading = css_urls.length + 3;\n } else {\n root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length;\n } if (((window['Quill'] !== undefined) && (!(window['Quill'] instanceof HTMLElement))) || window.requirejs) {\n var urls = ['https://cdn.holoviz.org/panel/0.14.3/dist/bundled/quillinput/1.3.6/quill.js'];\n for (var i = 0; i < urls.length; i++) {\n skip.push(urls[i])\n }\n } if (((window['GridStack'] !== undefined) && (!(window['GridStack'] instanceof HTMLElement))) || window.requirejs) {\n var urls = ['https://cdn.holoviz.org/panel/0.14.3/dist/bundled/gridstack/gridstack@4.2.5/dist/gridstack-h5.js'];\n for (var i = 0; i < urls.length; i++) {\n skip.push(urls[i])\n }\n } if (((window['Notyf'] !== undefined) && (!(window['Notyf'] instanceof HTMLElement))) || window.requirejs) {\n var urls = ['https://cdn.holoviz.org/panel/0.14.3/dist/bundled/notificationarea/notyf@3/notyf.min.js'];\n for (var i = 0; i < urls.length; i++) {\n skip.push(urls[i])\n }\n } for (var i = 0; i < js_urls.length; i++) {\n var url = js_urls[i];\n if (skip.indexOf(url) >= 0) {\n\tif (!window.requirejs) {\n\t on_load();\n\t}\n\tcontinue;\n }\n var element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (var i = 0; i < js_modules.length; i++) {\n var url = js_modules[i];\n if (skip.indexOf(url) >= 0) {\n\tif (!window.requirejs) {\n\t on_load();\n\t}\n\tcontinue;\n }\n var element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n if (!js_urls.length && !js_modules.length) {\n on_load()\n }\n };\n\n function inject_raw_css(css) {\n const element = document.createElement(\"style\");\n element.appendChild(document.createTextNode(css));\n document.body.appendChild(element);\n }\n\n var js_urls = [\"https://cdn.holoviz.org/panel/0.14.3/dist/bundled/quillinput/1.3.6/quill.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.3.min.js\", \"https://unpkg.com/@holoviz/panel@0.14.3/dist/panel.min.js\"];\n var js_modules = [];\n var css_urls = [\"https://cdn.holoviz.org/panel/0.14.3/dist/bundled/quillinput/1.3.6/quill.bubble.css\", \"https://cdn.holoviz.org/panel/0.14.3/dist/bundled/quillinput/1.3.6/quill.snow.css\", \"https://cdn.holoviz.org/panel/0.14.3/dist/css/alerts.css\", \"https://cdn.holoviz.org/panel/0.14.3/dist/css/card.css\", \"https://cdn.holoviz.org/panel/0.14.3/dist/css/dataframe.css\", \"https://cdn.holoviz.org/panel/0.14.3/dist/css/debugger.css\", \"https://cdn.holoviz.org/panel/0.14.3/dist/css/json.css\", \"https://cdn.holoviz.org/panel/0.14.3/dist/css/loading.css\", \"https://cdn.holoviz.org/panel/0.14.3/dist/css/markdown.css\", \"https://cdn.holoviz.org/panel/0.14.3/dist/css/widgets.css\"];\n var inline_js = [ function(Bokeh) {\n inject_raw_css(\"\\n .bk.pn-loading.arc:before {\\n background-image: url(\\\"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHN0eWxlPSJtYXJnaW46IGF1dG87IGJhY2tncm91bmQ6IG5vbmU7IGRpc3BsYXk6IGJsb2NrOyBzaGFwZS1yZW5kZXJpbmc6IGF1dG87IiB2aWV3Qm94PSIwIDAgMTAwIDEwMCIgcHJlc2VydmVBc3BlY3RSYXRpbz0ieE1pZFlNaWQiPiAgPGNpcmNsZSBjeD0iNTAiIGN5PSI1MCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjYzNjM2MzIiBzdHJva2Utd2lkdGg9IjEwIiByPSIzNSIgc3Ryb2tlLWRhc2hhcnJheT0iMTY0LjkzMzYxNDMxMzQ2NDE1IDU2Ljk3Nzg3MTQzNzgyMTM4Ij4gICAgPGFuaW1hdGVUcmFuc2Zvcm0gYXR0cmlidXRlTmFtZT0idHJhbnNmb3JtIiB0eXBlPSJyb3RhdGUiIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIiBkdXI9IjFzIiB2YWx1ZXM9IjAgNTAgNTA7MzYwIDUwIDUwIiBrZXlUaW1lcz0iMDsxIj48L2FuaW1hdGVUcmFuc2Zvcm0+ICA8L2NpcmNsZT48L3N2Zz4=\\\");\\n background-size: auto calc(min(50%, 400px));\\n }\\n \");\n }, function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\nfunction(Bokeh) {} // ensure no trailing comma for IE\n ];\n\n function run_inline_js() {\n if ((root.Bokeh !== undefined) || (force === true)) {\n for (var i = 0; i < inline_js.length; i++) {\n inline_js[i].call(root, root.Bokeh);\n }} else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n }\n }\n\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n run_inline_js();\n } else {\n load_libs(css_urls, js_urls, js_modules, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n}(window));" }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "if ((window.PyViz === undefined) || (window.PyViz instanceof HTMLElement)) {\n", " window.PyViz = {comms: {}, comm_status:{}, kernels:{}, receivers: {}, plot_index: []}\n", "}\n", "\n", "\n", " function JupyterCommManager() {\n", " }\n", "\n", " JupyterCommManager.prototype.register_target = function(plot_id, comm_id, msg_handler) {\n", " if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n", " var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n", " comm_manager.register_target(comm_id, function(comm) {\n", " comm.on_msg(msg_handler);\n", " });\n", " } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n", " window.PyViz.kernels[plot_id].registerCommTarget(comm_id, function(comm) {\n", " comm.onMsg = msg_handler;\n", " });\n", " } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n", " google.colab.kernel.comms.registerTarget(comm_id, (comm) => {\n", " var messages = comm.messages[Symbol.asyncIterator]();\n", " function processIteratorResult(result) {\n", " var message = result.value;\n", " console.log(message)\n", " var content = {data: message.data, comm_id};\n", " var buffers = []\n", " for (var buffer of message.buffers || []) {\n", " buffers.push(new DataView(buffer))\n", " }\n", " var metadata = message.metadata || {};\n", " var msg = {content, buffers, metadata}\n", " msg_handler(msg);\n", " return messages.next().then(processIteratorResult);\n", " }\n", " return messages.next().then(processIteratorResult);\n", " })\n", " }\n", " }\n", "\n", " JupyterCommManager.prototype.get_client_comm = function(plot_id, comm_id, msg_handler) {\n", " if (comm_id in window.PyViz.comms) {\n", " return window.PyViz.comms[comm_id];\n", " } else if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n", " var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n", " var comm = comm_manager.new_comm(comm_id, {}, {}, {}, comm_id);\n", " if (msg_handler) {\n", " comm.on_msg(msg_handler);\n", " }\n", " } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n", " var comm = window.PyViz.kernels[plot_id].connectToComm(comm_id);\n", " comm.open();\n", " if (msg_handler) {\n", " comm.onMsg = msg_handler;\n", " }\n", " } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n", " var comm_promise = google.colab.kernel.comms.open(comm_id)\n", " comm_promise.then((comm) => {\n", " window.PyViz.comms[comm_id] = comm;\n", " if (msg_handler) {\n", " var messages = comm.messages[Symbol.asyncIterator]();\n", " function processIteratorResult(result) {\n", " var message = result.value;\n", " var content = {data: message.data};\n", " var metadata = message.metadata || {comm_id};\n", " var msg = {content, metadata}\n", " msg_handler(msg);\n", " return messages.next().then(processIteratorResult);\n", " }\n", " return messages.next().then(processIteratorResult);\n", " }\n", " }) \n", " var sendClosure = (data, metadata, buffers, disposeOnDone) => {\n", " return comm_promise.then((comm) => {\n", " comm.send(data, metadata, buffers, disposeOnDone);\n", " });\n", " };\n", " var comm = {\n", " send: sendClosure\n", " };\n", " }\n", " window.PyViz.comms[comm_id] = comm;\n", " return comm;\n", " }\n", " window.PyViz.comm_manager = new JupyterCommManager();\n", " \n", "\n", "\n", "var JS_MIME_TYPE = 'application/javascript';\n", "var HTML_MIME_TYPE = 'text/html';\n", "var EXEC_MIME_TYPE = 'application/vnd.holoviews_exec.v0+json';\n", "var CLASS_NAME = 'output';\n", "\n", "/**\n", " * Render data to the DOM node\n", " */\n", "function render(props, node) {\n", " var div = document.createElement(\"div\");\n", " var script = document.createElement(\"script\");\n", " node.appendChild(div);\n", " node.appendChild(script);\n", "}\n", "\n", "/**\n", " * Handle when a new output is added\n", " */\n", "function handle_add_output(event, handle) {\n", " var output_area = handle.output_area;\n", " var output = handle.output;\n", " if ((output.data == undefined) || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n", " return\n", " }\n", " var id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n", " var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n", " if (id !== undefined) {\n", " var nchildren = toinsert.length;\n", " var html_node = toinsert[nchildren-1].children[0];\n", " html_node.innerHTML = output.data[HTML_MIME_TYPE];\n", " var scripts = [];\n", " var nodelist = html_node.querySelectorAll(\"script\");\n", " for (var i in nodelist) {\n", " if (nodelist.hasOwnProperty(i)) {\n", " scripts.push(nodelist[i])\n", " }\n", " }\n", "\n", " scripts.forEach( function (oldScript) {\n", " var newScript = document.createElement(\"script\");\n", " var attrs = [];\n", " var nodemap = oldScript.attributes;\n", " for (var j in nodemap) {\n", " if (nodemap.hasOwnProperty(j)) {\n", " attrs.push(nodemap[j])\n", " }\n", " }\n", " attrs.forEach(function(attr) { newScript.setAttribute(attr.name, attr.value) });\n", " newScript.appendChild(document.createTextNode(oldScript.innerHTML));\n", " oldScript.parentNode.replaceChild(newScript, oldScript);\n", " });\n", " if (JS_MIME_TYPE in output.data) {\n", " toinsert[nchildren-1].children[1].textContent = output.data[JS_MIME_TYPE];\n", " }\n", " output_area._hv_plot_id = id;\n", " if ((window.Bokeh !== undefined) && (id in Bokeh.index)) {\n", " window.PyViz.plot_index[id] = Bokeh.index[id];\n", " } else {\n", " window.PyViz.plot_index[id] = null;\n", " }\n", " } else if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n", " var bk_div = document.createElement(\"div\");\n", " bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n", " var script_attrs = bk_div.children[0].attributes;\n", " for (var i = 0; i < script_attrs.length; i++) {\n", " toinsert[toinsert.length - 1].childNodes[1].setAttribute(script_attrs[i].name, script_attrs[i].value);\n", " }\n", " // store reference to server id on output_area\n", " output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n", " }\n", "}\n", "\n", "/**\n", " * Handle when an output is cleared or removed\n", " */\n", "function handle_clear_output(event, handle) {\n", " var id = handle.cell.output_area._hv_plot_id;\n", " var server_id = handle.cell.output_area._bokeh_server_id;\n", " if (((id === undefined) || !(id in PyViz.plot_index)) && (server_id !== undefined)) { return; }\n", " var comm = window.PyViz.comm_manager.get_client_comm(\"hv-extension-comm\", \"hv-extension-comm\", function () {});\n", " if (server_id !== null) {\n", " comm.send({event_type: 'server_delete', 'id': server_id});\n", " return;\n", " } else if (comm !== null) {\n", " comm.send({event_type: 'delete', 'id': id});\n", " }\n", " delete PyViz.plot_index[id];\n", " if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {\n", " var doc = window.Bokeh.index[id].model.document\n", " doc.clear();\n", " const i = window.Bokeh.documents.indexOf(doc);\n", " if (i > -1) {\n", " window.Bokeh.documents.splice(i, 1);\n", " }\n", " }\n", "}\n", "\n", "/**\n", " * Handle kernel restart event\n", " */\n", "function handle_kernel_cleanup(event, handle) {\n", " delete PyViz.comms[\"hv-extension-comm\"];\n", " window.PyViz.plot_index = {}\n", "}\n", "\n", "/**\n", " * Handle update_display_data messages\n", " */\n", "function handle_update_output(event, handle) {\n", " handle_clear_output(event, {cell: {output_area: handle.output_area}})\n", " handle_add_output(event, handle)\n", "}\n", "\n", "function register_renderer(events, OutputArea) {\n", " function append_mime(data, metadata, element) {\n", " // create a DOM node to render to\n", " var toinsert = this.create_output_subarea(\n", " metadata,\n", " CLASS_NAME,\n", " EXEC_MIME_TYPE\n", " );\n", " this.keyboard_manager.register_events(toinsert);\n", " // Render to node\n", " var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n", " render(props, toinsert[0]);\n", " element.append(toinsert);\n", " return toinsert\n", " }\n", "\n", " events.on('output_added.OutputArea', handle_add_output);\n", " events.on('output_updated.OutputArea', handle_update_output);\n", " events.on('clear_output.CodeCell', handle_clear_output);\n", " events.on('delete.Cell', handle_clear_output);\n", " events.on('kernel_ready.Kernel', handle_kernel_cleanup);\n", "\n", " OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n", " safe: true,\n", " index: 0\n", " });\n", "}\n", "\n", "if (window.Jupyter !== undefined) {\n", " try {\n", " var events = require('base/js/events');\n", " var OutputArea = require('notebook/js/outputarea').OutputArea;\n", " if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n", " register_renderer(events, OutputArea);\n", " }\n", " } catch(err) {\n", " }\n", "}\n" ], "application/vnd.holoviews_load.v0+json": "\nif ((window.PyViz === undefined) || (window.PyViz instanceof HTMLElement)) {\n window.PyViz = {comms: {}, comm_status:{}, kernels:{}, receivers: {}, plot_index: []}\n}\n\n\n function JupyterCommManager() {\n }\n\n JupyterCommManager.prototype.register_target = function(plot_id, comm_id, msg_handler) {\n if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n comm_manager.register_target(comm_id, function(comm) {\n comm.on_msg(msg_handler);\n });\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n window.PyViz.kernels[plot_id].registerCommTarget(comm_id, function(comm) {\n comm.onMsg = msg_handler;\n });\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n google.colab.kernel.comms.registerTarget(comm_id, (comm) => {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n console.log(message)\n var content = {data: message.data, comm_id};\n var buffers = []\n for (var buffer of message.buffers || []) {\n buffers.push(new DataView(buffer))\n }\n var metadata = message.metadata || {};\n var msg = {content, buffers, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n })\n }\n }\n\n JupyterCommManager.prototype.get_client_comm = function(plot_id, comm_id, msg_handler) {\n if (comm_id in window.PyViz.comms) {\n return window.PyViz.comms[comm_id];\n } else if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n var comm = comm_manager.new_comm(comm_id, {}, {}, {}, comm_id);\n if (msg_handler) {\n comm.on_msg(msg_handler);\n }\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n var comm = window.PyViz.kernels[plot_id].connectToComm(comm_id);\n comm.open();\n if (msg_handler) {\n comm.onMsg = msg_handler;\n }\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n var comm_promise = google.colab.kernel.comms.open(comm_id)\n comm_promise.then((comm) => {\n window.PyViz.comms[comm_id] = comm;\n if (msg_handler) {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n var content = {data: message.data};\n var metadata = message.metadata || {comm_id};\n var msg = {content, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n }\n }) \n var sendClosure = (data, metadata, buffers, disposeOnDone) => {\n return comm_promise.then((comm) => {\n comm.send(data, metadata, buffers, disposeOnDone);\n });\n };\n var comm = {\n send: sendClosure\n };\n }\n window.PyViz.comms[comm_id] = comm;\n return comm;\n }\n window.PyViz.comm_manager = new JupyterCommManager();\n \n\n\nvar JS_MIME_TYPE = 'application/javascript';\nvar HTML_MIME_TYPE = 'text/html';\nvar EXEC_MIME_TYPE = 'application/vnd.holoviews_exec.v0+json';\nvar CLASS_NAME = 'output';\n\n/**\n * Render data to the DOM node\n */\nfunction render(props, node) {\n var div = document.createElement(\"div\");\n var script = document.createElement(\"script\");\n node.appendChild(div);\n node.appendChild(script);\n}\n\n/**\n * Handle when a new output is added\n */\nfunction handle_add_output(event, handle) {\n var output_area = handle.output_area;\n var output = handle.output;\n if ((output.data == undefined) || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n return\n }\n var id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n if (id !== undefined) {\n var nchildren = toinsert.length;\n var html_node = toinsert[nchildren-1].children[0];\n html_node.innerHTML = output.data[HTML_MIME_TYPE];\n var scripts = [];\n var nodelist = html_node.querySelectorAll(\"script\");\n for (var i in nodelist) {\n if (nodelist.hasOwnProperty(i)) {\n scripts.push(nodelist[i])\n }\n }\n\n scripts.forEach( function (oldScript) {\n var newScript = document.createElement(\"script\");\n var attrs = [];\n var nodemap = oldScript.attributes;\n for (var j in nodemap) {\n if (nodemap.hasOwnProperty(j)) {\n attrs.push(nodemap[j])\n }\n }\n attrs.forEach(function(attr) { newScript.setAttribute(attr.name, attr.value) });\n newScript.appendChild(document.createTextNode(oldScript.innerHTML));\n oldScript.parentNode.replaceChild(newScript, oldScript);\n });\n if (JS_MIME_TYPE in output.data) {\n toinsert[nchildren-1].children[1].textContent = output.data[JS_MIME_TYPE];\n }\n output_area._hv_plot_id = id;\n if ((window.Bokeh !== undefined) && (id in Bokeh.index)) {\n window.PyViz.plot_index[id] = Bokeh.index[id];\n } else {\n window.PyViz.plot_index[id] = null;\n }\n } else if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n var bk_div = document.createElement(\"div\");\n bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n var script_attrs = bk_div.children[0].attributes;\n for (var i = 0; i < script_attrs.length; i++) {\n toinsert[toinsert.length - 1].childNodes[1].setAttribute(script_attrs[i].name, script_attrs[i].value);\n }\n // store reference to server id on output_area\n output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n }\n}\n\n/**\n * Handle when an output is cleared or removed\n */\nfunction handle_clear_output(event, handle) {\n var id = handle.cell.output_area._hv_plot_id;\n var server_id = handle.cell.output_area._bokeh_server_id;\n if (((id === undefined) || !(id in PyViz.plot_index)) && (server_id !== undefined)) { return; }\n var comm = window.PyViz.comm_manager.get_client_comm(\"hv-extension-comm\", \"hv-extension-comm\", function () {});\n if (server_id !== null) {\n comm.send({event_type: 'server_delete', 'id': server_id});\n return;\n } else if (comm !== null) {\n comm.send({event_type: 'delete', 'id': id});\n }\n delete PyViz.plot_index[id];\n if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {\n var doc = window.Bokeh.index[id].model.document\n doc.clear();\n const i = window.Bokeh.documents.indexOf(doc);\n if (i > -1) {\n window.Bokeh.documents.splice(i, 1);\n }\n }\n}\n\n/**\n * Handle kernel restart event\n */\nfunction handle_kernel_cleanup(event, handle) {\n delete PyViz.comms[\"hv-extension-comm\"];\n window.PyViz.plot_index = {}\n}\n\n/**\n * Handle update_display_data messages\n */\nfunction handle_update_output(event, handle) {\n handle_clear_output(event, {cell: {output_area: handle.output_area}})\n handle_add_output(event, handle)\n}\n\nfunction register_renderer(events, OutputArea) {\n function append_mime(data, metadata, element) {\n // create a DOM node to render to\n var toinsert = this.create_output_subarea(\n metadata,\n CLASS_NAME,\n EXEC_MIME_TYPE\n );\n this.keyboard_manager.register_events(toinsert);\n // Render to node\n var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n render(props, toinsert[0]);\n element.append(toinsert);\n return toinsert\n }\n\n events.on('output_added.OutputArea', handle_add_output);\n events.on('output_updated.OutputArea', handle_update_output);\n events.on('clear_output.CodeCell', handle_clear_output);\n events.on('delete.Cell', handle_clear_output);\n events.on('kernel_ready.Kernel', handle_kernel_cleanup);\n\n OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n safe: true,\n index: 0\n });\n}\n\nif (window.Jupyter !== undefined) {\n try {\n var events = require('base/js/events');\n var OutputArea = require('notebook/js/outputarea').OutputArea;\n if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n register_renderer(events, OutputArea);\n }\n } catch(err) {\n }\n}\n" }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "## panel extension\n", "pn.extension('texteditor', template=\"bootstrap\", sizing_mode='stretch_width')\n", "pn.state.template.param.update(\n", " main_max_width=\"690px\",\n", " header_background=\"#F08080\",\n", ")" ] }, { "cell_type": "code", "execution_count": 9, "id": "47ad9a37", "metadata": {}, "outputs": [], "source": [ "## create widgets\n", "file_input = pn.widgets.FileInput(width=300)\n", "\n", "openaikey = pn.widgets.PasswordInput(value=\"\", placeholder=\"Enter your OpenAI API Key here...\", width=300)\n", "prompt = pn.widgets.TextEditor(\n", " value=\"\", placeholder=\"Enter your questions here...\", height=160, toolbar=False\n", ")\n", "run_button = pn.widgets.Button(name=\"Run!\")\n", "\n", "\n", "select_k = pn.widgets.IntSlider(\n", " name=\"Number of relevant chunks\", start=1, end=5, step=1, value=1\n", ")\n", "select_temperature = pn.widgets.FloatInput(\n", " name=\"Temperature\", start=0, end=1, step=0.01, value=0\n", ")\n", "select_chain_type = pn.widgets.RadioButtonGroup(\n", " name='Chain type', \n", " options=['stuff', 'map_reduce', \"refine\", \"map_rerank\"]\n", ")\n", "\n", "widgets = pn.Row(\n", " pn.Column(prompt, run_button, margin=5),\n", " pn.Card(\n", " \"Chain type:\",\n", " pn.Column(select_chain_type, select_k,select_temperature),\n", " title=\"Advanced settings\", margin=10\n", " ), width=600\n", ")" ] }, { "cell_type": "code", "execution_count": 10, "id": "66408a94", "metadata": {}, "outputs": [ { "data": {}, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.holoviews_exec.v0+json": "", "text/html": [ "
\n", "
\n", "
\n", "" ], "text/plain": [ "FileInput(width=300)" ] }, "execution_count": 10, "metadata": { "application/vnd.holoviews_exec.v0+json": { "id": "1020" } }, "output_type": "execute_result" } ], "source": [ "file_input" ] }, { "cell_type": "code", "execution_count": 11, "id": "513346b0", "metadata": {}, "outputs": [], "source": [ "file_input.value" ] }, { "cell_type": "code", "execution_count": 12, "id": "58871895", "metadata": {}, "outputs": [ { "data": {}, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.holoviews_exec.v0+json": "", "text/html": [ "
\n", "
\n", "
\n", "" ], "text/plain": [ "PasswordInput(placeholder='Enter your OpenAI A..., width=300)" ] }, "execution_count": 12, "metadata": { "application/vnd.holoviews_exec.v0+json": { "id": "1022" } }, "output_type": "execute_result" } ], "source": [ "openaikey" ] }, { "cell_type": "code", "execution_count": 13, "id": "e9370c45", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "''" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "openaikey.value" ] }, { "cell_type": "code", "execution_count": 14, "id": "5063b918", "metadata": { "scrolled": true }, "outputs": [ { "data": {}, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.holoviews_exec.v0+json": "", "text/html": [ "
\n", "
\n", "
\n", "" ], "text/plain": [ "Row(width=600)\n", " [0] Column(margin=5, sizing_mode='stretch_width')\n", " [0] TextEditor(height=160, placeholder='Enter your questions h..., sizing_mode='stretch_width', toolbar=False)\n", " [1] Button(name='Run!', sizing_mode='stretch_width')\n", " [1] Card(margin=10, sizing_mode='stretch_width', title='Advanced settings')\n", " [0] Markdown(str, sizing_mode='stretch_width')\n", " [1] Column(sizing_mode='stretch_width')\n", " [0] RadioButtonGroup(name='Chain type', options=['stuff', 'map_reduce', ...], sizing_mode='stretch_width', value='stuff')\n", " [1] IntSlider(end=5, name='Number of relevant c..., sizing_mode='stretch_width', start=1, value=1)\n", " [2] FloatInput(end=1, name='Temperature', sizing_mode='stretch_width', start=0, step=0.01)" ] }, "execution_count": 14, "metadata": { "application/vnd.holoviews_exec.v0+json": { "id": "1024" } }, "output_type": "execute_result" } ], "source": [ "widgets" ] }, { "cell_type": "code", "execution_count": 15, "id": "a3aeae41", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "select_temperature.value" ] }, { "cell_type": "code", "execution_count": 24, "id": "49527073", "metadata": {}, "outputs": [], "source": [ "def qa(file, query, chain_type, k,temperature_value):\n", " # load document\n", " loader = PyPDFLoader(file)\n", " documents = loader.load()\n", " # split the documents into chunks\n", " text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n", " texts = text_splitter.split_documents(documents)\n", " # select which embeddings we want to use\n", " embeddings = OpenAIEmbeddings()\n", "# embeddings = OpenAIEmbeddings(model='text-search-ada-doc-001')\n", " # create the vectorestore to use as the index\n", " db = Chroma.from_documents(texts, embeddings)\n", " # expose this index in a retriever interface\n", " retriever = db.as_retriever(search_type=\"similarity\", search_kwargs={\"k\": k})\n", " # create a chain to answer questions\n", " qa_chain = RetrievalQA.from_chain_type(\n", " llm=OpenAI(temperature=temperature_value), chain_type=chain_type, retriever=retriever, return_source_documents=True)\n", " result = qa_chain({\"query\": query})\n", " print(result['result'])\n", " return result" ] }, { "cell_type": "code", "execution_count": 18, "id": "70bdf5fa", "metadata": {}, "outputs": [], "source": [ "# os.environ[\"OPENAI_API_KEY\"] = ''" ] }, { "cell_type": "code", "execution_count": 14, "id": "e078d4ff", "metadata": {}, "outputs": [], "source": [ "# pip install pypdf" ] }, { "cell_type": "code", "execution_count": 15, "id": "a2277058", "metadata": {}, "outputs": [], "source": [ "# pip install openai" ] }, { "cell_type": "code", "execution_count": 16, "id": "37de0392", "metadata": {}, "outputs": [], "source": [ "# pip install --upgrade setuptools" ] }, { "cell_type": "code", "execution_count": 17, "id": "647f20fb", "metadata": {}, "outputs": [], "source": [ "# pip install chromadb" ] }, { "cell_type": "code", "execution_count": 18, "id": "d0f1cab3", "metadata": {}, "outputs": [], "source": [ "# pip install hnswlib" ] }, { "cell_type": "code", "execution_count": 19, "id": "39cb6064", "metadata": {}, "outputs": [], "source": [ "# pip install tiktoken" ] }, { "cell_type": "code", "execution_count": 6, "id": "abcd7f28", "metadata": {}, "outputs": [], "source": [ "# result = qa(\"ai_index.pdf\", \"what is the summary of the document\",'stuff',2,0.5)" ] }, { "cell_type": "code", "execution_count": 7, "id": "6c2bd936", "metadata": {}, "outputs": [], "source": [ "# result" ] }, { "cell_type": "code", "execution_count": 17, "id": "d5a59df5", "metadata": {}, "outputs": [], "source": [ "convos = [] # store all panel objects in a list\n", "\n", "def qa_result(_):\n", " os.environ[\"OPENAI_API_KEY\"] = openaikey.value\n", " \n", " # save pdf file to a temp file \n", " if file_input.value is not None:\n", " file_input.save(\"temp.pdf\")\n", " \n", " prompt_text = prompt.value\n", " print(prompt_text)\n", " if prompt_text:\n", " result = qa(file=\"temp.pdf\", query=prompt_text, chain_type=select_chain_type.value, k=select_k.value,temperature_value=select_temperature.value)\n", " print(result)\n", " convos.extend([\n", " pn.Row(\n", " pn.panel(\"\\U0001F60A\", width=10),\n", " prompt_text,\n", " width=600\n", " ),\n", " pn.Row(\n", " pn.panel(\"\\U0001F916\", width=10),\n", " pn.Column(\n", " result[\"result\"],\n", "# \"Relevant source text:\",\n", "# pn.pane.Markdown('\\n--------------------------------------------------------------------\\n'.join(doc.page_content for doc in result[\"source_documents\"]))\n", " )\n", " )\n", " ])\n", " #return convos\n", " return pn.Column(*convos, margin=15, width=575, min_height=300)" ] }, { "cell_type": "code", "execution_count": 19, "id": "8beb0b30", "metadata": {}, "outputs": [ { "data": {}, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.holoviews_exec.v0+json": "", "text/html": [ "
\n", "
\n", "
\n", "" ], "text/plain": [ "TextEditor(height=160, placeholder='Enter your questions h..., sizing_mode='stretch_width', toolbar=False)" ] }, "execution_count": 19, "metadata": { "application/vnd.holoviews_exec.v0+json": { "id": "1020" } }, "output_type": "execute_result" } ], "source": [ "# prompt" ] }, { "cell_type": "code", "execution_count": 20, "id": "b4fd5346", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'

How many AI publications in 2021

'" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# prompt.value" ] }, { "cell_type": "code", "execution_count": 23, "id": "b72fe800", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('stuff', 2, 0.6)" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# select_chain_type.value, select_k.value,select_temperature.value" ] }, { "cell_type": "code", "execution_count": 21, "id": "7e8c9ef6", "metadata": {}, "outputs": [ { "data": {}, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.holoviews_exec.v0+json": "", "text/html": [ "
\n", "
\n", "
\n", "" ], "text/plain": [ "Row(width=600)\n", " [0] Markdown(str, width=10)\n", " [1] Markdown(str, sizing_mode='stretch_width')" ] }, "execution_count": 21, "metadata": { "application/vnd.holoviews_exec.v0+json": { "id": "1033" } }, "output_type": "execute_result" } ], "source": [ "# pn.Row(\n", "# pn.panel(\"\\U0001F60A\", width=10),\n", "# prompt.value,\n", "# width=600)" ] }, { "cell_type": "code", "execution_count": 22, "id": "f9fd4e7b", "metadata": {}, "outputs": [ { "data": {}, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.holoviews_exec.v0+json": "", "text/html": [ "
\n", "
\n", "
\n", "" ], "text/plain": [ "Row(sizing_mode='stretch_width')\n", " [0] Markdown(str, width=10)\n", " [1] Column(sizing_mode='stretch_width')\n", " [0] Markdown(str, sizing_mode='stretch_width')\n", " [1] Markdown(str, sizing_mode='stretch_width')\n", " [2] Markdown(str, sizing_mode='stretch_width')" ] }, "execution_count": 22, "metadata": { "application/vnd.holoviews_exec.v0+json": { "id": "1037" } }, "output_type": "execute_result" } ], "source": [ "# pn.Row(\n", "# pn.panel(\"\\U0001F916\", width=10),\n", "# pn.Column(\n", "# result[\"result\"],\n", "# \"Relevant source text:\",\n", "# pn.pane.Markdown('\\n--------------------------------------------------------------------\\n'.join(doc.page_content for doc in result[\"source_documents\"]))\n", "# )\n", "# )" ] }, { "cell_type": "code", "execution_count": 18, "id": "1d01984b", "metadata": {}, "outputs": [], "source": [ "qa_interactive = pn.panel(\n", " pn.bind(qa_result, run_button),\n", " loading_indicator=True,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "663bc08b", "metadata": {}, "outputs": [], "source": [ "# qa_result(_)" ] }, { "cell_type": "code", "execution_count": 19, "id": "f7a8e3f5", "metadata": {}, "outputs": [], "source": [ "output = pn.WidgetBox('*Output will display here:*', qa_interactive, width=600,height=350, scroll=True)" ] }, { "cell_type": "code", "execution_count": 22, "id": "27facdde", "metadata": {}, "outputs": [], "source": [ "# output" ] }, { "cell_type": "code", "execution_count": 20, "id": "071de197", "metadata": {}, "outputs": [], "source": [ "# Create a button to clear the chat output\n", "clear_button = pn.widgets.Button(name='Clear')" ] }, { "cell_type": "code", "execution_count": 21, "id": "98f01c5b", "metadata": {}, "outputs": [], "source": [ "# Define the callback function for the clear button\n", "def clear_output(_):\n", " global convos\n", " convos=[] # Clear the chat output" ] }, { "cell_type": "code", "execution_count": 22, "id": "23e7bbbf", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Watcher(inst=Button(name='Clear', sizing_mode='stretch_width'), cls=, fn=, mode='args', onlychanged=False, parameter_names=('clicks',), what='value', queued=False, precedence=0)" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Set the callback function for the clear button\n", "clear_button.on_click(clear_output)" ] }, { "cell_type": "code", "execution_count": 32, "id": "1ada4113", "metadata": {}, "outputs": [], "source": [ "# output.append(qa_interactive)" ] }, { "cell_type": "code", "execution_count": 33, "id": "24d255b4", "metadata": {}, "outputs": [], "source": [ "# pn.bind(clr,clr_button)" ] }, { "cell_type": "code", "execution_count": 34, "id": "cab36281", "metadata": {}, "outputs": [], "source": [ "# output" ] }, { "cell_type": "code", "execution_count": 30, "id": "1946ea80", "metadata": {}, "outputs": [], "source": [ "# clr_button = pn.widgets.Button(name=\"Clear\",width=280)" ] }, { "cell_type": "code", "execution_count": 36, "id": "86ed98be", "metadata": {}, "outputs": [], "source": [ "# clr=output.clear() " ] }, { "cell_type": "code", "execution_count": 37, "id": "da24690b", "metadata": {}, "outputs": [], "source": [ "# clr_button.on_click(output.clear())" ] }, { "cell_type": "code", "execution_count": 38, "id": "59c90641", "metadata": {}, "outputs": [], "source": [ "# if clr_button.clicks>=1\n", "# value=1\n", "# output" ] }, { "cell_type": "code", "execution_count": 39, "id": "87c12370", "metadata": {}, "outputs": [], "source": [ "# clear_button=pn.panel(pn.bind(clr,clr_button))\n", "# clear=pn.WidgetBox(clear_button,clr_button)" ] }, { "cell_type": "code", "execution_count": 23, "id": "c1944209", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
Traceback (most recent call last):\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\pyviz_comms\\__init__.py", line 325, in _handle_msg\n",
       "    self._on_msg(msg)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\viewable.py", line 297, in _on_msg\n",
       "    patch.apply_to_document(doc, comm.id if comm else None)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\protocol\\messages\\patch_doc.py", line 115, in apply_to_document\n",
       "    invoke_with_curdoc(doc, lambda: doc.apply_json_patch(self.content, setter))\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\callbacks.py", line 408, in invoke_with_curdoc\n",
       "    return f()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\protocol\\messages\\patch_doc.py", line 115, in <lambda>\n",
       "    invoke_with_curdoc(doc, lambda: doc.apply_json_patch(self.content, setter))\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\document.py", line 391, in apply_json_patch\n",
       "    DocumentPatchedEvent.handle_json(self, event_json, references, setter)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\events.py", line 259, in handle_json\n",
       "    handler(doc, event_json, references, setter)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\events.py", line 300, in _handle_json\n",
       "    cb(event_json["msg_data"])\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\callbacks.py", line 355, in trigger_json_event\n",
       "    model._trigger_event(event)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\util\\callback_manager.py", line 119, in _trigger_event\n",
       "    self.document.callbacks.notify_event(cast(Model, self), event, invoke)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\callbacks.py", line 247, in notify_event\n",
       "    invoke_with_curdoc(doc, callback_invoker)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\callbacks.py", line 408, in invoke_with_curdoc\n",
       "    return f()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\util\\callback_manager.py", line 115, in invoke\n",
       "    cast(EventCallbackWithEvent, callback)(event)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\reactive.py", line 413, in _comm_event\n",
       "    state._handle_exception(e)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\io\\state.py", line 408, in _handle_exception\n",
       "    raise exception\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\reactive.py", line 411, in _comm_event\n",
       "    self._process_bokeh_event(doc, event)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\reactive.py", line 348, in _process_bokeh_event\n",
       "    self._process_event(event)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\widgets\\button.py", line 183, in _process_event\n",
       "    self.param.trigger('value')\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 1993, in trigger\n",
       "    self_.set_param(**dict(params, **triggers))\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 1929, in set_param\n",
       "    return self_.update(kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 1902, in update\n",
       "    self_._batch_call_watchers()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 2063, in _batch_call_watchers\n",
       "    self_._execute_watcher(watcher, events)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 2025, in _execute_watcher\n",
       "    watcher.fn(*args, **kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\param.py", line 838, in _replace_pane\n",
       "    new_object = self.eval(self.object)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\param.py", line 818, in eval\n",
       "    return function(*args, **kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 407, in _depends\n",
       "    return func(*args, **kw)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\depends.py", line 209, in wrapped\n",
       "    return function(*combined_args, **combined_kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\Temp\\ipykernel_22964\\272212504.py", line 12, in qa_result\n",
       "    result = qa(file="temp.pdf", query=prompt_text, chain_type=select_chain_type.value, k=select_k.value,temperature_value=select_temperature.value)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\Temp\\ipykernel_22964\\2633984213.py", line 12, in qa\n",
       "    db = Chroma.from_documents(texts, embeddings)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\vectorstores\\chroma.py", line 413, in from_documents\n",
       "    return cls.from_texts(\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\vectorstores\\chroma.py", line 381, in from_texts\n",
       "    chroma_collection.add_texts(texts=texts, metadatas=metadatas, ids=ids)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\vectorstores\\chroma.py", line 158, in add_texts\n",
       "    embeddings = self._embedding_function.embed_documents(list(texts))\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\embeddings\\openai.py", line 275, in embed_documents\n",
       "    return self._get_len_safe_embeddings(texts, engine=self.deployment)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\embeddings\\openai.py", line 208, in _get_len_safe_embeddings\n",
       "    response = embed_with_retry(\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\embeddings\\openai.py", line 63, in embed_with_retry\n",
       "    return _embed_with_retry(**kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 289, in wrapped_f\n",
       "    return self(f, *args, **kw)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 379, in __call__\n",
       "    do = self.iter(retry_state=retry_state)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 325, in iter\n",
       "    raise retry_exc.reraise()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 158, in reraise\n",
       "    raise self.last_attempt.result()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\concurrent\\futures\\_base.py", line 451, in result\n",
       "    return self.__get_result()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\concurrent\\futures\\_base.py", line 403, in __get_result\n",
       "    raise self._exception\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 382, in __call__\n",
       "    result = fn(*args, **kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\embeddings\\openai.py", line 61, in _embed_with_retry\n",
       "    return embeddings.client.create(**kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_resources\\embedding.py", line 33, in create\n",
       "    response = super().create(*args, **kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_resources\\abstract\\engine_api_resource.py", line 153, in create\n",
       "    response, _, api_key = requestor.request(\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_requestor.py", line 230, in request\n",
       "    resp, got_stream = self._interpret_response(result, stream)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_requestor.py", line 624, in _interpret_response\n",
       "    self._interpret_response_line(\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_requestor.py", line 687, in _interpret_response_line\n",
       "    raise self.handle_error_response(\n",
       "openai.error.RateLimitError: You exceeded your current quota, please check your plan and billing details.\n",
       "
\n", "\n", "\n", "
Traceback (most recent call last):\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\pyviz_comms\\__init__.py", line 325, in _handle_msg\n",
       "    self._on_msg(msg)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\viewable.py", line 297, in _on_msg\n",
       "    patch.apply_to_document(doc, comm.id if comm else None)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\protocol\\messages\\patch_doc.py", line 115, in apply_to_document\n",
       "    invoke_with_curdoc(doc, lambda: doc.apply_json_patch(self.content, setter))\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\callbacks.py", line 408, in invoke_with_curdoc\n",
       "    return f()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\protocol\\messages\\patch_doc.py", line 115, in <lambda>\n",
       "    invoke_with_curdoc(doc, lambda: doc.apply_json_patch(self.content, setter))\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\document.py", line 391, in apply_json_patch\n",
       "    DocumentPatchedEvent.handle_json(self, event_json, references, setter)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\events.py", line 259, in handle_json\n",
       "    handler(doc, event_json, references, setter)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\events.py", line 300, in _handle_json\n",
       "    cb(event_json["msg_data"])\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\callbacks.py", line 355, in trigger_json_event\n",
       "    model._trigger_event(event)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\util\\callback_manager.py", line 119, in _trigger_event\n",
       "    self.document.callbacks.notify_event(cast(Model, self), event, invoke)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\callbacks.py", line 247, in notify_event\n",
       "    invoke_with_curdoc(doc, callback_invoker)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\callbacks.py", line 408, in invoke_with_curdoc\n",
       "    return f()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\util\\callback_manager.py", line 115, in invoke\n",
       "    cast(EventCallbackWithEvent, callback)(event)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\reactive.py", line 413, in _comm_event\n",
       "    state._handle_exception(e)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\io\\state.py", line 408, in _handle_exception\n",
       "    raise exception\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\reactive.py", line 411, in _comm_event\n",
       "    self._process_bokeh_event(doc, event)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\reactive.py", line 348, in _process_bokeh_event\n",
       "    self._process_event(event)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\widgets\\button.py", line 183, in _process_event\n",
       "    self.param.trigger('value')\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 1993, in trigger\n",
       "    self_.set_param(**dict(params, **triggers))\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 1929, in set_param\n",
       "    return self_.update(kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 1902, in update\n",
       "    self_._batch_call_watchers()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 2063, in _batch_call_watchers\n",
       "    self_._execute_watcher(watcher, events)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 2025, in _execute_watcher\n",
       "    watcher.fn(*args, **kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\param.py", line 838, in _replace_pane\n",
       "    new_object = self.eval(self.object)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\param.py", line 818, in eval\n",
       "    return function(*args, **kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 407, in _depends\n",
       "    return func(*args, **kw)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\depends.py", line 209, in wrapped\n",
       "    return function(*combined_args, **combined_kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\Temp\\ipykernel_22964\\272212504.py", line 12, in qa_result\n",
       "    result = qa(file="temp.pdf", query=prompt_text, chain_type=select_chain_type.value, k=select_k.value,temperature_value=select_temperature.value)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\Temp\\ipykernel_22964\\2633984213.py", line 12, in qa\n",
       "    db = Chroma.from_documents(texts, embeddings)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\vectorstores\\chroma.py", line 413, in from_documents\n",
       "    return cls.from_texts(\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\vectorstores\\chroma.py", line 381, in from_texts\n",
       "    chroma_collection.add_texts(texts=texts, metadatas=metadatas, ids=ids)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\vectorstores\\chroma.py", line 158, in add_texts\n",
       "    embeddings = self._embedding_function.embed_documents(list(texts))\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\embeddings\\openai.py", line 275, in embed_documents\n",
       "    return self._get_len_safe_embeddings(texts, engine=self.deployment)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\embeddings\\openai.py", line 208, in _get_len_safe_embeddings\n",
       "    response = embed_with_retry(\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\embeddings\\openai.py", line 63, in embed_with_retry\n",
       "    return _embed_with_retry(**kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 289, in wrapped_f\n",
       "    return self(f, *args, **kw)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 379, in __call__\n",
       "    do = self.iter(retry_state=retry_state)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 325, in iter\n",
       "    raise retry_exc.reraise()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 158, in reraise\n",
       "    raise self.last_attempt.result()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\concurrent\\futures\\_base.py", line 451, in result\n",
       "    return self.__get_result()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\concurrent\\futures\\_base.py", line 403, in __get_result\n",
       "    raise self._exception\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 382, in __call__\n",
       "    result = fn(*args, **kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\embeddings\\openai.py", line 61, in _embed_with_retry\n",
       "    return embeddings.client.create(**kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_resources\\embedding.py", line 33, in create\n",
       "    response = super().create(*args, **kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_resources\\abstract\\engine_api_resource.py", line 153, in create\n",
       "    response, _, api_key = requestor.request(\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_requestor.py", line 230, in request\n",
       "    resp, got_stream = self._interpret_response(result, stream)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_requestor.py", line 624, in _interpret_response\n",
       "    self._interpret_response_line(\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_requestor.py", line 687, in _interpret_response_line\n",
       "    raise self.handle_error_response(\n",
       "openai.error.RateLimitError: You exceeded your current quota, please check your plan and billing details.\n",
       "
\n", "\n", "\n", "
Traceback (most recent call last):\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\pyviz_comms\\__init__.py", line 325, in _handle_msg\n",
       "    self._on_msg(msg)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\viewable.py", line 297, in _on_msg\n",
       "    patch.apply_to_document(doc, comm.id if comm else None)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\protocol\\messages\\patch_doc.py", line 115, in apply_to_document\n",
       "    invoke_with_curdoc(doc, lambda: doc.apply_json_patch(self.content, setter))\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\callbacks.py", line 408, in invoke_with_curdoc\n",
       "    return f()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\protocol\\messages\\patch_doc.py", line 115, in <lambda>\n",
       "    invoke_with_curdoc(doc, lambda: doc.apply_json_patch(self.content, setter))\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\document.py", line 391, in apply_json_patch\n",
       "    DocumentPatchedEvent.handle_json(self, event_json, references, setter)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\events.py", line 259, in handle_json\n",
       "    handler(doc, event_json, references, setter)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\events.py", line 300, in _handle_json\n",
       "    cb(event_json["msg_data"])\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\callbacks.py", line 355, in trigger_json_event\n",
       "    model._trigger_event(event)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\util\\callback_manager.py", line 119, in _trigger_event\n",
       "    self.document.callbacks.notify_event(cast(Model, self), event, invoke)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\callbacks.py", line 247, in notify_event\n",
       "    invoke_with_curdoc(doc, callback_invoker)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\callbacks.py", line 408, in invoke_with_curdoc\n",
       "    return f()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\util\\callback_manager.py", line 115, in invoke\n",
       "    cast(EventCallbackWithEvent, callback)(event)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\reactive.py", line 413, in _comm_event\n",
       "    state._handle_exception(e)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\io\\state.py", line 408, in _handle_exception\n",
       "    raise exception\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\reactive.py", line 411, in _comm_event\n",
       "    self._process_bokeh_event(doc, event)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\reactive.py", line 348, in _process_bokeh_event\n",
       "    self._process_event(event)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\widgets\\button.py", line 183, in _process_event\n",
       "    self.param.trigger('value')\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 1993, in trigger\n",
       "    self_.set_param(**dict(params, **triggers))\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 1929, in set_param\n",
       "    return self_.update(kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 1902, in update\n",
       "    self_._batch_call_watchers()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 2063, in _batch_call_watchers\n",
       "    self_._execute_watcher(watcher, events)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 2025, in _execute_watcher\n",
       "    watcher.fn(*args, **kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\param.py", line 838, in _replace_pane\n",
       "    new_object = self.eval(self.object)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\param.py", line 818, in eval\n",
       "    return function(*args, **kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 407, in _depends\n",
       "    return func(*args, **kw)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\depends.py", line 209, in wrapped\n",
       "    return function(*combined_args, **combined_kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\Temp\\ipykernel_22964\\272212504.py", line 12, in qa_result\n",
       "    result = qa(file="temp.pdf", query=prompt_text, chain_type=select_chain_type.value, k=select_k.value,temperature_value=select_temperature.value)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\Temp\\ipykernel_22964\\2633984213.py", line 12, in qa\n",
       "    db = Chroma.from_documents(texts, embeddings)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\vectorstores\\chroma.py", line 413, in from_documents\n",
       "    return cls.from_texts(\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\vectorstores\\chroma.py", line 381, in from_texts\n",
       "    chroma_collection.add_texts(texts=texts, metadatas=metadatas, ids=ids)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\vectorstores\\chroma.py", line 158, in add_texts\n",
       "    embeddings = self._embedding_function.embed_documents(list(texts))\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\embeddings\\openai.py", line 275, in embed_documents\n",
       "    return self._get_len_safe_embeddings(texts, engine=self.deployment)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\embeddings\\openai.py", line 208, in _get_len_safe_embeddings\n",
       "    response = embed_with_retry(\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\embeddings\\openai.py", line 63, in embed_with_retry\n",
       "    return _embed_with_retry(**kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 289, in wrapped_f\n",
       "    return self(f, *args, **kw)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 379, in __call__\n",
       "    do = self.iter(retry_state=retry_state)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 325, in iter\n",
       "    raise retry_exc.reraise()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 158, in reraise\n",
       "    raise self.last_attempt.result()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\concurrent\\futures\\_base.py", line 451, in result\n",
       "    return self.__get_result()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\concurrent\\futures\\_base.py", line 403, in __get_result\n",
       "    raise self._exception\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 382, in __call__\n",
       "    result = fn(*args, **kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\embeddings\\openai.py", line 61, in _embed_with_retry\n",
       "    return embeddings.client.create(**kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_resources\\embedding.py", line 33, in create\n",
       "    response = super().create(*args, **kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_resources\\abstract\\engine_api_resource.py", line 153, in create\n",
       "    response, _, api_key = requestor.request(\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_requestor.py", line 230, in request\n",
       "    resp, got_stream = self._interpret_response(result, stream)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_requestor.py", line 624, in _interpret_response\n",
       "    self._interpret_response_line(\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_requestor.py", line 687, in _interpret_response_line\n",
       "    raise self.handle_error_response(\n",
       "openai.error.RateLimitError: You exceeded your current quota, please check your plan and billing details.\n",
       "
\n", "\n", "\n", "
Traceback (most recent call last):\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\pyviz_comms\\__init__.py", line 325, in _handle_msg\n",
       "    self._on_msg(msg)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\viewable.py", line 297, in _on_msg\n",
       "    patch.apply_to_document(doc, comm.id if comm else None)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\protocol\\messages\\patch_doc.py", line 115, in apply_to_document\n",
       "    invoke_with_curdoc(doc, lambda: doc.apply_json_patch(self.content, setter))\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\callbacks.py", line 408, in invoke_with_curdoc\n",
       "    return f()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\protocol\\messages\\patch_doc.py", line 115, in <lambda>\n",
       "    invoke_with_curdoc(doc, lambda: doc.apply_json_patch(self.content, setter))\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\document.py", line 391, in apply_json_patch\n",
       "    DocumentPatchedEvent.handle_json(self, event_json, references, setter)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\events.py", line 259, in handle_json\n",
       "    handler(doc, event_json, references, setter)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\events.py", line 300, in _handle_json\n",
       "    cb(event_json["msg_data"])\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\callbacks.py", line 355, in trigger_json_event\n",
       "    model._trigger_event(event)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\util\\callback_manager.py", line 119, in _trigger_event\n",
       "    self.document.callbacks.notify_event(cast(Model, self), event, invoke)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\callbacks.py", line 247, in notify_event\n",
       "    invoke_with_curdoc(doc, callback_invoker)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\document\\callbacks.py", line 408, in invoke_with_curdoc\n",
       "    return f()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\bokeh\\util\\callback_manager.py", line 115, in invoke\n",
       "    cast(EventCallbackWithEvent, callback)(event)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\reactive.py", line 413, in _comm_event\n",
       "    state._handle_exception(e)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\io\\state.py", line 408, in _handle_exception\n",
       "    raise exception\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\reactive.py", line 411, in _comm_event\n",
       "    self._process_bokeh_event(doc, event)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\reactive.py", line 348, in _process_bokeh_event\n",
       "    self._process_event(event)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\widgets\\button.py", line 183, in _process_event\n",
       "    self.param.trigger('value')\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 1993, in trigger\n",
       "    self_.set_param(**dict(params, **triggers))\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 1929, in set_param\n",
       "    return self_.update(kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 1902, in update\n",
       "    self_._batch_call_watchers()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 2063, in _batch_call_watchers\n",
       "    self_._execute_watcher(watcher, events)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 2025, in _execute_watcher\n",
       "    watcher.fn(*args, **kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\param.py", line 838, in _replace_pane\n",
       "    new_object = self.eval(self.object)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\param.py", line 818, in eval\n",
       "    return function(*args, **kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\param\\parameterized.py", line 407, in _depends\n",
       "    return func(*args, **kw)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\panel\\depends.py", line 209, in wrapped\n",
       "    return function(*combined_args, **combined_kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\Temp\\ipykernel_22964\\272212504.py", line 12, in qa_result\n",
       "    result = qa(file="temp.pdf", query=prompt_text, chain_type=select_chain_type.value, k=select_k.value,temperature_value=select_temperature.value)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\Temp\\ipykernel_22964\\2633984213.py", line 12, in qa\n",
       "    db = Chroma.from_documents(texts, embeddings)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\vectorstores\\chroma.py", line 413, in from_documents\n",
       "    return cls.from_texts(\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\vectorstores\\chroma.py", line 381, in from_texts\n",
       "    chroma_collection.add_texts(texts=texts, metadatas=metadatas, ids=ids)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\vectorstores\\chroma.py", line 158, in add_texts\n",
       "    embeddings = self._embedding_function.embed_documents(list(texts))\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\embeddings\\openai.py", line 275, in embed_documents\n",
       "    return self._get_len_safe_embeddings(texts, engine=self.deployment)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\embeddings\\openai.py", line 208, in _get_len_safe_embeddings\n",
       "    response = embed_with_retry(\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\embeddings\\openai.py", line 63, in embed_with_retry\n",
       "    return _embed_with_retry(**kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 289, in wrapped_f\n",
       "    return self(f, *args, **kw)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 379, in __call__\n",
       "    do = self.iter(retry_state=retry_state)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 325, in iter\n",
       "    raise retry_exc.reraise()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 158, in reraise\n",
       "    raise self.last_attempt.result()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\concurrent\\futures\\_base.py", line 451, in result\n",
       "    return self.__get_result()\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\concurrent\\futures\\_base.py", line 403, in __get_result\n",
       "    raise self._exception\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\tenacity\\__init__.py", line 382, in __call__\n",
       "    result = fn(*args, **kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\langchain\\embeddings\\openai.py", line 61, in _embed_with_retry\n",
       "    return embeddings.client.create(**kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_resources\\embedding.py", line 33, in create\n",
       "    response = super().create(*args, **kwargs)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_resources\\abstract\\engine_api_resource.py", line 153, in create\n",
       "    response, _, api_key = requestor.request(\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_requestor.py", line 230, in request\n",
       "    resp, got_stream = self._interpret_response(result, stream)\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_requestor.py", line 624, in _interpret_response\n",
       "    self._interpret_response_line(\n",
       "  File "C:\\Users\\RuKo601\\AppData\\Local\\anaconda3\\lib\\site-packages\\openai\\api_requestor.py", line 687, in _interpret_response_line\n",
       "    raise self.handle_error_response(\n",
       "openai.error.RateLimitError: You exceeded your current quota, please check your plan and billing details.\n",
       "
\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.holoviews_exec.v0+json": "", "text/html": [ "
\n", "
\n", "
\n", "" ], "text/plain": [ "Column(sizing_mode='stretch_width')\n", " [0] Markdown(str, sizing_mode='stretch_width')\n", " [1] Row(sizing_mode='stretch_width')\n", " [0] FileInput(width=300)\n", " [1] PasswordInput(placeholder='Enter your OpenAI A..., width=300)\n", " [2] WidgetBox(height=350, scroll=True, sizing_mode='fixed', width=600)\n", " [0] Markdown(str, sizing_mode='stretch_width')\n", " [1] ParamFunction(function, _pane=Column, loading_indicator=True, sizing_mode='stretch_width')\n", " [3] Row(width=600)\n", " [0] Column(margin=5, sizing_mode='stretch_width')\n", " [0] TextEditor(height=160, placeholder='Enter your questions h..., sizing_mode='stretch_width', toolbar=False)\n", " [1] Button(name='Run!', sizing_mode='stretch_width')\n", " [1] Card(margin=10, sizing_mode='stretch_width', title='Advanced settings')\n", " [0] Markdown(str, sizing_mode='stretch_width')\n", " [1] Column(sizing_mode='stretch_width')\n", " [0] RadioButtonGroup(name='Chain type', options=['stuff', 'map_reduce', ...], sizing_mode='stretch_width', value='stuff')\n", " [1] IntSlider(end=5, name='Number of relevant c..., sizing_mode='stretch_width', start=1, value=1)\n", " [2] FloatInput(end=1, name='Temperature', sizing_mode='stretch_width', start=0, step=0.01)\n", " [4] Button(name='Clear', sizing_mode='stretch_width')" ] }, "execution_count": 23, "metadata": { "application/vnd.holoviews_exec.v0+json": { "id": "1037" } }, "output_type": "execute_result" } ], "source": [ "# layout\n", "pn.Column(\n", " pn.pane.Markdown(\"\"\"\n", " ## \\U0001F60A! Question Answering with your PDF file\n", " \n", " 1) Upload a PDF 2) Enter OpenAI API key 3) Type a question and click \"Run\".\n", " \n", " \"\"\"),\n", " pn.Row(file_input,openaikey),\n", " output,\n", " widgets,clear_button\n", "\n", ").servable()" ] }, { "cell_type": "code", "execution_count": 41, "id": "e5701f5e", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 42, "id": "c39db914", "metadata": {}, "outputs": [], "source": [ "# print(clr_button.clicks)" ] }, { "cell_type": "code", "execution_count": 8, "id": "3fe5f821", "metadata": {}, "outputs": [], "source": [ "# openaikey.value" ] }, { "cell_type": "code", "execution_count": null, "id": "d6e8eab9", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.9" } }, "nbformat": 4, "nbformat_minor": 5 }