{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "4a6b2b70",
"metadata": {},
"outputs": [],
"source": [
"import gradio as gr\n",
"\n",
"from buster.chatbot import Chatbot, ChatbotConfig\n",
"\n",
"hf_transformers_cfg = ChatbotConfig(\n",
" documents_file=\"../data/document_embeddings_hf_transformers.tar.gz\",\n",
" unknown_prompt=\"This doesn't seem to be related to the huggingface library. I am not sure how to answer.\",\n",
" embedding_model=\"text-embedding-ada-002\",\n",
" top_k=3,\n",
" thresh=0.7,\n",
" max_chars=3000,\n",
" completion_kwargs={\n",
" \"engine\": \"text-davinci-003\",\n",
" \"max_tokens\": 500,\n",
" },\n",
" separator=\"
\",\n",
" link_format=\"markdown\",\n",
" text_after_response=\"I'm a bot 🤖 trained to answer huggingface 🤗 transformers questions. My answers aren't always perfect.\",\n",
" text_before_prompt=\"\"\"You are a slack chatbot assistant answering technical questions about huggingface transformers, a library to train transformers in python.\n",
" Make sure to format your answers in Markdown format, including code block and snippets.\n",
" Do not include any links to urls or hyperlinks in your answers.\n",
"\n",
" If you do not know the answer to a question, or if it is completely irrelevant to the library usage, simply reply with:\n",
"\n",
" 'This doesn't seem to be related to the huggingface library.'\n",
"\n",
" For example:\n",
"\n",
" What is the meaning of life for huggingface?\n",
"\n",
" This doesn't seem to be related to the huggingface library.\n",
"\n",
" Now answer the following question:\n",
" \"\"\",\n",
")\n",
"hf_transformers_chatbot = Chatbot(hf_transformers_cfg)\n",
"\n",
"def chat(question, history):\n",
" history = history or []\n",
" answer = hf_transformers_chatbot.process_input(question)\n",
"\n",
" history.append((question, answer))\n",
" print(history)\n",
" return history, history\n",
"\n",
"\n",
"\n",
"block = gr.Blocks(css=\".gradio-container {background-color: lightgray}\")\n",
"\n",
"with block:\n",
" with gr.Row():\n",
" gr.Markdown(\"