nivakaran commited on
Commit
7aa0011
·
verified ·
1 Parent(s): b1171f2

Upload 10 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ codebug.pdf filter=lfs diff=lfs merge=lfs -text
37
+ falcon_db/chroma.sqlite3 filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Use the official python 3.10 image
2
+ FROM python:3.10.9
3
+
4
+ ## Set the working directory to /code
5
+ WORKDIR /code
6
+
7
+ ## Copy the current directory contents into the container at /code
8
+ COPY ./requirements.txt /code/requirements.txt
9
+
10
+ ## Install the requirements.txt
11
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
12
+
13
+
14
+ # Set up a new user named "user"
15
+ RUN useradd user
16
+
17
+ # Switch to the "user" user
18
+ USER user
19
+
20
+
21
+ ENV HOME=/home/user \
22
+ PATH=/home/user/.local/bin:$PATH
23
+
24
+ # Set the working directory to the user's home directory
25
+ WORKDIR $HOME/app
26
+
27
+ # Copy the current directory contents into the container at the user's home directory
28
+ COPY --chown=user . $HOME/app
29
+
30
+ ## Start the FASTAPI App on port 7869
31
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ from pydantic import BaseModel
4
+ from langchain.chains import create_history_aware_retriever, create_retrieval_chain
5
+ from langchain.chains.combine_documents import create_stuff_documents_chain
6
+ from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
7
+ from langchain_groq import ChatGroq
8
+ from langchain_huggingface import HuggingFaceEmbeddings
9
+ from langchain_text_splitters import RecursiveCharacterTextSplitter
10
+ from langchain_community.document_loaders import PyPDFLoader
11
+ from langchain_chroma import Chroma
12
+ import os
13
+ import re
14
+ import firebase_admin
15
+ from firebase_admin import credentials, db
16
+ from datetime import datetime
17
+
18
+ # Firebase setup
19
+ cred = credentials.Certificate("falcon-86e9e-firebase-adminsdk-fbsvc-6f3352dc87.json")
20
+ firebase_admin.initialize_app(cred, {'databaseURL': 'https://falcon-86e9e-default-rtdb.firebaseio.com/'})
21
+
22
+ # Load environment variables
23
+ os.environ['HF_TOKEN'] = os.getenv("HF_TOKEN")
24
+ os.environ['GROQ_API_KEY'] = os.getenv("GROQ_API_KEY")
25
+
26
+ # Initialize FastAPI
27
+ app = FastAPI()
28
+
29
+ # CORS Middleware
30
+ app.add_middleware(
31
+ CORSMiddleware,
32
+ allow_origins=["*"],
33
+ allow_credentials=True,
34
+ allow_methods=["*"],
35
+ allow_headers=["*"],
36
+ )
37
+
38
+ # Initialize global embeddings and retriever
39
+ embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
40
+ llm = ChatGroq(model_name="Deepseek-R1-Distill-Llama-70b")
41
+ vectorstore = Chroma(persist_directory="./falcon_db", embedding_function=embeddings)
42
+ retriever = vectorstore.as_retriever()
43
+
44
+ # Session store (Only chat history, avoids large objects)
45
+ session_store = {}
46
+
47
+ # Request model
48
+ class QuestionRequest(BaseModel):
49
+ session_id: str
50
+ question: str
51
+
52
+ # Function extraction helper
53
+ def extract_function_call(answer):
54
+ match = re.search(r"<function>(\w+)\((.*?)\)</function>", answer)
55
+ if match:
56
+ function_name, params_str = match.groups()
57
+ params = dict(param.split("=") for param in params_str.split(","))
58
+ return function_name, {k.strip(): v.strip().strip('"') for k, v in params.items()}
59
+ return None, None
60
+
61
+ # Firebase meeting scheduler
62
+ def schedule_meeting(name: str, phoneNumber: str, availableTime: str, email: str, message: str):
63
+ meeting_details = {
64
+ 'name': name,
65
+ 'phoneNumber': phoneNumber,
66
+ 'availableTime': availableTime,
67
+ 'email': email,
68
+ 'message': message,
69
+ 'status': 'Scheduled',
70
+ 'timestamp': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
71
+ }
72
+ db.reference('meetings').push(meeting_details)
73
+ return f"Meeting scheduled at {availableTime}. Confirmation sent to {email} & {phoneNumber}."
74
+
75
+ FUNCTIONS = {"scheduleMeeting": schedule_meeting}
76
+
77
+ @app.post("/ask_question/")
78
+ async def ask_question(request: QuestionRequest):
79
+ session_id, question = request.session_id, request.question
80
+
81
+ # Use a shared retriever instead of per-session
82
+ history_aware_retriever = create_history_aware_retriever(llm, retriever, ChatPromptTemplate.from_messages([
83
+ ("system", "Rephrase user question into a standalone query."),
84
+ MessagesPlaceholder("chat_history"),
85
+ ("human", "{input}")
86
+ ]))
87
+
88
+ # System prompt optimization (removed redundancy)
89
+ qa_prompt = ChatPromptTemplate.from_messages([
90
+ ("system", (
91
+ "You are Falcon, an AI assistant developed by Codebug Technologies. "
92
+ "Answer questions concisely or call a function when needed.\n\n"
93
+ "Function Format: <function>FUNCTION_NAME(ARG1=VALUE1, ARG2=VALUE2)</function>\n\n"
94
+ "Use retrieved context:\n{context}"
95
+ )),
96
+ MessagesPlaceholder("chat_history"),
97
+ ("human", "{input}"),
98
+ ])
99
+
100
+ question_answer_chain = create_stuff_documents_chain(llm, qa_prompt)
101
+ rag_chain = create_retrieval_chain(history_aware_retriever, question_answer_chain)
102
+
103
+ # Store only chat history in session memory
104
+ if session_id not in session_store:
105
+ session_store[session_id] = {"history": []} # Store only message history
106
+
107
+ session_history = session_store[session_id]["history"]
108
+ last_messages = session_history[-10:] # Reduce stored messages
109
+
110
+ response = rag_chain.invoke(
111
+ {"input": question, "chat_history": last_messages},
112
+ config={"configurable": {"session_id": session_id}}
113
+ )
114
+
115
+ answer = response["answer"]
116
+ session_history.append({"role": "user", "content": question})
117
+ session_history.append({"role": "assistant", "content": answer})
118
+
119
+ # Function call execution
120
+ function_name, params = extract_function_call(answer)
121
+ if function_name and function_name in FUNCTIONS:
122
+ return {"answer": FUNCTIONS[function_name](**params)}
123
+
124
+ return {"answer": answer, "chat_history": last_messages}
codebug.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9fbf3eb5a7e0c3a5420fbd1112e43420138dbf1a2049774c30415c83cfe1ee02
3
+ size 3895736
falcon-86e9e-firebase-adminsdk-fbsvc-6f3352dc87.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "type": "service_account",
3
+ "project_id": "falcon-86e9e",
4
+ "private_key_id": "6f3352dc873de37ae9c9d75ac8e70339ad726973",
5
+ "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC/vSTiv2QB1uHf\n80BSGkqNCYt3Wm27CeGfVcNko2UFXv3yd4mYjat66TlzAO7z3DWROgQJviSO3IV9\njEfL9JTR++96h1DaX46DC4phe5uE3wTkcPqj32uyBunT1BWurrq5URzMfGmGQE58\nQWKT3zPM/iy6i2v8QHG59e0AXNFUKitc/4/yAs1YGEQaZ/drSig5UTA6VapepC/b\nbksHaqN21SqZdu5usC3nQsAnzua7rsmum3qVi8yY0AI1SEUK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MSvR/4c1EU38YY7ejk281rLU90fPq6xO95OXZYv4xD\nThs8Rc1O1BF8UIeywKua+g0SvOkpSrq5Uh4zekUCgYAz2YYZVleOUOJ/jJLZsBhF\nbKWK9qnSvpBmOL6eZJG/MEiKSNyw5azg/9Q4/r1oErhIWHb+oA70SHnzwhFj4oRw\nEAtJECEytkNlY069u8OYrkdfDhdR88fUznMFhVaFDIC2CxMjpmXN/SZ+SqsoJ81D\n4pYQv6L2E90tL8l8YiTGDA==\n-----END PRIVATE KEY-----\n",
6
+ "client_email": "firebase-adminsdk-fbsvc@falcon-86e9e.iam.gserviceaccount.com",
7
+ "client_id": "103712069535679525334",
8
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
9
+ "token_uri": "https://oauth2.googleapis.com/token",
10
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
11
+ "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-fbsvc%40falcon-86e9e.iam.gserviceaccount.com",
12
+ "universe_domain": "googleapis.com"
13
+ }
falcon_db/chroma.sqlite3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7db7cc4f059991a96e01ac64303c23cbaee7621e9947a2c563d32b5816fb30e2
3
+ size 315392
falcon_db/d647c821-3795-4f41-a46d-e2b9a858e73a/data_level0.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d3c9fd302f000d7790aa403c2d0d8fec363fe46f30b07d53020b6e33b22435a9
3
+ size 1676000
falcon_db/d647c821-3795-4f41-a46d-e2b9a858e73a/header.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e87a1dc8bcae6f2c4bea6d5dd5005454d4dace8637dae29bff3c037ea771411e
3
+ size 100
falcon_db/d647c821-3795-4f41-a46d-e2b9a858e73a/length.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:60f70c0fae47039c7965844a23420e5bc42afc04a516b8803d85b9c94b060f74
3
+ size 4000
falcon_db/d647c821-3795-4f41-a46d-e2b9a858e73a/link_lists.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
3
+ size 0
requirements.txt ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiohappyeyeballs==2.4.4
2
+ aiohttp==3.11.11
3
+ aiosignal==1.3.2
4
+ altair==5.5.0
5
+ annotated-types==0.7.0
6
+ anyio==4.8.0
7
+ arxiv==2.1.3
8
+ asgiref==3.8.1
9
+ asttokens==3.0.0
10
+ async-timeout==4.0.3
11
+ attrs==25.1.0
12
+ backoff==2.2.1
13
+ bcrypt==4.2.1
14
+ beautifulsoup4==4.12.3
15
+ blinker==1.9.0
16
+ bs4==0.0.2
17
+ build==1.2.2.post1
18
+ CacheControl==0.14.2
19
+ cachetools==5.5.1
20
+ certifi==2024.12.14
21
+ cffi==1.17.1
22
+ charset-normalizer==3.4.1
23
+ chroma-hnswlib==0.7.6
24
+ chromadb==0.6.3
25
+ click==8.1.8
26
+ colorama==0.4.6
27
+ coloredlogs==15.0.1
28
+ comm==0.2.2
29
+ cryptography==44.0.0
30
+ dataclasses-json==0.6.7
31
+ debugpy==1.8.12
32
+ decorator==5.1.1
33
+ Deprecated==1.2.18
34
+ distro==1.9.0
35
+ duckdb==1.1.3
36
+ durationpy==0.9
37
+ exceptiongroup==1.2.2
38
+ executing==2.2.0
39
+ faiss-cpu==1.9.0.post1
40
+ fastapi==0.115.7
41
+ feedparser==6.0.11
42
+ filelock==3.17.0
43
+ firebase-admin==6.6.0
44
+ flatbuffers==25.1.24
45
+ frozenlist==1.5.0
46
+ fsspec==2024.12.0
47
+ gitdb==4.0.12
48
+ GitPython==3.1.44
49
+ google-api-core==2.24.1
50
+ google-api-python-client==2.160.0
51
+ google-auth==2.38.0
52
+ google-auth-httplib2==0.2.0
53
+ google-cloud-core==2.4.1
54
+ google-cloud-firestore==2.20.0
55
+ google-cloud-storage==3.0.0
56
+ google-crc32c==1.6.0
57
+ google-resumable-media==2.7.2
58
+ googleapis-common-protos==1.66.0
59
+ greenlet==3.1.1
60
+ groq==0.15.0
61
+ grpcio==1.70.0
62
+ grpcio-status==1.70.0
63
+ h11==0.14.0
64
+ httpcore==1.0.7
65
+ httplib2==0.22.0
66
+ httptools==0.6.4
67
+ httpx==0.28.1
68
+ httpx-sse==0.4.0
69
+ huggingface-hub==0.28.0
70
+ humanfriendly==10.0
71
+ idna==3.10
72
+ importlib_metadata==8.5.0
73
+ importlib_resources==6.5.2
74
+ ipykernel==6.29.5
75
+ ipython==8.31.0
76
+ jedi==0.19.2
77
+ Jinja2==3.1.5
78
+ jiter==0.8.2
79
+ joblib==1.4.2
80
+ jsonpatch==1.33
81
+ jsonpointer==3.0.0
82
+ jsonschema==4.23.0
83
+ jsonschema-specifications==2024.10.1
84
+ jupyter_client==8.6.3
85
+ jupyter_core==5.7.2
86
+ kubernetes==32.0.0
87
+ langchain==0.3.16
88
+ langchain-chroma==0.2.1
89
+ langchain-community==0.3.16
90
+ langchain-core==0.3.32
91
+ langchain-groq==0.2.3
92
+ langchain-huggingface==0.1.2
93
+ langchain-openai==0.3.2
94
+ langchain-text-splitters==0.3.5
95
+ langsmith==0.3.2
96
+ markdown-it-py==3.0.0
97
+ MarkupSafe==3.0.2
98
+ marshmallow==3.26.0
99
+ matplotlib-inline==0.1.7
100
+ mdurl==0.1.2
101
+ mmh3==5.1.0
102
+ monotonic==1.6
103
+ mpmath==1.3.0
104
+ msgpack==1.1.0
105
+ multidict==6.1.0
106
+ mypy-extensions==1.0.0
107
+ narwhals==1.24.1
108
+ nest-asyncio==1.6.0
109
+ networkx==3.4.2
110
+ numpy==1.26.4
111
+ oauthlib==3.2.2
112
+ onnxruntime==1.20.1
113
+ openai==1.60.2
114
+ opentelemetry-api==1.29.0
115
+ opentelemetry-exporter-otlp-proto-common==1.29.0
116
+ opentelemetry-exporter-otlp-proto-grpc==1.29.0
117
+ opentelemetry-instrumentation==0.50b0
118
+ opentelemetry-instrumentation-asgi==0.50b0
119
+ opentelemetry-instrumentation-fastapi==0.50b0
120
+ opentelemetry-proto==1.29.0
121
+ opentelemetry-sdk==1.29.0
122
+ opentelemetry-semantic-conventions==0.50b0
123
+ opentelemetry-util-http==0.50b0
124
+ orjson==3.10.15
125
+ overrides==7.7.0
126
+ packaging==24.2
127
+ pandas==2.2.3
128
+ parso==0.8.4
129
+ pillow==11.1.0
130
+ platformdirs==4.3.6
131
+ posthog==3.11.0
132
+ prompt_toolkit==3.0.50
133
+ propcache==0.2.1
134
+ proto-plus==1.26.0
135
+ protobuf==5.29.3
136
+ psutil==6.1.1
137
+ pure_eval==0.2.3
138
+ pyarrow==19.0.0
139
+ pyasn1==0.6.1
140
+ pyasn1_modules==0.4.1
141
+ pycparser==2.22
142
+ pydantic==2.10.6
143
+ pydantic-settings==2.7.1
144
+ pydantic_core==2.27.2
145
+ pydeck==0.9.1
146
+ Pygments==2.19.1
147
+ PyJWT==2.10.1
148
+ PyMuPDF==1.25.2
149
+ pyparsing==3.2.1
150
+ pypdf==5.2.0
151
+ PyPika==0.48.9
152
+ pyproject_hooks==1.2.0
153
+ pyreadline3==3.5.4
154
+ python-dateutil==2.9.0.post0
155
+ python-dotenv==1.0.1
156
+ python-multipart==0.0.20
157
+ pytz==2024.2
158
+
159
+ PyYAML==6.0.2
160
+ pyzmq==26.2.0
161
+ referencing==0.36.2
162
+ regex==2024.11.6
163
+ requests==2.32.3
164
+ requests-oauthlib==2.0.0
165
+ requests-toolbelt==1.0.0
166
+ rich==13.9.4
167
+ rpds-py==0.22.3
168
+ rsa==4.9
169
+ safetensors==0.5.2
170
+ scikit-learn==1.6.1
171
+ scipy==1.15.1
172
+ sentence-transformers==3.4.0
173
+ sgmllib3k==1.0.0
174
+ shellingham==1.5.4
175
+ six==1.17.0
176
+ smmap==5.0.2
177
+ sniffio==1.3.1
178
+ soupsieve==2.6
179
+ SQLAlchemy==2.0.37
180
+ stack-data==0.6.3
181
+ starlette==0.45.3
182
+ streamlit==1.41.1
183
+ sympy==1.13.1
184
+ tenacity==9.0.0
185
+ threadpoolctl==3.5.0
186
+ tiktoken==0.8.0
187
+ tokenizers==0.21.0
188
+ toml==0.10.2
189
+ tomli==2.2.1
190
+ torch==2.5.1
191
+ tornado==6.4.2
192
+ tqdm==4.67.1
193
+ traitlets==5.14.3
194
+ transformers==4.48.1
195
+ typer==0.15.1
196
+ typing-inspect==0.9.0
197
+ typing_extensions==4.12.2
198
+ tzdata==2025.1
199
+ uritemplate==4.1.1
200
+ urllib3==2.3.0
201
+ uvicorn==0.34.0
202
+ watchdog==6.0.0
203
+ watchfiles==1.0.4
204
+ wcwidth==0.2.13
205
+ websocket-client==1.8.0
206
+ websockets==14.2
207
+ wikipedia==1.4.0
208
+ wrapt==1.17.2
209
+ yarl==1.18.3
210
+ zipp==3.21.0
211
+ zstandard==0.23.0