architojha commited on
Commit
dbde425
·
1 Parent(s): 4ba9dd1

pushing api

Browse files
Files changed (6) hide show
  1. Dockerfile +13 -0
  2. requirements.txt +10 -0
  3. routers/query/query.py +77 -0
  4. server.py +21 -0
  5. utils/LLMResponse.py +150 -0
  6. utils/ScrapeClass.py +42 -0
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ RUN useradd -m -u 1000 user
4
+ USER user
5
+ ENV PATH="/home/user/.local/bin:$PATH"
6
+
7
+ WORKDIR /app
8
+
9
+ COPY --chown=user ./requirements.txt requirements.txt
10
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
+
12
+ COPY --chown=user . /app
13
+ CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "7860"]
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ langchain-groq
2
+ fastapi
3
+ uvicorn
4
+ python-dotenv
5
+ pandas
6
+ tqdm
7
+ requests
8
+ bs4
9
+ lxml
10
+ chardet
routers/query/query.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import APIRouter
2
+ from pydantic import BaseModel
3
+ from langchain_groq import ChatGroq
4
+ from utils.LLMResponse import GenerateLLMResponse
5
+ from utils.ScrapeClass import ScrapeJobDetails
6
+ from dotenv import load_dotenv
7
+ import os
8
+
9
+ router = APIRouter(prefix='/query')
10
+ load_dotenv()
11
+
12
+ class RequestType(BaseModel):
13
+ resume: str
14
+ cover_letter: str
15
+ task: str
16
+ urls: list
17
+
18
+ global llm, instructions
19
+
20
+ @router.on_event('startup')
21
+ def _initialize():
22
+ api = os.getenv('groq_api_key')
23
+
24
+ global llm
25
+
26
+ llm = ChatGroq(groq_api_key=api,
27
+ model="llama-3.3-70b-versatile", temperature=0.3)
28
+
29
+ global instructions
30
+
31
+ instructions = '''
32
+ 0. **Adopt a conversational yet professional tone**: Write naturally as if you're explaining your interest and value to a hiring manager, avoiding overly formal or robotic language.
33
+
34
+ 1. **Start with a specific reference to the company**: Mention a project, product, or initiative that directly aligns with your skills or experience. Research the company's AI-related work and integrate it naturally into the response. Avoid generic statements like "I'm excited about your innovation."
35
+
36
+ 2. **Showcase your unique abilities and proven expertise**: Highlight your strongest abilities, previous experience, and measurable achievements that make you uniquely qualified for this role. Draw examples directly from your past work, such as specific tools (e.g., LLMs, RAG architectures) or accomplishments (e.g., "improved response accuracy by 25%").
37
+
38
+ 3. **Demonstrate clear value to the company**: Link your achievements and skills to the company’s goals or challenges. Instead of saying "I can make an impact," explain exactly how your expertise will solve their problems, improve processes, or drive innovation.
39
+
40
+ 4. **Provide measurable results with context**: Use one strong example with metrics to back up your claims (e.g., "I implemented a this at that that improved performance by this percent "). Avoid inventing metrics or offering vague claims.
41
+
42
+ 5. **Make every sentence count**: Remove repetition or filler. Each sentence should serve a clear purpose—whether it's showing value, demonstrating expertise, or connecting to the company's mission.
43
+
44
+ 6. **End with a confident, specific conclusion**: Reinforce how your unique skills will help the company succeed. Replace weak statements like "I’m excited to help" with clear, tailored contributions (e.g., "I’m eager to optimize your AI pipeline and drive measurable performance gains for your team").
45
+
46
+ 7. **Keep it concise and focused**: Limit the response to **100-150 words** while retaining clarity, specificity, and impact. Be enthusiastic but to the point.
47
+
48
+ 8. Replace metrics & results that are not mentioned in my resume & cover letter. Don't invent results. Only use values that are in resume & cover letter
49
+ '''
50
+
51
+ @router.post("/")
52
+ def _query(data: RequestType):
53
+
54
+ list_ = data.urls
55
+
56
+ object_ = ScrapeJobDetails(list_)
57
+ response_dict = object_._run()
58
+
59
+ lr = GenerateLLMResponse(llm)
60
+
61
+ resultList = {}
62
+
63
+ for url in list_:
64
+
65
+ context = lr._extract_relevant_details(
66
+ resume=data.resume, job_desc=response_dict[url]
67
+ )
68
+
69
+ custom_prompt = lr._buildPrompt(
70
+ context = context, cover_letter=data.cover_letter, jobData=response_dict[url], task=data.task)
71
+
72
+ final_response = lr._runInferenceLoop(
73
+ instruction=instructions, prompt=custom_prompt)
74
+
75
+ resultList[url] = final_response
76
+
77
+ return resultList
server.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, routing, Response
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ from routers.query.query import router as query_router
4
+
5
+ app = FastAPI()
6
+
7
+ app.add_middleware(
8
+ CORSMiddleware,
9
+ allow_origins=["*"],
10
+ allow_credentials=True,
11
+ allow_methods=["GET", "POST", "PUT", "DELETE"],
12
+ allow_headers=["*"],
13
+ )
14
+
15
+
16
+ app.include_router(query_router)
17
+
18
+ @app.get('/')
19
+ def _default_router():
20
+ return Response('Server is running!')
21
+
utils/LLMResponse.py ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from tqdm import tqdm
2
+
3
+ class GenerateLLMResponse:
4
+ def __init__(self, llm):
5
+
6
+ self.llm = llm
7
+
8
+ def _extract_relevant_details(self, resume: str, job_desc: str)->str:
9
+
10
+ prompt = f'''
11
+ You are an experienced & harsh employer thats extracts specific important aspects from the resume that is relevant to the job Details
12
+ You will be given text that contains multiple sentences. Only output the sentences that can be relevant to the job Details.
13
+
14
+ Use the following rules to judge if a particular sentence is important/ relevant to the job Details or not.
15
+
16
+ 1. Extract the sentence contains specific skills mentioned in the job Details.
17
+ 2. Extract sentences that reference specific tools, technologies, frameworks, or platforms that are mentioned in the job Details.
18
+ 3. Extract sentences that highlight measurable results and are highly relevant.
19
+ 4. Extract sentences that demonstrate experience with tasks or responsibilities similar to those listed in the job Details.
20
+ 5. Extract sentences that demonstrate problem-solving ability or direct impact on previous projects or companies.
21
+ 6. Extract sentences that demonstrate previous roles or positions that are similar to the job you are hiring for should be marked as relevant.
22
+
23
+ -Input Format-
24
+
25
+ Job Description: ""
26
+ Resume: ""
27
+
28
+ -Output Format-
29
+
30
+ "Relevant Sentence"
31
+ "Relevant Sentence"
32
+
33
+ -Instructions-
34
+
35
+ 1. Maintain the original meaning of the text, using proper grammar and vocabulary suitable for a general audience.
36
+ 2. Avoid changing the tone or intent of the original sentence.
37
+ 3. Preserve all escape sequences such as \\n (newlines) and \\t (tabs) in their exact positions in the text.
38
+ 4. Don't generate any sentence on your own. Only filter the relevant sentences from the resume
39
+ 5. Don't give results like "This skill is demonstrated in this..."
40
+ 6. Also do mention skills from the resume section
41
+
42
+ Dont give me any code and dont mention 'json' at the top of the response. There should not be any extra output (even a single word) besides the output required.
43
+
44
+ ######################
45
+ -Examples-
46
+ ######################
47
+
48
+ Job Details:
49
+
50
+ We are looking for a Senior AI Engineer with expertise in fine-tuning large language models (LLMs) and working with retrieval-augmented generation (RAG) architectures.
51
+ In this role, you will help enhance our existing AI systems by fine-tuning LLMs for specific use cases, integrating RAG architectures to improve model performance, and developing high-impact AI solutions.
52
+ Key Responsibilities:
53
+ Fine-tune large language models (LLMs) to improve performance on domain-specific tasks.
54
+ Design and implement RAG architectures to enhance retrieval-based AI systems.
55
+ Collaborate with cross-functional teams to identify AI-driven solutions for business challenges.
56
+ Optimize LLMs for both accuracy and efficiency, ensuring high-quality model output.
57
+ Conduct thorough testing and validation of fine-tuned models to ensure robustness and scalability.
58
+ Provide leadership and mentorship in AI model development and deployment processes.
59
+ Required Skills:
60
+ Proven experience in fine-tuning large language models (GPT, BERT, T5, etc.) for domain-specific tasks.
61
+ Deep understanding of retrieval-augmented generation (RAG) architectures and integration with LLMs.
62
+ Strong programming skills in Python, TensorFlow, PyTorch, and relevant AI libraries.
63
+ Experience in designing and deploying AI solutions at scale.
64
+ Knowledge of natural language processing (NLP) techniques and best practices.
65
+ Strong communication and collaboration skills.
66
+
67
+ Resume:
68
+
69
+
70
+ ################
71
+ Output:
72
+
73
+ "Led a project to fine-tune a large GPT-3 model for customer support, improving response accuracy by 20% compared to the previous version."
74
+ "Designed and implemented a retrieval-augmented generation (RAG) architecture to integrate external knowledge sources, enhancing the relevance and diversity of generated text."
75
+ "Optimized BERT for document classification tasks, increasing accuracy by 15% while reducing inference time by 25%."
76
+ "Collaborated with cross-functional teams to build and deploy an LLM-powered chatbot, improving customer satisfaction by 30% through personalized interactions."
77
+ "Implemented end-to-end pipelines for training and fine-tuning LLMs, including data preprocessing, model selection, and hyperparameter tuning."
78
+ "Integrated RAG techniques into a content generation system, reducing reliance on pre-trained models and improving the context relevance of generated responses."
79
+ "Developed scalable LLM fine-tuning strategies using TensorFlow and PyTorch, ensuring model performance on a range of NLP tasks."
80
+ "Evaluated model performance through rigorous testing and validation, ensuring robustness and alignment with business needs in a production environment."
81
+
82
+ #############################
83
+
84
+ -Real Data-
85
+ ######################
86
+ Job Details: {job_desc}
87
+ Resume: {resume}
88
+ ######################
89
+ Output:
90
+
91
+ '''
92
+
93
+ result = self._invoke(prompt)
94
+
95
+ return result
96
+
97
+ def _invoke(self, prompt: str)->str:
98
+
99
+ response = self.llm.invoke(prompt)
100
+
101
+ return response.content
102
+
103
+ def _buildPrompt(self, context: str, cover_letter: str, jobData: str, task: str)->str:
104
+
105
+ template = f'''
106
+
107
+ Instruction:
108
+
109
+ Think from the perspective of an employer. Your response must sound extremely natural and should not contain buzzwords.
110
+ Be direct & sound enthusiastic about the role. Don't give very general response.
111
+ Give answers that display my expertise for that particular topic
112
+
113
+ Only return the answer to the question and nothing else. In no circumstance will yoo return anything like "I made the following changes:..."
114
+
115
+
116
+ Details relevant to the job details:
117
+
118
+ {context}
119
+
120
+
121
+ My cover letter which contains my tech background:
122
+
123
+ {cover_letter}
124
+
125
+ Job data which includes about the job & requirements:
126
+
127
+ {jobData}
128
+
129
+ {task}
130
+
131
+ Only give me the final answer & don't give tell what changes did you make.
132
+
133
+ '''
134
+
135
+ return template
136
+
137
+ def _runInferenceLoop(self, instruction: str, prompt: str):
138
+
139
+
140
+ prompt = f'''
141
+
142
+ Prompt: {prompt}
143
+
144
+ Instruction: {instruction}
145
+ '''
146
+
147
+ result = self._invoke(prompt)
148
+
149
+ return result
150
+
utils/ScrapeClass.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from bs4 import BeautifulSoup
2
+ import requests
3
+
4
+ class ScrapeJobDetails:
5
+ def __init__(self, urls: list):
6
+
7
+ self.url_list = urls
8
+
9
+ def _fetchUrlData(self, url: str):
10
+
11
+ headers = {
12
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
13
+ 'Accept-Language': 'en-US,en;q=0.9',
14
+ }
15
+
16
+ return requests.get(url, headers=headers).text
17
+
18
+ def _parseHtml(self, html_content):
19
+
20
+ soup = BeautifulSoup(html_content, 'lxml')
21
+
22
+ tags_to_extract = ['p', 'li', 'ul']
23
+
24
+ extracted_text = []
25
+ for tag in tags_to_extract:
26
+ for element in soup.find_all(tag):
27
+ extracted_text.append(element.get_text(strip=True))
28
+
29
+ return "\n".join(extracted_text)
30
+
31
+
32
+ def _run(self):
33
+
34
+ result_dict = {}
35
+
36
+ for url in self.url_list:
37
+
38
+ html_data = self._fetchUrlData(url)
39
+
40
+ result_dict[url] = self._parseHtml(html_data)
41
+
42
+ return result_dict