Shreekant Kalwar (Nokia) commited on
Commit
c996a96
Β·
1 Parent(s): 65dde8a

new changes

Browse files
Files changed (1) hide show
  1. util.py +42 -13
util.py CHANGED
@@ -244,12 +244,17 @@ class ErrorBot:
244
  # """
245
 
246
  system_prompt = f"""
247
- You are a technical assistant. A user may ask questions about Problem Reports (PR), Fault Analyses (FA), and Corrections (CR).
248
- Your task is to:
249
- 1. Identify which information (PR, FA, CR) is relevant to answering the user's question.
250
- 2. Explain the solution in simple, clear, actionable language.
251
- 3. Do not just repeat the content; summarize and explain.
252
-
 
 
 
 
 
253
  ### User Question:
254
 
255
 
@@ -394,6 +399,11 @@ class ErrorBot:
394
  is_followup = self.is_followup_query(query, history)
395
 
396
  # Step 2: Non-technical standalone
 
 
 
 
 
397
  #if not is_technical:
398
  if not is_technical and not is_followup:
399
  print("⚠️ Non-technical standalone query β†’ skipping Qdrant.")
@@ -413,12 +423,7 @@ class ErrorBot:
413
  )
414
  return completion.choices[0].message.content.strip(), []
415
 
416
- # Step 3: Technical or follow-up
417
- print("is_followup", is_followup)
418
- print("last_context", self.last_context)
419
- print("is_technical", is_technical)
420
-
421
- if is_followup and self.last_context:
422
  if not is_technical:
423
  print("⚠️ Non-technical followup β†’ skipping Qdrant.")
424
  system_prompt = "You are a helpful assistant. Answer clearly and concisely."
@@ -440,6 +445,30 @@ class ErrorBot:
440
  print("πŸ”„ Follow-up query β†’ reusing previous context.")
441
  retrieved_context = self.last_context
442
  context_docs = retrieved_context
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
443
 
444
  else:
445
  print("πŸ“₯ New technical query β†’ retrieving from Qdrant.")
@@ -522,7 +551,7 @@ class ErrorBot:
522
 
523
  answer = self.generate_answer(query, context_docs, history, is_followup)
524
  last_context = self.last_context
525
- print(f"\nπŸ€– Answer: {answer}")
526
  return (answer, last_context)
527
 
528
 
 
244
  # """
245
 
246
  system_prompt = f"""
247
+ You are a versatile assistant. A user may ask questions about:
248
+ - Problem Reports (PR), Fault Analyses (FA), and Corrections (CR).
249
+ - Programming, algorithms, and code examples.
250
+ - Non-technical or general everyday topics.
251
+
252
+ Your tasks are:
253
+ 1. If the question is about PR, FA, or CR β†’ Identify which information is relevant and explain clearly in simple, actionable language (summarize, don’t just repeat).
254
+ 2. If the question is about programming or algorithms β†’ Provide a correct, clear, and well-structured code example in the requested language, with a short explanation.
255
+ 3. If the question is non-technical/general β†’ Respond politely, clearly, and helpfully in a conversational style.
256
+ 4. Always keep answers concise and easy to understand.
257
+
258
  ### User Question:
259
 
260
 
 
399
  is_followup = self.is_followup_query(query, history)
400
 
401
  # Step 2: Non-technical standalone
402
+ # Step 3: Technical or follow-up
403
+ print("is_followup", is_followup)
404
+ #print("last_context", self.last_context)
405
+ print("is_technical", is_technical)
406
+
407
  #if not is_technical:
408
  if not is_technical and not is_followup:
409
  print("⚠️ Non-technical standalone query β†’ skipping Qdrant.")
 
423
  )
424
  return completion.choices[0].message.content.strip(), []
425
 
426
+ elif is_followup and self.last_context:
 
 
 
 
 
427
  if not is_technical:
428
  print("⚠️ Non-technical followup β†’ skipping Qdrant.")
429
  system_prompt = "You are a helpful assistant. Answer clearly and concisely."
 
445
  print("πŸ”„ Follow-up query β†’ reusing previous context.")
446
  retrieved_context = self.last_context
447
  context_docs = retrieved_context
448
+
449
+ elif is_followup and not self.last_context:
450
+
451
+ if not is_technical:
452
+ print("⚠️ Non-technical followup β†’ skipping Qdrant.")
453
+ system_prompt = "You are a helpful assistant. Answer clearly and concisely."
454
+ convo = [{"role": "system", "content": system_prompt},
455
+ {"role": "user", "content": query}]
456
+
457
+ if self.llm_provider == "gemini":
458
+ convo_str = "\n".join([f"{m['role'].capitalize()}: {m['content']}" for m in convo])
459
+ response = self.llm.generate_content(convo_str)
460
+ return response.text.strip(), []
461
+
462
+ elif self.llm_provider == "groq":
463
+ completion = self.llm.chat.completions.create(
464
+ model=self.llm_model_name,
465
+ messages=convo
466
+ )
467
+ return completion.choices[0].message.content.strip(), []
468
+ else:
469
+ print("πŸ”„ Follow-up query β†’ without previous context.")
470
+ #retrieved_context = self.last_context
471
+ context_docs = []
472
 
473
  else:
474
  print("πŸ“₯ New technical query β†’ retrieving from Qdrant.")
 
551
 
552
  answer = self.generate_answer(query, context_docs, history, is_followup)
553
  last_context = self.last_context
554
+ #print(f"\nπŸ€– Answer: {answer}")
555
  return (answer, last_context)
556
 
557