embedchain

Форк
0
/
embedchain-docs-site-example.ipynb 
121 строка · 3.3 Кб
1
{
2
 "cells": [
3
  {
4
   "cell_type": "code",
5
   "execution_count": 1,
6
   "id": "e9a9dc6a",
7
   "metadata": {},
8
   "outputs": [],
9
   "source": [
10
    "from embedchain import App\n",
11
    "\n",
12
    "embedchain_docs_bot = App()"
13
   ]
14
  },
15
  {
16
   "cell_type": "code",
17
   "execution_count": 2,
18
   "id": "c1c24d68",
19
   "metadata": {},
20
   "outputs": [
21
    {
22
     "name": "stdout",
23
     "output_type": "stream",
24
     "text": [
25
      "All data from https://docs.embedchain.ai/ already exists in the database.\n"
26
     ]
27
    }
28
   ],
29
   "source": [
30
    "embedchain_docs_bot.add(\"docs_site\", \"https://docs.embedchain.ai/\")"
31
   ]
32
  },
33
  {
34
   "cell_type": "code",
35
   "execution_count": 3,
36
   "id": "48cdaecf",
37
   "metadata": {},
38
   "outputs": [],
39
   "source": [
40
    "answer = embedchain_docs_bot.query(\"Write a flask API for embedchain bot\")"
41
   ]
42
  },
43
  {
44
   "cell_type": "code",
45
   "execution_count": 4,
46
   "id": "0fe18085",
47
   "metadata": {},
48
   "outputs": [
49
    {
50
     "data": {
51
      "text/markdown": [
52
       "To write a Flask API for the embedchain bot, you can use the following code snippet:\n",
53
       "\n",
54
       "```python\n",
55
       "from flask import Flask, request, jsonify\n",
56
       "from embedchain import App\n",
57
       "\n",
58
       "app = Flask(__name__)\n",
59
       "bot = App()\n",
60
       "\n",
61
       "# Add datasets to the bot\n",
62
       "bot.add(\"youtube_video\", \"https://www.youtube.com/watch?v=3qHkcs3kG44\")\n",
63
       "bot.add(\"pdf_file\", \"https://navalmanack.s3.amazonaws.com/Eric-Jorgenson_The-Almanack-of-Naval-Ravikant_Final.pdf\")\n",
64
       "\n",
65
       "@app.route('/query', methods=['POST'])\n",
66
       "def query():\n",
67
       "    data = request.get_json()\n",
68
       "    question = data['question']\n",
69
       "    response = bot.query(question)\n",
70
       "    return jsonify({'response': response})\n",
71
       "\n",
72
       "if __name__ == '__main__':\n",
73
       "    app.run()\n",
74
       "```\n",
75
       "\n",
76
       "In this code, we create a Flask app and initialize an instance of the embedchain bot. We then add the desired datasets to the bot using the `add()` function.\n",
77
       "\n",
78
       "Next, we define a route `/query` that accepts POST requests. The request body should contain a JSON object with a `question` field. The bot's `query()` function is called with the provided question, and the response is returned as a JSON object.\n",
79
       "\n",
80
       "Finally, we run the Flask app using `app.run()`.\n",
81
       "\n",
82
       "Note: Make sure to install Flask and embedchain packages before running this code."
83
      ],
84
      "text/plain": [
85
       "<IPython.core.display.Markdown object>"
86
      ]
87
     },
88
     "metadata": {},
89
     "output_type": "display_data"
90
    }
91
   ],
92
   "source": [
93
    "from IPython.display import Markdown\n",
94
    "# Create a Markdown object and display it\n",
95
    "markdown_answer = Markdown(answer)\n",
96
    "display(markdown_answer)"
97
   ]
98
  }
99
 ],
100
 "metadata": {
101
  "kernelspec": {
102
   "display_name": "Python 3 (ipykernel)",
103
   "language": "python",
104
   "name": "python3"
105
  },
106
  "language_info": {
107
   "codemirror_mode": {
108
    "name": "ipython",
109
    "version": 3
110
   },
111
   "file_extension": ".py",
112
   "mimetype": "text/x-python",
113
   "name": "python",
114
   "nbconvert_exporter": "python",
115
   "pygments_lexer": "ipython3",
116
   "version": "3.11.4"
117
  }
118
 },
119
 "nbformat": 4,
120
 "nbformat_minor": 5
121
}
122

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.