File size: 12,414 Bytes
d903cfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ingesting GitHub data, please input the following information:\n",
      "Ingesting GitHub data...\n",
      "Ingesting files from the repository...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 75/75 [00:43<00:00,  1.73it/s]\n"
     ]
    }
   ],
   "source": [
    "from cura import github_ingestion\n",
    "from cura import vector_store\n",
    "\n",
    "print(\"Ingesting GitHub data, please input the following information:\")\n",
    "url = \"MarkCodering/mindify-website\"\n",
    "access_token = input(\"GitHub Access Token: \")\n",
    "\n",
    "print(\"Ingesting GitHub data...\")\n",
    "github_repo_data = github_ingestion.ingest_github_repo(url, access_token)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Storing GitHub data in ChromaDB...\n"
     ]
    }
   ],
   "source": [
    "collection_name = url.replace(\"/\", \"_\")\n",
    "collection = vector_store.set_up_chromadb(collection_name)\n",
    "ids = []\n",
    "for i in range(len(github_repo_data[0])):\n",
    "    ids.append(str(i))\n",
    "    \n",
    "print(\"Storing GitHub data in ChromaDB...\")\n",
    "collection.add(ids=ids, documents=github_repo_data[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Querying the data from the vector store...\n",
      "---\n",
      "// @ts-ignore\n",
      "const features = [\n",
      "  {\n",
      "    title: \"Learn AI Technologies\",\n",
      "    description:\n",
      "      \"We provide online and in-person training to help you learn the latest generative AI technologies.\",\n",
      "  },\n",
      "  {\n",
      "    title: \"Deploy AI Solutions\",\n",
      "    description:\n",
      "      \"We provide a platform for developers to deploy generative AI solutions in their projects.\",\n",
      "  },\n",
      "  {\n",
      "    title: \"Fast Prototyping and Concept Validation\",\n",
      "    description:\n",
      "      \"We help you quickly prototype and validate your AI concepts to bring them to market faster.\",\n",
      "  },\n",
      "];\n",
      "---\n",
      "\n",
      "<div class=\"mt-16 md:mt-0\">\n",
      "  <h2 class=\"text-4xl lg:text-5xl font-bold lg:tracking-tight text-center\">\n",
      "    About Mindify AI\n",
      "  </h2>\n",
      "  <p class=\"text-lg mt-4 text-slate-600\">\n",
      "    Mindify is an AI solution company that provides a platform for developers to\n",
      "    learn and deploy generative AI solutions. We deliver online and in-person\n",
      "    training to help you learn the latest AI technologies and deploy them in\n",
      "    your projects. Our mission is to help you bring your AI concepts to market\n",
      "    faster and deliver value to your customers.\n",
      "  </p>\n",
      "</div>\n",
      "\n",
      "<div class=\"grid sm:grid-cols-2 md:grid-cols-3 mt-16 gap-16\">\n",
      "  {\n",
      "    features.map((item) => (\n",
      "      <div class=\"flex gap-4 items-start\">\n",
      "        <div>\n",
      "          <h3 class=\"font-semibold text-lg\">{item.title}</h3>{\" \"}\n",
      "          <p class=\"text-slate-500 mt-2 leading-relaxed\">{item.description}</p>\n",
      "        </div>\n",
      "      </div>\n",
      "    ))\n",
      "  }\n",
      "</div>\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Query the data from the vector store\n",
    "print(\"Querying the data from the vector store...\")\n",
    "prompt = \"What is Mindify AI?\"\n",
    "results = collection.query(\n",
    "    query_texts=[prompt], # Chroma will embed this for you\n",
    "    n_results=2 # how many results to return\n",
    ")\n",
    "print(results[\"documents\"][0][0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Asking OpenAI the following question: You are a smart and helpful AI programmer and here is the repository I am working on: MarkCodering/mindify-websiteAnd, I wonder if you can help me with the following question with the following question: What is Mindify AI?based on the data in the repository which is available here: ---\n",
      "// @ts-ignore\n",
      "const features = [\n",
      "  {\n",
      "    title: \"Learn AI Technologies\",\n",
      "    description:\n",
      "      \"We provide online and in-person training to help you learn the latest generative AI technologies.\",\n",
      "  },\n",
      "  {\n",
      "    title: \"Deploy AI Solutions\",\n",
      "    description:\n",
      "      \"We provide a platform for developers to deploy generative AI solutions in their projects.\",\n",
      "  },\n",
      "  {\n",
      "    title: \"Fast Prototyping and Concept Validation\",\n",
      "    description:\n",
      "      \"We help you quickly prototype and validate your AI concepts to bring them to market faster.\",\n",
      "  },\n",
      "];\n",
      "---\n",
      "\n",
      "<div class=\"mt-16 md:mt-0\">\n",
      "  <h2 class=\"text-4xl lg:text-5xl font-bold lg:tracking-tight text-center\">\n",
      "    About Mindify AI\n",
      "  </h2>\n",
      "  <p class=\"text-lg mt-4 text-slate-600\">\n",
      "    Mindify is an AI solution company that provides a platform for developers to\n",
      "    learn and deploy generative AI solutions. We deliver online and in-person\n",
      "    training to help you learn the latest AI technologies and deploy them in\n",
      "    your projects. Our mission is to help you bring your AI concepts to market\n",
      "    faster and deliver value to your customers.\n",
      "  </p>\n",
      "</div>\n",
      "\n",
      "<div class=\"grid sm:grid-cols-2 md:grid-cols-3 mt-16 gap-16\">\n",
      "  {\n",
      "    features.map((item) => (\n",
      "      <div class=\"flex gap-4 items-start\">\n",
      "        <div>\n",
      "          <h3 class=\"font-semibold text-lg\">{item.title}</h3>{\" \"}\n",
      "          <p class=\"text-slate-500 mt-2 leading-relaxed\">{item.description}</p>\n",
      "        </div>\n",
      "      </div>\n",
      "    ))\n",
      "  }\n",
      "</div>\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
      "To disable this warning, you can either:\n",
      "\t- Avoid using `tokenizers` before the fork if possible\n",
      "\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n"
     ]
    }
   ],
   "source": [
    "from cura import openai_chat\n",
    "\n",
    "question = (\n",
    "    \"You are a smart and helpful AI programmer and here is the repository I am working on: {}\".format(\n",
    "        url\n",
    "    )\n",
    "    + \"And, I wonder if you can help me with the following question with the following question: {}\".format(\n",
    "        prompt\n",
    "    )\n",
    "    + \"based on the data in the repository which is available here: {}\".format(\n",
    "        results[\"documents\"][0][0]\n",
    "    )\n",
    ")\n",
    "print(\"Asking OpenAI the following question: {}\".format(question))\n",
    "\n",
    "answer = openai_chat.ask_question(question)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Based on the provided data from the repository, Mindify AI is an AI solution company that focuses on providing a platform for developers to learn and deploy generative AI solutions. Here are the key aspects of Mindify AI:\n",
      "\n",
      "1. **Learning AI Technologies**: Mindify AI offers both online and in-person training to help individuals and developers learn the latest generative AI technologies.\n",
      "\n",
      "2. **Deploying AI Solutions**: The platform allows developers to deploy generative AI solutions in their projects, facilitating the integration of advanced AI capabilities.\n",
      "\n",
      "3. **Fast Prototyping and Concept Validation**: Mindify AI assists in quickly prototyping and validating AI concepts, enabling faster time-to-market for AI-driven products and solutions.\n",
      "\n",
      "The mission of Mindify AI is to help developers and businesses bring their AI concepts to market more quickly and deliver value to their customers through advanced AI technologies.\n",
      "\n",
      "Here is a summary of the features provided by Mindify AI:\n",
      "- **Learn AI Technologies**: Training programs to learn the latest generative AI technologies.\n",
      "- **Deploy AI Solutions**: A platform for deploying generative AI solutions in projects.\n",
      "- **Fast Prototyping and Concept Validation**: Support for rapid prototyping and validation of AI concepts.\n",
      "\n",
      "Overall, Mindify AI aims to empower developers and businesses with the knowledge and tools needed to leverage generative AI effectively.\n"
     ]
    }
   ],
   "source": [
    "print(answer.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/mark/Documents/Mindify/CURA-alpha/.venv/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Running on local URL:  http://127.0.0.1:7860\n",
      "\n",
      "To create a public link, set `share=True` in `launch()`.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": []
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import gradio as gr\n",
    "\n",
    "def echo(question):\n",
    "    # Query the collection with the provided question\n",
    "    results = collection.query(\n",
    "        query_texts=[question],  # Chroma will embed this for you\n",
    "        n_results=1  # Number of results to return\n",
    "    )\n",
    "    \n",
    "    # Append the retrieved document to the question\n",
    "    question = question + results[\"documents\"][0][0]\n",
    "    \n",
    "    # Use OpenAI's chat to ask the modified question\n",
    "    answer = openai_chat.ask_question(question)\n",
    "    \n",
    "    # Return the content of the answer\n",
    "    return answer.content\n",
    "\n",
    "# Define the Gradio interface\n",
    "iface = gr.Interface(\n",
    "    fn=echo,\n",
    "    inputs=gr.Textbox(lines=2, placeholder=\"Enter your question here...\"),\n",
    "    outputs=gr.Code(label=\"Answer\", language=\"markdown\"),\n",
    ")\n",
    "\n",
    "# Launch the Gradio interface\n",
    "iface.launch()\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.9.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}