AakashJammula commited on
Commit
09a5fd9
·
1 Parent(s): ed0d437
Files changed (7) hide show
  1. .gitignore +181 -0
  2. .python-version +1 -0
  3. app.py +49 -0
  4. pyproject.toml +18 -0
  5. rag.py +28 -0
  6. requirements.txt +9 -1
  7. uv.lock +0 -0
.gitignore ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # Ruff stuff:
171
+ .ruff_cache/
172
+
173
+ # PyPI configuration file
174
+ .pypirc
175
+
176
+ # Cursor
177
+ # Cursor is an AI-powered code editor.`.cursorignore` specifies files/directories to
178
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
179
+ # refer to https://docs.cursor.com/context/ignore-files
180
+ .cursorignore
181
+ .cursorindexingignore
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.11
app.py CHANGED
@@ -1,6 +1,55 @@
1
  from fastapi import FastAPI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  app = FastAPI()
 
 
 
 
 
 
3
 
4
  @app.get("/")
5
  def read_root():
6
  return {"hello": "world"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from fastapi import FastAPI
2
+ from langchain_core.prompts import PromptTemplate
3
+ from langchain_google_genai import ChatGoogleGenerativeAI
4
+ from langchain_core.messages import HumanMessage
5
+ import os
6
+ from fastapi import FastAPI, HTTPException
7
+ from fastapi.middleware.cors import CORSMiddleware
8
+ from pydantic import BaseModel
9
+ from typing import List, Optional
10
+ from rag import retrieve_context
11
+ # RAG LLM setup
12
+ llm_rag = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0.5)
13
+
14
+ prompt = PromptTemplate.from_template(
15
+ "you are rag bot designed to answer questions on aakash jammula "
16
+ "(document contains my information/resume) and be engaging and only respond in text "
17
+ "like a human. Use context only when they ask about me (aakash jammula).\n\n"
18
+ "Context:\n{context}\n\nQuestion:\n{question}\nAnswer:"
19
+ )
20
+
21
+
22
  app = FastAPI()
23
+ app.add_middleware(
24
+ CORSMiddleware,
25
+ allow_origins=["*"],
26
+ allow_methods=["*"],
27
+ allow_headers=["*"],
28
+ )
29
 
30
  @app.get("/")
31
  def read_root():
32
  return {"hello": "world"}
33
+
34
+
35
+
36
+ class Query(BaseModel):
37
+ q: str
38
+ k: int = 5
39
+
40
+ @app.post("/ask")
41
+ async def ask(req: Query):
42
+ if not req.q:
43
+ raise HTTPException(status_code=400, detail="Missing question text")
44
+ context = retrieve_context(req.q, k=req.k)
45
+ user_prompt = prompt.invoke({"context": context, "question": req.q})
46
+ resp = llm_rag.invoke(user_prompt)
47
+ return {"context": context, "answer": resp.content}
48
+
49
+ if __name__ == "__main__":
50
+ import uvicorn
51
+ uvicorn.run(
52
+ app,
53
+ host="0.0.0.0",
54
+ port=int(os.getenv("PORT", 5000))
55
+ )
pyproject.toml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "backend-port"
3
+ version = "0.1.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ dependencies = [
8
+ "fastapi>=0.115.12",
9
+ "hf-xet>=1.1.2",
10
+ "langchain-core>=0.3.60",
11
+ "langchain-google-genai>=2.1.4",
12
+ "langchain-huggingface>=0.2.0",
13
+ "langchain-pinecone>=0.2.6",
14
+ "pinecone>=6.0.2",
15
+ "python-dotenv>=1.1.0",
16
+ "python-multipart>=0.0.20",
17
+ "uvicorn>=0.34.2",
18
+ ]
rag.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # rag.py
2
+ import os
3
+ from dotenv import load_dotenv
4
+ from pinecone import Pinecone, ServerlessSpec
5
+ from langchain_huggingface import HuggingFaceEmbeddings
6
+ from langchain_pinecone import PineconeVectorStore
7
+
8
+ load_dotenv()
9
+
10
+ # Initialize Pinecone
11
+ pc = Pinecone(api_key=os.getenv("PINECONE_API_KEY"))
12
+ index_name = "resume-index"
13
+ if not pc.has_index(index_name):
14
+ pc.create_index(
15
+ name=index_name,
16
+ dimension=384,
17
+ metric="cosine",
18
+ spec=ServerlessSpec(cloud="aws", region="us-east-1"),
19
+ )
20
+ pinecone_index = pc.Index(index_name)
21
+
22
+ # Embeddings + VectorStore
23
+ embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
24
+ vectorstore = PineconeVectorStore(index=pinecone_index, embedding=embeddings)
25
+
26
+ def retrieve_context(question: str, k: int = 5) -> str:
27
+ docs = vectorstore.similarity_search(question, k=k)
28
+ return "\n\n".join(d.page_content for d in docs)
requirements.txt CHANGED
@@ -1,2 +1,10 @@
1
  uvicorn
2
- fastapi
 
 
 
 
 
 
 
 
 
1
  uvicorn
2
+ fastapi
3
+ python-dotenv
4
+ pinecone
5
+ langchain_huggingface
6
+ langchain_pinecone
7
+ langchain_google_genai
8
+ python-multipart
9
+ langchain-core
10
+ hf_xet
uv.lock ADDED
The diff for this file is too large to render. See raw diff