Update app/services/chat_service.py
Browse files- app/services/chat_service.py +55 -7
app/services/chat_service.py
CHANGED
|
@@ -32,19 +32,67 @@ class ChatService:
|
|
| 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 |
Relevant Code Context:
|
| 40 |
{context}
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
Your Expert Analysis:"""
|
| 50 |
|
|
|
|
| 32 |
try:
|
| 33 |
context = self.prepare_context(code_chunks)
|
| 34 |
|
| 35 |
+
prompt = f"""You are QODEX AI, an expert code assistant analyzing the {repository_name} repository.
|
| 36 |
|
| 37 |
User Question: {query}
|
| 38 |
|
| 39 |
Relevant Code Context:
|
| 40 |
{context}
|
| 41 |
|
| 42 |
+
RESPONSE FORMAT WITH KEYWORDS:
|
| 43 |
+
Use these EXACT keywords for formatting:
|
| 44 |
+
|
| 45 |
+
[ANSWER] - Direct answer to question
|
| 46 |
+
[SECTION] - Main section title
|
| 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 |
+
EXAMPLE RESPONSE FORMAT:
|
| 58 |
+
|
| 59 |
+
[ANSWER]The authentication system uses JWT tokens with refresh token rotation for enhanced security.
|
| 60 |
+
|
| 61 |
+
[SECTION]How Authentication Works
|
| 62 |
+
|
| 63 |
+
The system implements a comprehensive authentication flow that balances security with user experience. When a user logs in, the application creates two types of tokens that work together to maintain secure sessions.
|
| 64 |
+
|
| 65 |
+
[SUBSECTION]Token Generation Process
|
| 66 |
+
|
| 67 |
+
[FLOW]User Login Flow:
|
| 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 |
+
The [CODE]generateTokens[/CODE] function in [FILE]auth.service.ts[/FILE] handles this entire process. It uses the [HIGHLIGHT]jsonwebtoken library[/HIGHLIGHT] to create tokens with specific expiration times.
|
| 75 |
+
|
| 76 |
+
[SUBSECTION]Token Security Features
|
| 77 |
+
|
| 78 |
+
[INSIGHT]The system uses short-lived access tokens (15 minutes) combined with longer-lived refresh tokens (7 days). This approach minimizes the risk window if an access token is compromised, while the refresh token allows seamless re-authentication.
|
| 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 |
|