rohit commited on
Commit
b5e33d3
Β·
1 Parent(s): b99f945

improved tool calling , prompt enhance

Browse files
Files changed (1) hide show
  1. app/main.py +30 -24
app/main.py CHANGED
@@ -143,7 +143,33 @@ async def chat_with_ai(request: ChatRequest):
143
  # Add system message to guide the AI
144
  system_message: ChatCompletionMessageParam = {
145
  "role": "system",
146
- "content": "You are a helpful AI assistant. You have access to a RAG (Retrieval-Augmented Generation) pipeline that can answer questions about specific datasets. Use the rag_qa tool when users ask questions that would benefit from searching the dataset knowledge. For general conversation, respond normally. The available datasets are primarily focused on developer portfolio information, but can include other topics depending on what's loaded."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  }
148
 
149
  # Insert system message at the beginning
@@ -216,11 +242,10 @@ async def chat_with_ai(request: ChatRequest):
216
  "tool_calls": [
217
  {
218
  "name": tc.function.name,
219
- "arguments": tc.function.arguments,
220
- "result": next(tr["result"] for tr in tool_results if tr["tool_call_id"] == tc.id)
221
  }
222
  for tc in message.tool_calls
223
- ] if message.tool_calls else None
224
  }
225
  else:
226
  # Direct response without tool calls
@@ -232,26 +257,7 @@ async def chat_with_ai(request: ChatRequest):
232
  except Exception as e:
233
  raise HTTPException(status_code=500, detail=str(e))
234
 
235
- @app.post("/answer")
236
- async def get_answer(question: Question):
237
- try:
238
- # Check if any pipelines are loaded
239
- if not pipelines:
240
- return {
241
- "answer": "RAG Pipeline is running but datasets are still loading in the background. Please try again in a moment, or check /health for loading status.",
242
- "dataset": question.dataset,
243
- "status": "datasets_loading"
244
- }
245
-
246
- # Select the appropriate pipeline based on dataset
247
- if question.dataset not in pipelines:
248
- raise HTTPException(status_code=400, detail=f"Dataset '{question.dataset}' not available. Available datasets: {list(pipelines.keys())}")
249
-
250
- selected_pipeline = pipelines[question.dataset]
251
- answer = selected_pipeline.answer_question(question.text)
252
- return {"answer": answer, "dataset": question.dataset}
253
- except Exception as e:
254
- raise HTTPException(status_code=500, detail=str(e))
255
 
256
  @app.get("/datasets")
257
  async def list_datasets():
 
143
  # Add system message to guide the AI
144
  system_message: ChatCompletionMessageParam = {
145
  "role": "system",
146
+ "content": """You are an AI assistant for Rohit's developer portfolio. You have access to a RAG (Retrieval-Augmented Generation) pipeline containing information about Rohit's professional background, skills, and experience.
147
+
148
+ CRITICAL: The portfolio information is about ROHIT, not you. Always refer to Rohit in the third person ("he", "his", "Rohit") rather than first person ("I", "my", "me").
149
+
150
+ When you use rag_qa tool, you MUST use retrieved information to answer about Rohit's background.
151
+
152
+ Guidelines:
153
+ - Use rag_qa tool for questions about Rohit's: work experience, skills, projects, achievements, contact info
154
+ - For general greetings, introduce yourself as Rohit's AI assistant
155
+ - Always refer to Rohit in third person (he/his/Rohit)
156
+ - Synthesize RAG results into natural responses about Rohit
157
+ - Format responses with markdown for readability
158
+
159
+ Examples:
160
+ ❌ Wrong: "I am a Tech Lead at FleetEnable"
161
+ βœ… Right: "Rohit is currently working as a Tech Lead at FleetEnable"
162
+
163
+ ❌ Wrong: "My responsibilities include..."
164
+ βœ… Right: "His responsibilities include..."
165
+
166
+ ❌ Wrong: "I have 5+ years of experience..."
167
+ βœ… Right: "Rohit has 5+ years of experience..."
168
+
169
+ ❌ Wrong: "You can reach me at..."
170
+ βœ… Right: "You can reach Rohit at..."
171
+
172
+ For greetings: "Hi! I'm Rohit's AI assistant. I can help you learn about his professional background, skills, and experience. What would you like to know about Rohit?"""
173
  }
174
 
175
  # Insert system message at the beginning
 
242
  "tool_calls": [
243
  {
244
  "name": tc.function.name,
245
+ "arguments": tc.function.arguments
 
246
  }
247
  for tc in message.tool_calls
248
+ ]
249
  }
250
  else:
251
  # Direct response without tool calls
 
257
  except Exception as e:
258
  raise HTTPException(status_code=500, detail=str(e))
259
 
260
+ # /answer endpoint removed - use /chat for all interactions
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
 
262
  @app.get("/datasets")
263
  async def list_datasets():