File size: 1,000 Bytes
6064cea
 
 
 
 
 
 
 
 
 
cdb5924
6064cea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from __future__ import annotations

from google import genai


class LegalLLM:

    def __init__(
        self,
        api_key: str,
        model: str = "gemini-2.5-flash-lite"
    ):

        self.model = model

        self.client = genai.Client(
            api_key=api_key
        )

    # =====================================================
    # GENERATE
    # =====================================================

    def generate(
        self,
        query: str,
        context: str
    ):

        prompt = f"""
You are an expert Indian Legal Assistant.

Use ONLY the supplied legal context.

If the answer is not found in the context,
say:

"The provided legal corpus does not contain
sufficient information to answer this question."

Question:
{query}

Legal Context:
{context}

Answer:
"""

        response = (
            self.client.models.generate_content(
                model=self.model,
                contents=prompt
            )
        )

        return response.text