Update app/services/chat_service.py
Browse files- app/services/chat_service.py +18 -16
app/services/chat_service.py
CHANGED
|
@@ -33,44 +33,32 @@ class ChatService:
|
|
| 33 |
context = self.prepare_context(code_chunks)
|
| 34 |
|
| 35 |
prompt = f"""You are an expert code assistant analyzing the {repository_name} repository.
|
| 36 |
-
|
| 37 |
User Question: {query}
|
| 38 |
-
|
| 39 |
Code Context:
|
| 40 |
{context}
|
| 41 |
-
|
| 42 |
RESPONSE FORMAT:
|
| 43 |
Use clean, professional markdown formatting similar to GitHub README files:
|
| 44 |
-
|
| 45 |
## Main Answer
|
| 46 |
[Direct answer to the user's question]
|
| 47 |
-
|
| 48 |
-
## Implementation Overview
|
| 49 |
[High-level explanation of how the feature/system works]
|
| 50 |
-
|
| 51 |
### Key Components
|
| 52 |
- **Component Name**: Brief description (`filename.py`, lines X-Y)
|
| 53 |
- **Component Name**: Brief description (`filename.py`, lines X-Y)
|
| 54 |
-
|
| 55 |
### Technical Details
|
| 56 |
[Detailed explanation with code references]
|
| 57 |
-
|
| 58 |
When referencing code:
|
| 59 |
- Use **bold** for important file names and concepts
|
| 60 |
- Use `backticks` for functions, variables, classes, and code snippets
|
| 61 |
- Reference specific files and line numbers: `filename.py` (lines X-Y)
|
| 62 |
- Use > blockquotes for important insights or warnings
|
| 63 |
-
|
| 64 |
### How It Works
|
| 65 |
1. **Step 1**: Description of first step
|
| 66 |
-
2. **Step 2**: Description of second step
|
| 67 |
3. **Step 3**: Description of third step
|
| 68 |
-
|
| 69 |
> **Key Insight**: Important observations about the implementation
|
| 70 |
-
|
| 71 |
## Additional Notes
|
| 72 |
[Any limitations, missing information, or recommendations]
|
| 73 |
-
|
| 74 |
REQUIREMENTS:
|
| 75 |
- NO emojis - use clean text only
|
| 76 |
- Be comprehensive and detailed
|
|
@@ -79,11 +67,25 @@ REQUIREMENTS:
|
|
| 79 |
- Use proper markdown hierarchy (##, ###, -, >, etc.)
|
| 80 |
- Focus on explanation rather than just code listing
|
| 81 |
- Professional documentation style
|
| 82 |
-
|
| 83 |
Your detailed markdown analysis:"""
|
| 84 |
|
| 85 |
response = self.model.generate_content(prompt)
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
sources = []
|
| 88 |
for chunk in code_chunks:
|
| 89 |
sources.append({
|
|
@@ -95,7 +97,7 @@ Your detailed markdown analysis:"""
|
|
| 95 |
})
|
| 96 |
|
| 97 |
return {
|
| 98 |
-
'response':
|
| 99 |
'sources': sources,
|
| 100 |
'context_chunks_used': len(code_chunks),
|
| 101 |
'repository_name': repository_name,
|
|
|
|
| 33 |
context = self.prepare_context(code_chunks)
|
| 34 |
|
| 35 |
prompt = f"""You are an expert code assistant analyzing the {repository_name} repository.
|
|
|
|
| 36 |
User Question: {query}
|
|
|
|
| 37 |
Code Context:
|
| 38 |
{context}
|
|
|
|
| 39 |
RESPONSE FORMAT:
|
| 40 |
Use clean, professional markdown formatting similar to GitHub README files:
|
|
|
|
| 41 |
## Main Answer
|
| 42 |
[Direct answer to the user's question]
|
| 43 |
+
## Implementation Overview
|
|
|
|
| 44 |
[High-level explanation of how the feature/system works]
|
|
|
|
| 45 |
### Key Components
|
| 46 |
- **Component Name**: Brief description (`filename.py`, lines X-Y)
|
| 47 |
- **Component Name**: Brief description (`filename.py`, lines X-Y)
|
|
|
|
| 48 |
### Technical Details
|
| 49 |
[Detailed explanation with code references]
|
|
|
|
| 50 |
When referencing code:
|
| 51 |
- Use **bold** for important file names and concepts
|
| 52 |
- Use `backticks` for functions, variables, classes, and code snippets
|
| 53 |
- Reference specific files and line numbers: `filename.py` (lines X-Y)
|
| 54 |
- Use > blockquotes for important insights or warnings
|
|
|
|
| 55 |
### How It Works
|
| 56 |
1. **Step 1**: Description of first step
|
| 57 |
+
2. **Step 2**: Description of second step
|
| 58 |
3. **Step 3**: Description of third step
|
|
|
|
| 59 |
> **Key Insight**: Important observations about the implementation
|
|
|
|
| 60 |
## Additional Notes
|
| 61 |
[Any limitations, missing information, or recommendations]
|
|
|
|
| 62 |
REQUIREMENTS:
|
| 63 |
- NO emojis - use clean text only
|
| 64 |
- Be comprehensive and detailed
|
|
|
|
| 67 |
- Use proper markdown hierarchy (##, ###, -, >, etc.)
|
| 68 |
- Focus on explanation rather than just code listing
|
| 69 |
- Professional documentation style
|
|
|
|
| 70 |
Your detailed markdown analysis:"""
|
| 71 |
|
| 72 |
response = self.model.generate_content(prompt)
|
| 73 |
|
| 74 |
+
# --- START: BEST FIX ---
|
| 75 |
+
# Clean the response text to remove markdown code block wrappers
|
| 76 |
+
response_text = response.text
|
| 77 |
+
|
| 78 |
+
if response_text.startswith("```markdown"):
|
| 79 |
+
response_text = response_text[len("```markdown"):]
|
| 80 |
+
elif response_text.startswith("```"):
|
| 81 |
+
response_text = response_text[len("```"):]
|
| 82 |
+
|
| 83 |
+
if response_text.endswith("```"):
|
| 84 |
+
response_text = response_text[:-len("```")]
|
| 85 |
+
|
| 86 |
+
response_text = response_text.strip() # Remove any leading/trailing whitespace
|
| 87 |
+
# --- END: BEST FIX ---
|
| 88 |
+
|
| 89 |
sources = []
|
| 90 |
for chunk in code_chunks:
|
| 91 |
sources.append({
|
|
|
|
| 97 |
})
|
| 98 |
|
| 99 |
return {
|
| 100 |
+
'response': response_text, # Use the cleaned text
|
| 101 |
'sources': sources,
|
| 102 |
'context_chunks_used': len(code_chunks),
|
| 103 |
'repository_name': repository_name,
|