You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: app/Services/Llm/Driver/GeminiDriver.php
+27-8Lines changed: 27 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -18,14 +18,12 @@ public function prompt(?array $prismMessages = [], ?User $user = null, ?string $
18
18
try {
19
19
return Prism::text()
20
20
->using(Provider::Gemini, 'gemini-2.5-flash')
21
-
->withSystemPrompt("You are a helpful AI assistant that primarily answers questions based on the legal documents provided in the Context. When a user asks a question related to the Context, use the information from it as your main source and cite each reference inline using the page id format (e.g., [Page 1]).
22
-
If the user's question is general, conversational, or unrelated to the provided Context, you may respond naturally and helpfully using your own general knowledge — do NOT reply with “I couldn't find relevant information in the provided documents.”
23
-
Always aim to be informative, friendly, and accurate. When relevant, include citations from the Context, but when not relevant, engage normally as a helpful assistant while replying 'No relevant information found in the provided documents.'.
24
-
Never, never, never leave a response empty please!.")
25
-
// ->withMessages($prismMessages)
26
-
->withPrompt($prompt)
27
-
->withMaxTokens(512)
28
-
->usingTemperature(0.0)
21
+
->withSystemPrompt($this->getSystemPrompt())
22
+
->withMessages($prismMessages)
23
+
// ->withPrompt($prompt)
24
+
->withMaxTokens(8000)
25
+
->withClientOptions(['timeout' => 60])
26
+
->usingTemperature(0.2)
29
27
->asText()->text;
30
28
} catch (PrismException$e) {
31
29
Log::error('Prompt generation failed:', [
@@ -57,4 +55,25 @@ public function embed(?string $texts = null, ?string $path = null): array
57
55
return [];
58
56
}
59
57
}
58
+
59
+
protectedfunctiongetSystemPrompt(): string
60
+
{
61
+
return"You are a helpful and informative AI assistant specializing in legal document analysis. Your primary goal is to answer questions accurately by prioritizing the information provided in the **Context** section below.
62
+
63
+
### Core RAG Rules:
64
+
1. **Grounded Answers:** When a user asks a question related to the Context, use only the retrieved documents as your source.
65
+
2. **Citations:** For every piece of information drawn from the Context, you **must** cite the reference inline using the document and page format, such as **[page: PAGE_NUM]**.
66
+
3. **Calculation Priority (New Rule):** If the user asks a question requiring arithmetic, you **must** use the tax bands and rates available in the Context to perform the calculation. State the final answer. **If specific initial income brackets are missing but subsequent brackets and rates are present, you must use reasonable assumptions derived from the common structure of the progressive tax system to complete the calculation.**
67
+
4. **Non-Relevant Queries:** If the user's question is general, conversational, or unrelated to the provided Context, you must ignore the Context and respond naturally and helpfully using your own general knowledge. Do not reference the documents or apologize for not finding information.
68
+
5. **No Empty Responses:** Under no circumstances should you ever return an empty response.
69
+
70
+
Always aim to be informative, friendly, and accurate. ";
71
+
72
+
// You must output the step-by-step arithmetic before stating
73
+
// 'You are a helpful AI assistant that primarily answers questions based on the legal documents provided in the Context. When a user asks a question related to the Context, use the information from it as your main source and cite each reference inline using the page id format (e.g., [Page 1]).
74
+
// If the user's question is general, conversational, or unrelated to the provided Context, you may respond naturally and helpfully using your own general knowledge — do NOT reply with “I couldn't find relevant information in the provided documents.”
75
+
// Always aim to be informative, friendly, and accurate. When relevant, include citations from the Context, but when not relevant, engage normally as a helpful assistant while replying 'No relevant information found in the provided documents.'.
76
+
// Never, never, never leave a response empty please!.'
0 commit comments