Update app/services/chat_service.py
Browse files- app/services/chat_service.py +34 -48
app/services/chat_service.py
CHANGED
|
@@ -32,69 +32,55 @@ class ChatService:
|
|
| 32 |
try:
|
| 33 |
context = self.prepare_context(code_chunks)
|
| 34 |
|
| 35 |
-
prompt = f"""You are
|
| 36 |
|
| 37 |
User Question: {query}
|
| 38 |
|
| 39 |
-
|
| 40 |
{context}
|
| 41 |
|
| 42 |
-
RESPONSE FORMAT
|
| 43 |
-
Use
|
| 44 |
|
| 45 |
-
|
| 46 |
-
[
|
| 47 |
-
[SUBSECTION] - Subsection title
|
| 48 |
-
[POINT] - Bullet point
|
| 49 |
-
[CODE] - Code elements (functions, variables, classes)
|
| 50 |
-
[FILE] - File references
|
| 51 |
-
[HIGHLIGHT] - Important concepts
|
| 52 |
-
[FLOW] - Step-by-step process
|
| 53 |
-
[INSIGHT] - Key insights or explanations
|
| 54 |
-
[NOTE] - Additional important information
|
| 55 |
-
[DIVIDER] - Section separator
|
| 56 |
|
| 57 |
-
|
|
|
|
| 58 |
|
| 59 |
-
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
|
|
|
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
-
[POINT]User submits credentials through the login form
|
| 69 |
-
[POINT]Server validates credentials against the database
|
| 70 |
-
[POINT]If valid, server generates both access and refresh tokens
|
| 71 |
-
[POINT]Tokens are stored in httpOnly cookies for security
|
| 72 |
-
[POINT]User is redirected to the dashboard
|
| 73 |
|
| 74 |
-
|
|
|
|
| 75 |
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
[POINT][HIGHLIGHT]Access Tokens[/HIGHLIGHT]: Contain user claims and expire quickly
|
| 81 |
-
[POINT][HIGHLIGHT]Refresh Tokens[/HIGHLIGHT]: Used to generate new access tokens
|
| 82 |
-
[POINT][HIGHLIGHT]Automatic Rotation[/HIGHLIGHT]: Refresh tokens are replaced on each use
|
| 83 |
-
|
| 84 |
-
[DIVIDER]
|
| 85 |
-
|
| 86 |
-
[NOTE]The refresh token rotation prevents token replay attacks by invalidating old refresh tokens immediately after use.
|
| 87 |
-
|
| 88 |
-
INSTRUCTIONS:
|
| 89 |
-
1. Use the EXACT keyword format shown above
|
| 90 |
-
2. Provide detailed explanations, not just code references
|
| 91 |
-
3. Explain WHY things work the way they do
|
| 92 |
-
4. Focus on concepts and implementation logic
|
| 93 |
-
5. Use sources for code proof, but explain in your own words
|
| 94 |
-
6. If context is insufficient, clearly state what's missing
|
| 95 |
-
7. Be comprehensive but well-structured
|
| 96 |
-
|
| 97 |
-
Your Expert Analysis:"""
|
| 98 |
|
| 99 |
response = self.model.generate_content(prompt)
|
| 100 |
|
|
|
|
| 32 |
try:
|
| 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
|
| 77 |
+
- Reference specific files and line numbers
|
| 78 |
+
- Explain both WHAT the code does and HOW it works
|
| 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 |
|