Spaces:
Sleeping
Sleeping
n0v33n
commited on
Commit
·
eb92ba2
1
Parent(s):
ff8f2b3
Updated tools
Browse files
app.py
CHANGED
@@ -68,6 +68,8 @@ def preprocess_query(query: str) -> str:
|
|
68 |
query = re.sub(rf'\b{k}\b', v, query, flags=re.IGNORECASE)
|
69 |
query = re.sub(r'\bproblem\s*(\d+)', r'Problem_\1', query, flags=re.IGNORECASE)
|
70 |
query = re.sub(r'\bquestion\s*(\d+)', r'Problem_\1', query, flags=re.IGNORECASE)
|
|
|
|
|
71 |
return query
|
72 |
|
73 |
def get_daily_coding_question(query: str = "") -> dict:
|
@@ -130,21 +132,21 @@ def fetch_interview_questions(query: str) -> dict:
|
|
130 |
if not TAVILY_API_KEY:
|
131 |
return {"status": "error", "response": "Tavily API key not configured"}
|
132 |
|
133 |
-
if not query.strip() or query.lower() in ["a interview
|
134 |
return {"status": "error", "response": "Please provide a specific topic for interview questions (e.g., 'Python', 'data structures', 'system design')."}
|
135 |
|
136 |
try:
|
137 |
-
tavily = TavilySearch(api_key=TAVILY_API_KEY, max_results=
|
138 |
-
search_query = f"{query} interview questions
|
139 |
print(f"Executing Tavily search for: {search_query}")
|
140 |
|
141 |
-
# Use invoke method for TavilySearch
|
142 |
results = tavily.invoke(search_query)
|
|
|
143 |
|
144 |
if not results or not isinstance(results, list) or len(results) == 0:
|
145 |
return {"status": "success", "response": "No relevant interview questions found. Try a more specific topic or different keywords."}
|
146 |
|
147 |
-
resp = "**Interview Questions Search Results:**\n\n"
|
148 |
for i, r in enumerate(results, 1):
|
149 |
if isinstance(r, dict):
|
150 |
title = r.get('title', 'No title')
|
@@ -216,14 +218,14 @@ You are an interview preparation assistant. Analyze the user's query and determi
|
|
216 |
|
217 |
Available tools:
|
218 |
1. get_daily_coding_question - For coding practice, LeetCode problems, daily questions
|
219 |
-
2. fetch_interview_questions - For searching interview questions on specific topics
|
220 |
3. simulate_mock_interview - For mock interview practice (HR/behavioral or technical)
|
221 |
|
222 |
Instructions:
|
223 |
- If user asks for coding questions, daily questions, LeetCode problems, practice problems -> use get_daily_coding_question
|
224 |
-
- If user asks for interview questions on specific topics,
|
225 |
-
- If user asks for mock interview, interview simulation, practice interview -> use simulate_mock_interview
|
226 |
-
-
|
227 |
|
228 |
Respond ONLY with valid JSON in this exact format:
|
229 |
{"tool": "tool_name", "args": {"param1": "value1", "param2": "value2"}}
|
@@ -234,6 +236,15 @@ User Query: {query}
|
|
234 |
def _classify_intent(self, query: str) -> tuple[str, dict]:
|
235 |
query_lower = query.lower()
|
236 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
if any(keyword in query_lower for keyword in ["daily", "coding question", "leetcode", "practice problem", "coding practice"]):
|
238 |
problem_match = re.search(r'problem\s*(\d+)', query_lower)
|
239 |
if problem_match:
|
@@ -248,17 +259,12 @@ User Query: {query}
|
|
248 |
|
249 |
return "get_daily_coding_question", {"query": ""}
|
250 |
|
251 |
-
|
252 |
-
("give" in query_lower and "interview question" in query_lower):
|
253 |
-
return "simulate_mock_interview", {"query": query, "user_id": "default"}
|
254 |
-
|
255 |
-
if "interview question" in query_lower and any(word in query_lower for word in ["technical", "hr", "behavioral"]):
|
256 |
-
return "simulate_mock_interview", {"query": query, "user_id": "default"}
|
257 |
-
|
258 |
if any(keyword in query_lower for keyword in ["search interview questions", "find interview questions", "interview prep resources"]) or \
|
259 |
-
|
260 |
return "fetch_interview_questions", {"query": query}
|
261 |
|
|
|
262 |
try:
|
263 |
prompt = self.instruction_text.format(query=query)
|
264 |
response = self.model.generate_content(prompt)
|
@@ -324,4 +330,4 @@ def root():
|
|
324 |
|
325 |
if __name__ == "__main__":
|
326 |
import uvicorn
|
327 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
68 |
query = re.sub(rf'\b{k}\b', v, query, flags=re.IGNORECASE)
|
69 |
query = re.sub(r'\bproblem\s*(\d+)', r'Problem_\1', query, flags=re.IGNORECASE)
|
70 |
query = re.sub(r'\bquestion\s*(\d+)', r'Problem_\1', query, flags=re.IGNORECASE)
|
71 |
+
query = re.sub(r'\b(find|search)\s+interview\s+questions\s+for\s+', '', query, flags=re.IGNORECASE)
|
72 |
+
query = re.sub(r'\binterview\s+questions\b', '', query, flags=re.IGNORECASE).strip()
|
73 |
return query
|
74 |
|
75 |
def get_daily_coding_question(query: str = "") -> dict:
|
|
|
132 |
if not TAVILY_API_KEY:
|
133 |
return {"status": "error", "response": "Tavily API key not configured"}
|
134 |
|
135 |
+
if not query.strip() or query.lower() in ["a", "interview", "question", "questions"]:
|
136 |
return {"status": "error", "response": "Please provide a specific topic for interview questions (e.g., 'Python', 'data structures', 'system design')."}
|
137 |
|
138 |
try:
|
139 |
+
tavily = TavilySearch(api_key=TAVILY_API_KEY, max_results=5)
|
140 |
+
search_query = f"{query} interview questions -inurl:(signup | login)"
|
141 |
print(f"Executing Tavily search for: {search_query}")
|
142 |
|
|
|
143 |
results = tavily.invoke(search_query)
|
144 |
+
print(f"Raw Tavily results: {results}")
|
145 |
|
146 |
if not results or not isinstance(results, list) or len(results) == 0:
|
147 |
return {"status": "success", "response": "No relevant interview questions found. Try a more specific topic or different keywords."}
|
148 |
|
149 |
+
resp = "**Interview Questions Search Results for '{}':**\n\n".format(query)
|
150 |
for i, r in enumerate(results, 1):
|
151 |
if isinstance(r, dict):
|
152 |
title = r.get('title', 'No title')
|
|
|
218 |
|
219 |
Available tools:
|
220 |
1. get_daily_coding_question - For coding practice, LeetCode problems, daily questions
|
221 |
+
2. fetch_interview_questions - For searching interview questions on specific topics
|
222 |
3. simulate_mock_interview - For mock interview practice (HR/behavioral or technical)
|
223 |
|
224 |
Instructions:
|
225 |
- If user asks for coding questions, daily questions, LeetCode problems, practice problems -> use get_daily_coding_question
|
226 |
+
- If user asks for interview questions on specific topics (e.g., Python, data structures) without "mock" or "simulate" -> use fetch_interview_questions
|
227 |
+
- If user asks for mock interview, interview simulation, practice interview, or HR/behavioral questions -> use simulate_mock_interview
|
228 |
+
- If user explicitly mentions "HR" or "behavioral" -> use simulate_mock_interview with HR focus
|
229 |
|
230 |
Respond ONLY with valid JSON in this exact format:
|
231 |
{"tool": "tool_name", "args": {"param1": "value1", "param2": "value2"}}
|
|
|
236 |
def _classify_intent(self, query: str) -> tuple[str, dict]:
|
237 |
query_lower = query.lower()
|
238 |
|
239 |
+
# Prioritize HR/behavioral for explicit mentions
|
240 |
+
if any(keyword in query_lower for keyword in ["hr", "behavioral", "give hr questions", "give behavioral questions"]):
|
241 |
+
return "simulate_mock_interview", {"query": query, "user_id": "default"}
|
242 |
+
|
243 |
+
# Handle mock interview or simulation requests
|
244 |
+
if any(keyword in query_lower for keyword in ["mock interview", "practice interview", "interview simulation", "simulate_mock_interview"]):
|
245 |
+
return "simulate_mock_interview", {"query": query, "user_id": "default"}
|
246 |
+
|
247 |
+
# Handle coding-related queries
|
248 |
if any(keyword in query_lower for keyword in ["daily", "coding question", "leetcode", "practice problem", "coding practice"]):
|
249 |
problem_match = re.search(r'problem\s*(\d+)', query_lower)
|
250 |
if problem_match:
|
|
|
259 |
|
260 |
return "get_daily_coding_question", {"query": ""}
|
261 |
|
262 |
+
# Handle topic-specific interview questions
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
if any(keyword in query_lower for keyword in ["search interview questions", "find interview questions", "interview prep resources"]) or \
|
264 |
+
"interview" in query_lower:
|
265 |
return "fetch_interview_questions", {"query": query}
|
266 |
|
267 |
+
# Fallback to LLM classification
|
268 |
try:
|
269 |
prompt = self.instruction_text.format(query=query)
|
270 |
response = self.model.generate_content(prompt)
|
|
|
330 |
|
331 |
if __name__ == "__main__":
|
332 |
import uvicorn
|
333 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|