MarkChenX commited on
Commit
d903cfe
·
verified ·
1 Parent(s): d392c8d

Upload 12 files

Browse files
Dockerfile ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use an official fastapi runtime as a parent image
2
+ FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8
3
+
4
+ # Set the working directory in the container
5
+ WORKDIR /app
6
+
7
+ # Copy the current directory contents into the container at /app
8
+ COPY . /app
9
+
10
+ # Install any needed packages specified in requirements.txt
11
+ RUN pip install --trusted-host pypi.python.org -r requirements.txt
12
+
13
+ # Make port 80 available to the world outside this container
14
+ EXPOSE 80
15
+
16
+ # Run index.py when the container launches
17
+ CMD ["uvicorn", "index:app", "--port", "80", "--reload"]
README.md CHANGED
@@ -1,11 +1 @@
1
- ---
2
- title: Mindify Chat Api Demo
3
- emoji: 🦀
4
- colorFrom: gray
5
- colorTo: gray
6
- sdk: docker
7
- pinned: false
8
- license: mit
9
- ---
10
 
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
1
 
 
cura/__init__.py ADDED
File without changes
cura/github_ingestion.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ """
3
+ GitHub Repo File Ingestion and Indexing
4
+ """
5
+
6
+ from langchain_community.document_loaders.github import GithubFileLoader
7
+ from tqdm import tqdm
8
+
9
+ def ingest_github_repo(repo_name: str, access_token: str):
10
+ """
11
+ Ingests files from a GitHub repository and returns the files as a list of strings.
12
+
13
+ Args:
14
+ repo_name: str
15
+ The name of the GitHub repository in the format "username/repo_name".
16
+ access_token: str
17
+ The GitHub access token to access the repository.
18
+
19
+ Returns:
20
+ list
21
+ A list of strings containing the contents of the files in the repository.
22
+ """
23
+ loader = GithubFileLoader(
24
+ repo=repo_name,
25
+ access_token=access_token,
26
+ )
27
+
28
+ # List the directory contents for the repository
29
+ file_paths = loader.get_file_paths()
30
+
31
+ # Load the files from the repository using curl
32
+ files = []
33
+
34
+ print("Ingesting files from the repository...")
35
+ for i in tqdm(range(len(file_paths))):
36
+ try:
37
+ file = loader.get_file_content_by_path(file_paths[i]["path"])
38
+ # If the file is not textual file, skip it
39
+ if file is None:
40
+ continue
41
+ else:
42
+ files.append(file)
43
+ except:
44
+ continue
45
+
46
+ return files, file_paths
cura/openai_chat.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_openai import ChatOpenAI
2
+ import os
3
+
4
+ def ask_question(message: str) -> str:
5
+ llm = ChatOpenAI(
6
+ model="gpt-4o",
7
+ temperature=0,
8
+ max_tokens=None,
9
+ timeout=None,
10
+ max_retries=2,
11
+ api_key=os.getenv("OPENAI_API_KEY"),
12
+ # api_key="...", # if you prefer to pass api key in directly instaed of using env vars
13
+ # base_url="...",
14
+ # organization="...",
15
+ # other params...
16
+ )
17
+
18
+ try:
19
+ response = llm.invoke(message)
20
+ return response
21
+ except:
22
+ print("Error in openai_chat.py")
cura/vector_store.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ """
3
+ Vector Store for Mindify Chat
4
+ """
5
+
6
+ import chromadb
7
+
8
+ def set_up_chromadb(collection_name: str):
9
+ """
10
+ Set up a ChromaDB collection for storing vectors.
11
+
12
+ Args:
13
+ collection_name: str
14
+ The name of the collection to create or retrieve.
15
+
16
+ Returns:
17
+ ChromaDB Collection
18
+ The ChromaDB collection object.
19
+ """
20
+ chroma_client = chromadb.Client()
21
+
22
+ try:
23
+ # Check if the collection already exists
24
+ collection = chroma_client.get_collection(name=collection_name)
25
+ return collection
26
+ except:
27
+ # Create a new collection
28
+ collection = chroma_client.create_collection(name=collection_name)
29
+ return collection
30
+
31
+
32
+ def index_vector_store(collection_name:str, files: list):
33
+ """
34
+ Index the files in the ChromaDB collection.
35
+
36
+ Args:
37
+ collection: ChromaDB Collection
38
+ The collection to store the vectors in.
39
+ files: list
40
+ A list of strings containing the contents of the files.
41
+
42
+ Returns:
43
+ bool
44
+ True if the data is stored successfully, False otherwise.
45
+ """
46
+ # Set up collection
47
+ try:
48
+ collection = chromadb.Client().get_collection(name=collection_name)
49
+ except:
50
+ collection = chromadb.Client().create_collection(name=collection_name)
51
+
52
+ print("Indexing files...")
53
+ ids = []
54
+ for i in range(len(files[0])):
55
+ ids.append(str(i))
56
+
57
+ print("Storing GitHub data in ChromaDB...")
58
+ try:
59
+ collection.add(ids=ids, documents=files[0])
60
+ print("Data stored successfully!")
61
+
62
+ return True
63
+ except:
64
+ print("Error storing data in ChromaDB")
65
+ return False
66
+
67
+ def query_vector_store(collection_name: str, query: str):
68
+ """
69
+ Query the ChromaDB collection for similar vectors to the query vector.
70
+ """
71
+ print("Querying ChromaDB...")
72
+ try:
73
+ list_collection = chromadb.Client().list_collections()
74
+ print(list_collection)
75
+ collection = chromadb.Client().get_collection(name=collection_name)
76
+ return collection.query(query_texts=query, n_results=5)
77
+ except:
78
+ print("Error querying ChromaDB")
79
+ return None
cura_alpha.ipynb ADDED
@@ -0,0 +1,347 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 2,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "name": "stdout",
10
+ "output_type": "stream",
11
+ "text": [
12
+ "Ingesting GitHub data, please input the following information:\n",
13
+ "Ingesting GitHub data...\n",
14
+ "Ingesting files from the repository...\n"
15
+ ]
16
+ },
17
+ {
18
+ "name": "stderr",
19
+ "output_type": "stream",
20
+ "text": [
21
+ "100%|██████████| 75/75 [00:43<00:00, 1.73it/s]\n"
22
+ ]
23
+ }
24
+ ],
25
+ "source": [
26
+ "from cura import github_ingestion\n",
27
+ "from cura import vector_store\n",
28
+ "\n",
29
+ "print(\"Ingesting GitHub data, please input the following information:\")\n",
30
+ "url = \"MarkCodering/mindify-website\"\n",
31
+ "access_token = input(\"GitHub Access Token: \")\n",
32
+ "\n",
33
+ "print(\"Ingesting GitHub data...\")\n",
34
+ "github_repo_data = github_ingestion.ingest_github_repo(url, access_token)"
35
+ ]
36
+ },
37
+ {
38
+ "cell_type": "code",
39
+ "execution_count": 3,
40
+ "metadata": {},
41
+ "outputs": [
42
+ {
43
+ "name": "stdout",
44
+ "output_type": "stream",
45
+ "text": [
46
+ "Storing GitHub data in ChromaDB...\n"
47
+ ]
48
+ }
49
+ ],
50
+ "source": [
51
+ "collection_name = url.replace(\"/\", \"_\")\n",
52
+ "collection = vector_store.set_up_chromadb(collection_name)\n",
53
+ "ids = []\n",
54
+ "for i in range(len(github_repo_data[0])):\n",
55
+ " ids.append(str(i))\n",
56
+ " \n",
57
+ "print(\"Storing GitHub data in ChromaDB...\")\n",
58
+ "collection.add(ids=ids, documents=github_repo_data[0])"
59
+ ]
60
+ },
61
+ {
62
+ "cell_type": "code",
63
+ "execution_count": 4,
64
+ "metadata": {},
65
+ "outputs": [
66
+ {
67
+ "name": "stdout",
68
+ "output_type": "stream",
69
+ "text": [
70
+ "Querying the data from the vector store...\n",
71
+ "---\n",
72
+ "// @ts-ignore\n",
73
+ "const features = [\n",
74
+ " {\n",
75
+ " title: \"Learn AI Technologies\",\n",
76
+ " description:\n",
77
+ " \"We provide online and in-person training to help you learn the latest generative AI technologies.\",\n",
78
+ " },\n",
79
+ " {\n",
80
+ " title: \"Deploy AI Solutions\",\n",
81
+ " description:\n",
82
+ " \"We provide a platform for developers to deploy generative AI solutions in their projects.\",\n",
83
+ " },\n",
84
+ " {\n",
85
+ " title: \"Fast Prototyping and Concept Validation\",\n",
86
+ " description:\n",
87
+ " \"We help you quickly prototype and validate your AI concepts to bring them to market faster.\",\n",
88
+ " },\n",
89
+ "];\n",
90
+ "---\n",
91
+ "\n",
92
+ "<div class=\"mt-16 md:mt-0\">\n",
93
+ " <h2 class=\"text-4xl lg:text-5xl font-bold lg:tracking-tight text-center\">\n",
94
+ " About Mindify AI\n",
95
+ " </h2>\n",
96
+ " <p class=\"text-lg mt-4 text-slate-600\">\n",
97
+ " Mindify is an AI solution company that provides a platform for developers to\n",
98
+ " learn and deploy generative AI solutions. We deliver online and in-person\n",
99
+ " training to help you learn the latest AI technologies and deploy them in\n",
100
+ " your projects. Our mission is to help you bring your AI concepts to market\n",
101
+ " faster and deliver value to your customers.\n",
102
+ " </p>\n",
103
+ "</div>\n",
104
+ "\n",
105
+ "<div class=\"grid sm:grid-cols-2 md:grid-cols-3 mt-16 gap-16\">\n",
106
+ " {\n",
107
+ " features.map((item) => (\n",
108
+ " <div class=\"flex gap-4 items-start\">\n",
109
+ " <div>\n",
110
+ " <h3 class=\"font-semibold text-lg\">{item.title}</h3>{\" \"}\n",
111
+ " <p class=\"text-slate-500 mt-2 leading-relaxed\">{item.description}</p>\n",
112
+ " </div>\n",
113
+ " </div>\n",
114
+ " ))\n",
115
+ " }\n",
116
+ "</div>\n",
117
+ "\n"
118
+ ]
119
+ }
120
+ ],
121
+ "source": [
122
+ "# Query the data from the vector store\n",
123
+ "print(\"Querying the data from the vector store...\")\n",
124
+ "prompt = \"What is Mindify AI?\"\n",
125
+ "results = collection.query(\n",
126
+ " query_texts=[prompt], # Chroma will embed this for you\n",
127
+ " n_results=2 # how many results to return\n",
128
+ ")\n",
129
+ "print(results[\"documents\"][0][0])"
130
+ ]
131
+ },
132
+ {
133
+ "cell_type": "code",
134
+ "execution_count": 5,
135
+ "metadata": {},
136
+ "outputs": [
137
+ {
138
+ "name": "stdout",
139
+ "output_type": "stream",
140
+ "text": [
141
+ "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",
142
+ "// @ts-ignore\n",
143
+ "const features = [\n",
144
+ " {\n",
145
+ " title: \"Learn AI Technologies\",\n",
146
+ " description:\n",
147
+ " \"We provide online and in-person training to help you learn the latest generative AI technologies.\",\n",
148
+ " },\n",
149
+ " {\n",
150
+ " title: \"Deploy AI Solutions\",\n",
151
+ " description:\n",
152
+ " \"We provide a platform for developers to deploy generative AI solutions in their projects.\",\n",
153
+ " },\n",
154
+ " {\n",
155
+ " title: \"Fast Prototyping and Concept Validation\",\n",
156
+ " description:\n",
157
+ " \"We help you quickly prototype and validate your AI concepts to bring them to market faster.\",\n",
158
+ " },\n",
159
+ "];\n",
160
+ "---\n",
161
+ "\n",
162
+ "<div class=\"mt-16 md:mt-0\">\n",
163
+ " <h2 class=\"text-4xl lg:text-5xl font-bold lg:tracking-tight text-center\">\n",
164
+ " About Mindify AI\n",
165
+ " </h2>\n",
166
+ " <p class=\"text-lg mt-4 text-slate-600\">\n",
167
+ " Mindify is an AI solution company that provides a platform for developers to\n",
168
+ " learn and deploy generative AI solutions. We deliver online and in-person\n",
169
+ " training to help you learn the latest AI technologies and deploy them in\n",
170
+ " your projects. Our mission is to help you bring your AI concepts to market\n",
171
+ " faster and deliver value to your customers.\n",
172
+ " </p>\n",
173
+ "</div>\n",
174
+ "\n",
175
+ "<div class=\"grid sm:grid-cols-2 md:grid-cols-3 mt-16 gap-16\">\n",
176
+ " {\n",
177
+ " features.map((item) => (\n",
178
+ " <div class=\"flex gap-4 items-start\">\n",
179
+ " <div>\n",
180
+ " <h3 class=\"font-semibold text-lg\">{item.title}</h3>{\" \"}\n",
181
+ " <p class=\"text-slate-500 mt-2 leading-relaxed\">{item.description}</p>\n",
182
+ " </div>\n",
183
+ " </div>\n",
184
+ " ))\n",
185
+ " }\n",
186
+ "</div>\n",
187
+ "\n"
188
+ ]
189
+ },
190
+ {
191
+ "name": "stderr",
192
+ "output_type": "stream",
193
+ "text": [
194
+ "huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
195
+ "To disable this warning, you can either:\n",
196
+ "\t- Avoid using `tokenizers` before the fork if possible\n",
197
+ "\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n"
198
+ ]
199
+ }
200
+ ],
201
+ "source": [
202
+ "from cura import openai_chat\n",
203
+ "\n",
204
+ "question = (\n",
205
+ " \"You are a smart and helpful AI programmer and here is the repository I am working on: {}\".format(\n",
206
+ " url\n",
207
+ " )\n",
208
+ " + \"And, I wonder if you can help me with the following question with the following question: {}\".format(\n",
209
+ " prompt\n",
210
+ " )\n",
211
+ " + \"based on the data in the repository which is available here: {}\".format(\n",
212
+ " results[\"documents\"][0][0]\n",
213
+ " )\n",
214
+ ")\n",
215
+ "print(\"Asking OpenAI the following question: {}\".format(question))\n",
216
+ "\n",
217
+ "answer = openai_chat.ask_question(question)"
218
+ ]
219
+ },
220
+ {
221
+ "cell_type": "code",
222
+ "execution_count": 6,
223
+ "metadata": {},
224
+ "outputs": [
225
+ {
226
+ "name": "stdout",
227
+ "output_type": "stream",
228
+ "text": [
229
+ "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",
230
+ "\n",
231
+ "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",
232
+ "\n",
233
+ "2. **Deploying AI Solutions**: The platform allows developers to deploy generative AI solutions in their projects, facilitating the integration of advanced AI capabilities.\n",
234
+ "\n",
235
+ "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",
236
+ "\n",
237
+ "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",
238
+ "\n",
239
+ "Here is a summary of the features provided by Mindify AI:\n",
240
+ "- **Learn AI Technologies**: Training programs to learn the latest generative AI technologies.\n",
241
+ "- **Deploy AI Solutions**: A platform for deploying generative AI solutions in projects.\n",
242
+ "- **Fast Prototyping and Concept Validation**: Support for rapid prototyping and validation of AI concepts.\n",
243
+ "\n",
244
+ "Overall, Mindify AI aims to empower developers and businesses with the knowledge and tools needed to leverage generative AI effectively.\n"
245
+ ]
246
+ }
247
+ ],
248
+ "source": [
249
+ "print(answer.content)"
250
+ ]
251
+ },
252
+ {
253
+ "cell_type": "code",
254
+ "execution_count": 7,
255
+ "metadata": {},
256
+ "outputs": [
257
+ {
258
+ "name": "stderr",
259
+ "output_type": "stream",
260
+ "text": [
261
+ "/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",
262
+ " from .autonotebook import tqdm as notebook_tqdm\n"
263
+ ]
264
+ },
265
+ {
266
+ "name": "stdout",
267
+ "output_type": "stream",
268
+ "text": [
269
+ "Running on local URL: http://127.0.0.1:7860\n",
270
+ "\n",
271
+ "To create a public link, set `share=True` in `launch()`.\n"
272
+ ]
273
+ },
274
+ {
275
+ "data": {
276
+ "text/html": [
277
+ "<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>"
278
+ ],
279
+ "text/plain": [
280
+ "<IPython.core.display.HTML object>"
281
+ ]
282
+ },
283
+ "metadata": {},
284
+ "output_type": "display_data"
285
+ },
286
+ {
287
+ "data": {
288
+ "text/plain": []
289
+ },
290
+ "execution_count": 7,
291
+ "metadata": {},
292
+ "output_type": "execute_result"
293
+ }
294
+ ],
295
+ "source": [
296
+ "import gradio as gr\n",
297
+ "\n",
298
+ "def echo(question):\n",
299
+ " # Query the collection with the provided question\n",
300
+ " results = collection.query(\n",
301
+ " query_texts=[question], # Chroma will embed this for you\n",
302
+ " n_results=1 # Number of results to return\n",
303
+ " )\n",
304
+ " \n",
305
+ " # Append the retrieved document to the question\n",
306
+ " question = question + results[\"documents\"][0][0]\n",
307
+ " \n",
308
+ " # Use OpenAI's chat to ask the modified question\n",
309
+ " answer = openai_chat.ask_question(question)\n",
310
+ " \n",
311
+ " # Return the content of the answer\n",
312
+ " return answer.content\n",
313
+ "\n",
314
+ "# Define the Gradio interface\n",
315
+ "iface = gr.Interface(\n",
316
+ " fn=echo,\n",
317
+ " inputs=gr.Textbox(lines=2, placeholder=\"Enter your question here...\"),\n",
318
+ " outputs=gr.Code(label=\"Answer\", language=\"markdown\"),\n",
319
+ ")\n",
320
+ "\n",
321
+ "# Launch the Gradio interface\n",
322
+ "iface.launch()\n"
323
+ ]
324
+ }
325
+ ],
326
+ "metadata": {
327
+ "kernelspec": {
328
+ "display_name": "Python 3",
329
+ "language": "python",
330
+ "name": "python3"
331
+ },
332
+ "language_info": {
333
+ "codemirror_mode": {
334
+ "name": "ipython",
335
+ "version": 3
336
+ },
337
+ "file_extension": ".py",
338
+ "mimetype": "text/x-python",
339
+ "name": "python",
340
+ "nbconvert_exporter": "python",
341
+ "pygments_lexer": "ipython3",
342
+ "version": "3.9.6"
343
+ }
344
+ },
345
+ "nbformat": 4,
346
+ "nbformat_minor": 2
347
+ }
database/__init__.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ # Load load_dotenv to load the .env file
3
+ from dotenv import load_dotenv
4
+ from supabase import create_client, Client
5
+
6
+ load_dotenv()
7
+
8
+ url: str = os.environ.get("SUPABASE_URL")
9
+ key: str = os.environ.get("SUPABASE_KEY")
10
+ supabase: Client = create_client(url, key)
11
+
12
+ def get_supabase() -> Client:
13
+ return supabase
14
+
15
+ def post_github_access_token(token: str, user_emaill: str) -> None:
16
+ supabase.table("users_github_access_tokens").insert({"github_access_token": token, "user_email": user_emaill}).execute()
17
+
18
+ def get_github_access_token(user_email: str):
19
+ # Get the last access token
20
+ table_results = supabase.table("users_github_access_tokens").select("github_access_token").eq("user_email", user_email).execute()
21
+ # Access the data attribute of the response object
22
+ data = table_results.data
23
+
24
+ # Check if there are results and return the last token
25
+ if data:
26
+ return data[-1]['github_access_token']
27
+ else:
28
+ return None # or handle the case where there is no matching token
29
+
30
+ def post_github_repo(repo_name: str, user_email: str) -> None:
31
+ supabase.table("users_github_repos_name").insert({"repo_name": repo_name, "user_email": user_email}).execute()
32
+
33
+ def get_github_repos(user_email: str) -> list:
34
+ return supabase.table("users_github_repos_name").select("repo_name").eq("user_email", user_email).execute().get("data")
index.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from fastapi import FastAPI
3
+ from fastapi.middleware.cors import CORSMiddleware
4
+ from database import post_github_access_token, post_github_repo, get_github_access_token
5
+ from cura import github_ingestion, vector_store
6
+
7
+ app = FastAPI(
8
+ title="Mindify Chat API",
9
+ description="API for Mindify Chat",
10
+ version="0.1"
11
+ )
12
+
13
+ app.add_middleware(
14
+ CORSMiddleware,
15
+ allow_origins=["*"],
16
+ allow_credentials=True,
17
+ allow_methods=["*"],
18
+ allow_headers=["*"]
19
+ )
20
+
21
+ @app.get("/")
22
+ def read_root():
23
+ return {"Hello": "World"}
24
+
25
+ @app.post("/github/access_token")
26
+ def post_github_access_token_route(token: str, user_email: str):
27
+ post_github_access_token(token, user_email)
28
+ return {"status": "success"}
29
+
30
+ @app.post("/github/repo")
31
+ def post_github_repo_route(repo_name: str, user_email: str):
32
+ post_github_repo(repo_name, user_email)
33
+ return {"status": "success"}
34
+
35
+
36
+ @app.post("/github/index")
37
+ def index_github_repo_route(repo_name: str, user_email: str):
38
+ access_token = get_github_access_token(user_email)
39
+ collection_name = repo_name.replace("/", "_")
40
+ if access_token is not None:
41
+ files = github_ingestion.ingest_github_repo(repo_name, access_token)
42
+ results = vector_store.index_vector_store(files=files, collection_name = collection_name)
43
+ if results:
44
+ return {"status": "success", "message": "GitHub data stored in ChromaDB"}
45
+ else:
46
+ return {"status": "error", "message": "Failed to set up ChromaDB collection"}
47
+
48
+ else:
49
+ return {"status": "error", "message": "Failed to get GitHub access token"}
50
+
51
+ @app.post("/github/query")
52
+ def query_github_repo_route(repo_name: str, query: str):
53
+ collection_name = repo_name.replace("/", "_")
54
+ if collection_name is not None:
55
+ response = vector_store.query_vector_store(collection_name=collection_name, query=query)
56
+ return {"status": "success", "response": response}
57
+ else:
58
+ return {"status": "error", "message": "Failed to set up ChromaDB collection"}
59
+
60
+ if __name__ == "__main__":
61
+ import uvicorn
62
+ uvicorn.run(app)
langgraph_code_assistant.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ fastapi
2
+ langchain_community
3
+ langchain_openai
4
+ supabase
5
+ uvicorn
6
+ chromadb
test_index.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Unit tests for the index.py file
3
+ """
4
+
5
+ from fastapi.testclient import TestClient
6
+
7
+ from index import app
8
+
9
+ client = TestClient(app)
10
+
11
+ def test_read_root():
12
+ response = client.get("/")
13
+ assert response.status_code == 200
14
+ assert response.json() == {"Hello": "World"}
15
+
16
+ def test_post_github_access_token_route():
17
+ response = client.post("/github/access_token", json={"token": "test_token", "user_email": "test_email"})
18
+ assert response.status_code == 200
19
+
20
+ def test_post_github_repo_route():
21
+ response = client.post("/github/repo", json={"repo_name": "test_repo", "user_email": "test_email"})
22
+ assert response.status_code == 200
23
+
24
+ def test_index_github_repo_route():
25
+ response = client.post("/github/index", json={"repo_name": "test_repo", "user_email": "test_email"})
26
+ assert response.status_code == 200
27
+
28
+ def test_query_github_repo_route():
29
+ response = client.get("/github/query", json={"repo_name": "test_repo", "query": "test_query"})
30
+ assert response.status_code == 200
31
+