amartyasaran commited on
Commit
f98e472
·
verified ·
1 Parent(s): 0e7752d
app.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from main.main import agent
4
+
5
+ app = FastAPI()
6
+
7
+ class Message(BaseModel):
8
+ text: str
9
+
10
+ @app.post("/chatbot/")
11
+ async def chatbot(message: Message):
12
+ response = agent.chat(message.text)
13
+ return {"message": response}
14
+
15
+ # if __name__ == "_main_":
16
+ # import uvicorn
17
+ # uvicorn.run(app, host="127.0.0.1", port=8000)
dockerfile ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the official Python image from the Docker Hub
2
+ FROM python:3.11
3
+
4
+ # Set the working directory in the container
5
+ WORKDIR /code
6
+
7
+ # Copy the requirements file into the container at /app
8
+ COPY ./requirements.txt /code/requirements.txt
9
+
10
+ # Install any dependencies specified in requirements.txt
11
+ RUN pip install --no-cache-dir -r /code/requirements.txt
12
+
13
+ # Copy the current directory contents into the container at /app
14
+ COPY . .
15
+
16
+ # Command to run the FastAPI application
17
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from llama_index.core import SimpleDirectoryReader, get_response_synthesizer
2
+ from llama_index.core import DocumentSummaryIndex
3
+ from llama_index.llms.openai import OpenAI
4
+ from llama_index.core import load_index_from_storage
5
+ from llama_index.core import StorageContext, ServiceContext
6
+ from llama_index.core.tools import QueryEngineTool, ToolMetadata
7
+ from llama_index.vector_stores.faiss import FaissVectorStore
8
+ from llama_index.core.query_engine import SubQuestionQueryEngine
9
+ from llama_index.agent.openai import OpenAIAgent
10
+ import openai
11
+ import faiss
12
+ import os
13
+
14
+ import nest_asyncio
15
+ nest_asyncio.apply()
16
+
17
+ os.environ["OPENAI_API_KEY"] = "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"
18
+
19
+ vector_store = FaissVectorStore.from_persist_dir("./storage")
20
+ storage_context = StorageContext.from_defaults(vector_store=vector_store,persist_dir="./storage")
21
+ index = load_index_from_storage(storage_context)
22
+ individual_query_engine_tools = [
23
+ QueryEngineTool(
24
+ query_engine=index.as_query_engine(),
25
+ metadata=ToolMetadata(
26
+ name=f"timetable",
27
+ description=f"useful for when you want to answer queries",
28
+ ),
29
+ )
30
+ ]
31
+
32
+ query_engine = SubQuestionQueryEngine.from_defaults(
33
+ query_engine_tools=individual_query_engine_tools,
34
+ llm=OpenAI(model="gpt-3.5-turbo"),
35
+ )
36
+
37
+ query_engine_tool = QueryEngineTool(
38
+ query_engine=query_engine,
39
+ metadata=ToolMetadata(
40
+ name="sub_question_query_engine",
41
+ description="useful for when you want to answer queries",
42
+ ),
43
+ )
44
+
45
+ tools = individual_query_engine_tools + [query_engine_tool]
46
+
47
+ agent = OpenAIAgent.from_tools(tools)
48
+
49
+ # while True:
50
+ # text_input = input("User: ")
51
+ # if text_input == "exit":
52
+ # break
53
+ # response = agent.chat(text_input)
54
+ # print(f"Agent: {response}")
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ pydantic
4
+ openai
5
+ llama-index
6
+ llama-index-core
7
+ llama-index-agent-openai
8
+ llama-index-llms-openai
9
+ llama-index-vector-stores-faiss
storage/default__vector_store.json ADDED
Binary file (24.6 kB). View file
 
storage/docstore.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"docstore/metadata": {"5a3e34ff-3374-4100-9970-651ad1a27567": {"doc_hash": "641e8516b4ed9f95f2ab93fa6f0d3174e66770df68cafdba744c380d2364d709"}, "b26b2220-f5a1-415c-96a5-f86062400aef": {"doc_hash": "251ef6a8d162bc068793b3096151dea5bab245a6368fd67d62cdda8419a582bb"}, "ccd55557-6c30-48b7-b158-6142337735e8": {"doc_hash": "48a46c2d6d68bc47177e684b02d9e914d8ae0f08b85a13fe97b59b4d47fce23a", "ref_doc_id": "5a3e34ff-3374-4100-9970-651ad1a27567"}, "085ce5fc-d9f2-4d01-af86-eed6824a25a0": {"doc_hash": "d7feb0e229a474aa331b9bc17227f026bbd9798b432eee082aeb66452d357b02", "ref_doc_id": "5a3e34ff-3374-4100-9970-651ad1a27567"}, "06468808-ad4c-406c-8de7-4407a4173de6": {"doc_hash": "36b65eba4ab9b864ec932af207246c2340b381b4aed9e9829698c49ef47f9a81", "ref_doc_id": "b26b2220-f5a1-415c-96a5-f86062400aef"}, "a005679a-636b-403e-9bfc-80f499216f44": {"doc_hash": "ebea3ea6d246850c8324e852d1f0a0db5abd00d8f9bade4dbc21c4959bdc63dc", "ref_doc_id": "b26b2220-f5a1-415c-96a5-f86062400aef"}}, "docstore/data": {"ccd55557-6c30-48b7-b158-6142337735e8": {"__data__": {"id_": "ccd55557-6c30-48b7-b158-6142337735e8", "embedding": null, "metadata": {"name": "Abhimanyu", "designation": "Assistant Professor", "department": "Computer Science and Engineering", "L-T-P": "7-0-6"}, "excluded_embed_metadata_keys": [], "excluded_llm_metadata_keys": [], "relationships": {"1": {"node_id": "5a3e34ff-3374-4100-9970-651ad1a27567", "node_type": "4", "metadata": {"name": "Abhimanyu", "designation": "Assistant Professor", "department": "Computer Science and Engineering", "L-T-P": "7-0-6"}, "hash": "641e8516b4ed9f95f2ab93fa6f0d3174e66770df68cafdba744c380d2364d709", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "085ce5fc-d9f2-4d01-af86-eed6824a25a0", "node_type": "1", "metadata": {}, "hash": "a402c82b9587ad370e75579d5ce196c03049e1b68c4c1bcb3740d4525c02e137", "class_name": "RelatedNodeInfo"}}, "text": "{'Monday': {'8:30-9:25': 'No Class', '9:30-10:25': 'No Class', '10:40-11:35': 'CSET105: B4,(P): Dr. Abhimanyu bar {203 B-LA}', '11:40-12:35': 'CSET105: B4,(P): Dr. Abhimanyu bar {203 B-LA}', '12:40-1:30': 'Break', '13:30-14:25': 'CSET105: G2,(L): Dr. Abhimanyu bar {102-N-LH(240)}', '14:30-15:25': 'No Class', '15:40-16:35': 'No Class', '16:40-17:35': 'CSET105: G4,(L): Dr. Abhimanyu bar {102-N-LH(240)}', '17:40-18:35': 'No Class'}, 'Tuesday': {'8:30-9:25': 'No Class', '9:30-10:25': 'No Class', '10:40-11:35': 'No Class', '11:40-12:35': 'No Class', '12:40-1:30': 'Break', '13:30-14:25': 'No Class', '14:30-15:25': 'No Class', '15:40-16:35': 'No Class', '16:40-17:35': 'No Class', '17:40-18:35': 'No Class'}, 'Wednesday': {'8:30-9:25': 'No Class', '9:30-10:25': 'No Class', '10:40-11:35': 'No Class', '11:40-12:35': 'No Class', '12:40-1:30': 'Break', '13:30-14:25': 'No Class', '14:30-15:25': 'CSET105: G2,(L): Dr. Abhimanyu bar {102-N-LH(240)}', '15:40-16:35': 'CSET105: G4,(L): Dr. Abhimanyu bar {102-N-LH(240)}', '16:40-17:35': 'No Class', '17:40-18:35': 'CSET306-UG-Research: ALL-L,(L): Dr. Abhimanyu bar {Online}'}, 'Thursday': {'8:30-9:25': 'CSET105: B15,(P): Dr. Abhimanyu bar {206 B-LA}', '9:30-10:25': 'CSET105: B15,(P): Dr. Abhimanyu bar {206 B-LA}', '10:40-11:35': 'No Class', '11:40-12:35': 'No Class', '12:40-1:30': 'Break', '13:30-14:25': 'CSET105: G2,(L): Dr. Abhimanyu bar {102-N-LH(240)}', '14:30-15:25': 'No Class', '15:40-16:35': 'CSET105: G4,(L): Dr. Abhimanyu bar {103-N-LH(240)}', '16:40-17:35': 'No Class', '17:40-18:35': 'No Class'}, 'Friday': {'8:30-9:25': 'No Class', '9:30-10:25': 'No Class', '10:40-11:35': 'No Class', '11:40-12:35': 'No Class', '12:40-1:30': 'Break', '13:30-14:25': 'No Class', '14:30-15:25': 'No Class', '15:40-16:35': 'CSET105: B56,(P): Dr. Abhimanyu bar {207 B-LA}', '16:40-17:35': 'CSET105: B56,(P): Dr.", "start_char_idx": 0, "end_char_idx": 1854, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}, "__type__": "1"}, "085ce5fc-d9f2-4d01-af86-eed6824a25a0": {"__data__": {"id_": "085ce5fc-d9f2-4d01-af86-eed6824a25a0", "embedding": null, "metadata": {"name": "Abhimanyu", "designation": "Assistant Professor", "department": "Computer Science and Engineering", "L-T-P": "7-0-6"}, "excluded_embed_metadata_keys": [], "excluded_llm_metadata_keys": [], "relationships": {"1": {"node_id": "5a3e34ff-3374-4100-9970-651ad1a27567", "node_type": "4", "metadata": {"name": "Abhimanyu", "designation": "Assistant Professor", "department": "Computer Science and Engineering", "L-T-P": "7-0-6"}, "hash": "641e8516b4ed9f95f2ab93fa6f0d3174e66770df68cafdba744c380d2364d709", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "ccd55557-6c30-48b7-b158-6142337735e8", "node_type": "1", "metadata": {"name": "Abhimanyu", "designation": "Assistant Professor", "department": "Computer Science and Engineering", "L-T-P": "7-0-6"}, "hash": "48a46c2d6d68bc47177e684b02d9e914d8ae0f08b85a13fe97b59b4d47fce23a", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "06468808-ad4c-406c-8de7-4407a4173de6", "node_type": "1", "metadata": {}, "hash": "780a4974b601786d60b0735c61b160712fd638cab0f9d3e12cca99510ef00f0e", "class_name": "RelatedNodeInfo"}}, "text": "Abhimanyu bar {103-N-LH(240)}', '16:40-17:35': 'No Class', '17:40-18:35': 'No Class'}, 'Friday': {'8:30-9:25': 'No Class', '9:30-10:25': 'No Class', '10:40-11:35': 'No Class', '11:40-12:35': 'No Class', '12:40-1:30': 'Break', '13:30-14:25': 'No Class', '14:30-15:25': 'No Class', '15:40-16:35': 'CSET105: B56,(P): Dr. Abhimanyu bar {207 B-LA}', '16:40-17:35': 'CSET105: B56,(P): Dr. Abhimanyu bar {207 B-LA}', '17:40-18:35': 'No Class'}, 'Saturday': {'8:30-9:25': 'No Class', '9:30-10:25': 'No Class', '10:40-11:35': 'No Class', '11:40-12:35': 'No Class', '12:40-1:30': 'Break', '13:30-14:25': 'No Class', '14:30-15:25': 'No Class', '15:40-16:35': 'No Class', '16:40-17:35': 'No Class', '17:40-18:35': 'No Class'}}", "start_char_idx": 1472, "end_char_idx": 2186, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}, "__type__": "1"}, "06468808-ad4c-406c-8de7-4407a4173de6": {"__data__": {"id_": "06468808-ad4c-406c-8de7-4407a4173de6", "embedding": null, "metadata": {"name": "Amit Tomar", "designation": "Assistant Professor", "department": "Computer Science & Engineering", "L-T-P": "7-0-6"}, "excluded_embed_metadata_keys": [], "excluded_llm_metadata_keys": [], "relationships": {"1": {"node_id": "b26b2220-f5a1-415c-96a5-f86062400aef", "node_type": "4", "metadata": {"name": "Amit Tomar", "designation": "Assistant Professor", "department": "Computer Science & Engineering", "L-T-P": "7-0-6"}, "hash": "251ef6a8d162bc068793b3096151dea5bab245a6368fd67d62cdda8419a582bb", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "085ce5fc-d9f2-4d01-af86-eed6824a25a0", "node_type": "1", "metadata": {"name": "Abhimanyu", "designation": "Assistant Professor", "department": "Computer Science and Engineering", "L-T-P": "7-0-6"}, "hash": "d7feb0e229a474aa331b9bc17227f026bbd9798b432eee082aeb66452d357b02", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "a005679a-636b-403e-9bfc-80f499216f44", "node_type": "1", "metadata": {}, "hash": "b273dbbaa77e2482d5d3f11d17492a154b310bbf0356a270daaedb9d7ff8eabc", "class_name": "RelatedNodeInfo"}}, "text": "{'Monday': {'8:30-9:25': 'No Class', '9:30-10:25': 'CSET106: G5,(L): Dr. Amit Tomar {103-N-LH(240)}', '10:40-11:35': 'No Class', '11:40-12:35': 'No Class', '12:40-1:30': 'Break', '13:30-14:25': 'No Class', '14:30-15:25': 'CSET106: B41,B42,(T): Dr. Amit Tomar {115-N-CA(60)}', '15:40-16:35': 'No Class', '16:40-17:35': 'No Class', '17:40-18:35': 'No Class'}, 'Tuesday': {'8:30-9:25': 'No Class', '9:30-10:25': 'No Class', '10:40-11:35': 'CSET106: B5,B6,(T): Dr. Amit Tomar {306-B-CA(60)}', '11:40-12:35': 'No Class', '12:40-1:30': 'CSET106: G9,(L): Dr. Amit Tomar {104-N-LH(240)}', '13:30-14:25': 'No Class', '14:30-15:25': 'No Class', '15:40-16:35': 'No Class', '16:40-17:35': 'No Class', '17:40-18:35': 'No Class'}, 'Wednesday': {'8:30-9:25': 'CSET106: G9,(L): Dr. Amit Tomar {104-N-LH(240)}', '9:30-10:25': 'No Class', '10:40-11:35': 'CSET106: G5,(L): Dr. Amit Tomar {103-N-LH(240)}', '11:40-12:35': 'No Class', '12:40-1:30': 'Break', '13:30-14:25': 'CSET106: B37,B38,(T): Dr. Amit Tomar {127-N-CA(60)}', '14:30-15:25': 'No Class', '15:40-16:35': 'No Class', '16:40-17:35': 'No Class', '17:40-18:35': 'CSET306-UG-Research: ALL-L,(L): Dr. Amit Tomar {Online}'}, 'Thursday': {'8:30-9:25': 'No Class', '9:30-10:25': 'No Class', '10:40-11:35': 'No Class', '11:40-12:35': 'No Class', '12:40-1:30': 'Break', '13:30-14:25': 'No Class', '14:30-15:25': 'No Class', '15:40-16:35': 'No Class', '16:40-17:35': 'No Class', '17:40-18:35': 'No Class'}, 'Friday': {'8:30-9:25': 'CSET106: B55,B56,(T): Dr. Amit Tomar {216-N-CA(60)}', '9:30-10:25': 'CSET106: G9,(L): Dr. Amit Tomar {102-B-LH(150)}', '10:40-11:35': 'No Class', '11:40-12:35': 'CSET106: G5,(L): Dr. Amit Tomar {101-N-LH(240)}', '12:40-1:30': 'Break', '13:30-14:25': 'No Class', '14:30-15:25': 'CSET106: B67,B68,(T): Dr.", "start_char_idx": 0, "end_char_idx": 1768, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}, "__type__": "1"}, "a005679a-636b-403e-9bfc-80f499216f44": {"__data__": {"id_": "a005679a-636b-403e-9bfc-80f499216f44", "embedding": null, "metadata": {"name": "Amit Tomar", "designation": "Assistant Professor", "department": "Computer Science & Engineering", "L-T-P": "7-0-6"}, "excluded_embed_metadata_keys": [], "excluded_llm_metadata_keys": [], "relationships": {"1": {"node_id": "b26b2220-f5a1-415c-96a5-f86062400aef", "node_type": "4", "metadata": {"name": "Amit Tomar", "designation": "Assistant Professor", "department": "Computer Science & Engineering", "L-T-P": "7-0-6"}, "hash": "251ef6a8d162bc068793b3096151dea5bab245a6368fd67d62cdda8419a582bb", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "06468808-ad4c-406c-8de7-4407a4173de6", "node_type": "1", "metadata": {"name": "Amit Tomar", "designation": "Assistant Professor", "department": "Computer Science & Engineering", "L-T-P": "7-0-6"}, "hash": "36b65eba4ab9b864ec932af207246c2340b381b4aed9e9829698c49ef47f9a81", "class_name": "RelatedNodeInfo"}}, "text": "Amit Tomar {216-N-CA(60)}', '9:30-10:25': 'CSET106: G9,(L): Dr. Amit Tomar {102-B-LH(150)}', '10:40-11:35': 'No Class', '11:40-12:35': 'CSET106: G5,(L): Dr. Amit Tomar {101-N-LH(240)}', '12:40-1:30': 'Break', '13:30-14:25': 'No Class', '14:30-15:25': 'CSET106: B67,B68,(T): Dr. Amit Tomar {128-N-CA(60)}', '15:40-16:35': 'No Class', '16:40-17:35': 'No Class', '17:40-18:35': 'No Class'}, 'Saturday': {'8:30-9:25': 'No Class', '9:30-10:25': 'No Class', '10:40-11:35': 'No Class', '11:40-12:35': 'No Class', '12:40-1:30': 'Break', '13:30-14:25': 'No Class', '14:30-15:25': 'No Class', '15:40-16:35': 'No Class', '16:40-17:35': 'No Class', '17:40-18:35': 'No Class'}}", "start_char_idx": 1491, "end_char_idx": 2155, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}, "__type__": "1"}}, "docstore/ref_doc_info": {"5a3e34ff-3374-4100-9970-651ad1a27567": {"node_ids": ["ccd55557-6c30-48b7-b158-6142337735e8", "085ce5fc-d9f2-4d01-af86-eed6824a25a0"], "metadata": {"name": "Abhimanyu", "designation": "Assistant Professor", "department": "Computer Science and Engineering", "L-T-P": "7-0-6"}}, "b26b2220-f5a1-415c-96a5-f86062400aef": {"node_ids": ["06468808-ad4c-406c-8de7-4407a4173de6", "a005679a-636b-403e-9bfc-80f499216f44"], "metadata": {"name": "Amit Tomar", "designation": "Assistant Professor", "department": "Computer Science & Engineering", "L-T-P": "7-0-6"}}}}
storage/graph_store.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"graph_dict": {}}
storage/image__vector_store.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"embedding_dict": {}, "text_id_to_ref_doc_id": {}, "metadata_dict": {}}
storage/index_store.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"index_store/data": {"664db5f0-8bf7-41e6-8e48-886a40f0d274": {"__type__": "vector_store", "__data__": "{\"index_id\": \"664db5f0-8bf7-41e6-8e48-886a40f0d274\", \"summary\": null, \"nodes_dict\": {\"0\": \"ccd55557-6c30-48b7-b158-6142337735e8\", \"1\": \"085ce5fc-d9f2-4d01-af86-eed6824a25a0\", \"2\": \"06468808-ad4c-406c-8de7-4407a4173de6\", \"3\": \"a005679a-636b-403e-9bfc-80f499216f44\"}, \"doc_id_dict\": {}, \"embeddings_dict\": {}}"}}}