anris05 commited on
Commit
e5a0a2f
·
1 Parent(s): dbb7de4
agents/intent_classifier.py CHANGED
@@ -88,10 +88,12 @@ _PRONOUN_ONLY_PATTERN = re.compile(
88
  )
89
 
90
  _WORKED_EXAMPLE_PATTERN = re.compile(
91
- r"\d+(?:\s*,\s*\d+){1,}.*\b(this|that|same)\b.*\b(search|sort|algorithm|method|approach|traversal)\b",
92
  re.IGNORECASE,
93
  )
94
 
 
 
95
  def is_followup_query(query: str, has_conversation_history: bool) -> bool:
96
  """
97
  A query is treated as a follow-up when:
@@ -110,10 +112,12 @@ def is_followup_query(query: str, has_conversation_history: bool) -> bool:
110
  return True
111
 
112
  word_count = len(query.strip().split())
113
- has_pronoun = bool(_PRONOUN_ONLY_PATTERN.search(query))
114
  mentions_topic = bool(extract_topics(query))
115
 
116
- if has_pronoun and not mentions_topic and word_count <= 8:
 
 
117
  return True
118
 
119
  return False
 
88
  )
89
 
90
  _WORKED_EXAMPLE_PATTERN = re.compile(
91
+ r"\d+(?:\s*,\s*\d+){1,}.*\b(this|that|same|additional info|additional information)\b.*\b(search|sort|algorithm|method|approach|traversal)\b",
92
  re.IGNORECASE,
93
  )
94
 
95
+ _CODE_REQUEST_PATTERN = re.compile(r"\b(code|implementation|logic)\b", re.IGNORECASE)
96
+
97
  def is_followup_query(query: str, has_conversation_history: bool) -> bool:
98
  """
99
  A query is treated as a follow-up when:
 
112
  return True
113
 
114
  word_count = len(query.strip().split())
115
+ has_pronoun = bool(_PRONOUN_ONLY_PATTERN.search(query)) or bool(_CODE_REQUEST_PATTERN.search(query))
116
  mentions_topic = bool(extract_topics(query))
117
 
118
+ # if has_pronoun and not mentions_topic and word_count <= 8:
119
+ # return True
120
+ if not mentions_topic and word_count <= 8 and has_conversation_history:
121
  return True
122
 
123
  return False
config.py CHANGED
@@ -77,6 +77,7 @@ LOCAL_MODEL_TEMPERATURE = float(os.getenv("LOCAL_MODEL_TEMPERATURE", 0.3))
77
  LOCAL_MODEL_LOAD_IN_4BIT = os.getenv("LOCAL_MODEL_LOAD_IN_4BIT", "True") == "True"
78
 
79
  GROQ_API_KEY = os.getenv("GROQ_API_KEY")
 
80
  GROQ_MODEL_NAME = os.getenv("GROQ_MODEL_NAME", "llama-3.3-70b-versatile")
81
 
82
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "")
 
77
  LOCAL_MODEL_LOAD_IN_4BIT = os.getenv("LOCAL_MODEL_LOAD_IN_4BIT", "True") == "True"
78
 
79
  GROQ_API_KEY = os.getenv("GROQ_API_KEY")
80
+ GROQ_MAX_TOKENS = int(os.getenv("GROQ_MAX_TOKENS", 1024))
81
  GROQ_MODEL_NAME = os.getenv("GROQ_MODEL_NAME", "llama-3.3-70b-versatile")
82
 
83
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "")
llm/groq_provider.py CHANGED
@@ -47,7 +47,7 @@ class GroqProvider(LLMProvider):
47
  model=self._model,
48
  messages=messages,
49
  temperature=config.LOCAL_MODEL_TEMPERATURE,
50
- max_tokens=config.LOCAL_MODEL_MAX_NEW_TOKENS,
51
  stream=False,
52
  )
53
  except Exception:
 
47
  model=self._model,
48
  messages=messages,
49
  temperature=config.LOCAL_MODEL_TEMPERATURE,
50
+ max_tokens=config.GROQ_MAX_TOKENS,
51
  stream=False,
52
  )
53
  except Exception:
llm/prompts.py CHANGED
@@ -24,7 +24,10 @@ These builders only assemble strings — they never call the LLM themselves
24
 
25
  SYSTEM_PROMPT = (
26
  "You are a patient, precise Data Structures and Algorithms (DSA) tutor. "
27
- "Answer using ONLY the information provided in the retrieved context below. "
 
 
 
28
  "If the retrieved context does not contain enough information to answer "
29
  "confidently, say so explicitly rather than guessing or inventing details. "
30
  "Explain concepts clearly, use the time/space complexity and examples given "
 
24
 
25
  SYSTEM_PROMPT = (
26
  "You are a patient, precise Data Structures and Algorithms (DSA) tutor. "
27
+ "Answer using the retrieved context as your primary source of truth for explanations, complexity, and examples."
28
+ "If the user asks for code, you may write a clean, correct implementation in the requested language, consistent with the algorithm described in the context."
29
+ "If language not specified, use python as the primary language."
30
+ "Always include the time and space complexities wherever possible."
31
  "If the retrieved context does not contain enough information to answer "
32
  "confidently, say so explicitly rather than guessing or inventing details. "
33
  "Explain concepts clearly, use the time/space complexity and examples given "
requirements.txt CHANGED
@@ -7,7 +7,7 @@ chromadb>=1.0.0
7
  sentence-transformers==3.3.1
8
  mem0ai==0.1.29
9
  groq==0.15.0
10
- torch==2.8.0
11
  transformers==4.47.1
12
  accelerate==1.2.1
13
  bitsandbytes==0.45.0
 
7
  sentence-transformers==3.3.1
8
  mem0ai==0.1.29
9
  groq==0.15.0
10
+ torch==2.6.0
11
  transformers==4.47.1
12
  accelerate==1.2.1
13
  bitsandbytes==0.45.0