gabykim commited on
Commit
ca665cb
·
1 Parent(s): d1597d8

polish prompts for chatbot

Browse files
src/know_lang_bot/chat_bot/chat_graph.py CHANGED
@@ -43,10 +43,21 @@ class ChatGraphDeps:
43
  @dataclass
44
  class PolishQuestionNode(BaseNode[ChatGraphState, ChatGraphDeps, ChatResult]):
45
  """Node that polishes the user's question"""
46
- system_prompt = """
47
- You are an expert at understanding code-related questions and reformulating them
48
- for better context retrieval. Your task is to polish the user's question to make
49
- it more specific and searchable. Focus on technical terms and code concepts.
 
 
 
 
 
 
 
 
 
 
 
50
  """
51
 
52
  async def run(self, ctx: GraphRunContext[ChatGraphState, ChatGraphDeps]) -> RetrieveContextNode:
@@ -55,13 +66,10 @@ class PolishQuestionNode(BaseNode[ChatGraphState, ChatGraphDeps, ChatResult]):
55
  f"{ctx.deps.config.llm.model_provider}:{ctx.deps.config.llm.model_name}",
56
  system_prompt=self.system_prompt
57
  )
58
- prompt = f"""
59
- Original question: {ctx.state.original_question}
60
-
61
- Please reformulate this question to be more specific and searchable,
62
- focusing on technical terms and code concepts. Keep the core meaning
63
- but make it more precise for code context retrieval.
64
- """
65
 
66
  result = await polish_agent.run(prompt)
67
  ctx.state.polished_question = result.data
@@ -111,13 +119,22 @@ class RetrieveContextNode(BaseNode[ChatGraphState, ChatGraphDeps, ChatResult]):
111
  class AnswerQuestionNode(BaseNode[ChatGraphState, ChatGraphDeps, ChatResult]):
112
  """Node that generates the final answer"""
113
  system_prompt = """
114
- You are an expert code assistant helping users understand a codebase.
115
- Always:
116
- 1. Reference specific files and line numbers in your explanations
117
- 2. Be direct and concise while being comprehensive
118
- 3. If the context is insufficient, explain why
119
- 4. If you're unsure about something, acknowledge it
120
- """
 
 
 
 
 
 
 
 
 
121
 
122
  async def run(self, ctx: GraphRunContext[ChatGraphState, ChatGraphDeps]) -> End[ChatResult]:
123
  answer_agent = Agent(
@@ -134,13 +151,17 @@ class AnswerQuestionNode(BaseNode[ChatGraphState, ChatGraphDeps, ChatResult]):
134
 
135
  context = ctx.state.retrieved_context
136
  prompt = f"""
137
- Question: {ctx.state.original_question}
138
-
139
- Available Code Context:
140
- {context.chunks}
141
-
142
- Please provide a comprehensive answer based on the code context above.
143
- Make sure to reference specific files and line numbers from the context.
 
 
 
 
144
  """
145
 
146
  try:
 
43
  @dataclass
44
  class PolishQuestionNode(BaseNode[ChatGraphState, ChatGraphDeps, ChatResult]):
45
  """Node that polishes the user's question"""
46
+ system_prompt = """You are a code question refinement expert. Your ONLY task is to rephrase questions
47
+ to be more precise for code context retrieval. Follow these rules strictly:
48
+
49
+ 1. Output ONLY the refined question - no explanations or analysis
50
+ 2. Preserve the original intent completely
51
+ 3. Add missing technical terms if obvious
52
+ 4. Keep the question concise - ideally one sentence
53
+ 5. Focus on searchable technical terms
54
+ 6. Do not add speculative terms not implied by the original question
55
+
56
+ Example Input: "How do I use transformers for translation?"
57
+ Example Output: "How do I use the Transformers pipeline for machine translation tasks?"
58
+
59
+ Example Input: "Where is the config stored?"
60
+ Example Output: "Where is the configuration file or configuration settings stored in this codebase?"
61
  """
62
 
63
  async def run(self, ctx: GraphRunContext[ChatGraphState, ChatGraphDeps]) -> RetrieveContextNode:
 
66
  f"{ctx.deps.config.llm.model_provider}:{ctx.deps.config.llm.model_name}",
67
  system_prompt=self.system_prompt
68
  )
69
+ prompt = f"""Original question: "{ctx.state.original_question}"
70
+
71
+ Return ONLY the polished question - no explanations or analysis.
72
+ Focus on making the question more searchable while preserving its original intent."""
 
 
 
73
 
74
  result = await polish_agent.run(prompt)
75
  ctx.state.polished_question = result.data
 
119
  class AnswerQuestionNode(BaseNode[ChatGraphState, ChatGraphDeps, ChatResult]):
120
  """Node that generates the final answer"""
121
  system_prompt = """
122
+ You are an expert code assistant helping developers understand complex codebases. Follow these rules strictly:
123
+
124
+ 1. ALWAYS START by directly answering the user's question - this is your primary task
125
+ 2. Base your answer ONLY on the provided code context, not on general knowledge
126
+ 3. When referencing code:
127
+ - Cite specific files and line numbers
128
+ - Quote relevant code snippets briefly
129
+ - Explain why this code is relevant to the question
130
+ 4. If you cannot find sufficient context to answer fully:
131
+ - Clearly state what's missing
132
+ - Explain what additional information would help
133
+ 5. Focus on accuracy over comprehensiveness:
134
+ - If you're unsure about part of your answer, explicitly say so
135
+ - Better to acknowledge limitations than make assumptions
136
+
137
+ Remember: Your primary goal is answering the user's specific question, not explaining the entire codebase."""
138
 
139
  async def run(self, ctx: GraphRunContext[ChatGraphState, ChatGraphDeps]) -> End[ChatResult]:
140
  answer_agent = Agent(
 
151
 
152
  context = ctx.state.retrieved_context
153
  prompt = f"""
154
+ Question: {ctx.state.original_question}
155
+
156
+ Relevant Code Context:
157
+ {context.chunks}
158
+
159
+ Provide a focused answer to the question above. Structure your response as:
160
+ 1. Direct Answer: Start with a clear, concise answer to the question
161
+ 2. Supporting Evidence: Reference specific code with file locations
162
+ 3. Limitations (if any): Note any missing context or uncertainties
163
+
164
+ Important: Stay focused on answering the specific question asked.
165
  """
166
 
167
  try: