File size: 2,607 Bytes
62a386e
 
 
 
 
 
 
 
 
 
6007bb8
62a386e
6007bb8
 
 
62a386e
6007bb8
 
 
 
 
 
 
62a386e
6007bb8
 
 
 
 
 
0a0248a
 
 
 
 
 
 
6007bb8
 
 
 
62a386e
 
6007bb8
 
62a386e
 
 
 
 
6007bb8
62a386e
 
6007bb8
 
62a386e
00d5554
 
 
 
6007bb8
 
00d5554
6007bb8
00d5554
6007bb8
62a386e
6007bb8
 
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
58
59
60
61
62
63
64
65
66
67
68
69
70
# ask_llm_with_context.py

import openai
import os

openai.api_base = "https://api.groq.com/openai/v1"
openai.api_key = os.getenv("GROQ_API_KEY")

def ask_llm_with_context(question, context, model="llama3-8b-8192"):
    prompt = f"""
You are a legal teaching assistant supporting land surveyors in British Columbia.

Your task is to answer questions **strictly** based on the following legal context. 
The users include licensed surveyors (BCLS) and Land Surveyors in Training (LSTs). 
Note: LSTs are not authorized to certify or sign legal survey documents and must work under BCLS supervision.

These individuals are governed by:
- Statutes
- Survey and Plan Rules
- Circular Letters
- Practice Bulletins
- Code of Ethics
- ABCLS bylaws and manuals

IMPORTANT INSTRUCTIONS:
- Only cite section numbers, regulations, or acts that are explicitly visible in the provided context.
- Do **NOT** make up legal citations, section numbers, or page references.
- If the specific section is **not in the context**, respond with: "The context does not provide a specific section for this."
- If unsure, recommend the appropriate document (e.g., "You may refer to the Survey and Plan Rules or Land Title Act").

Please organize your response in two sections:

**Referenced Document(s)**  
List the name(s) of the Acts, circular letters, bulletins, or sections that are directly relevant to the question.

**Explanation**  
Explain the answer clearly using the context. Focus on what the rule means, why it matters, and how it applies in practice.

---
Legal Context:
\"\"\"{context}\"\"\"

Question: {question}

Answer (cite only what's present in context):
"""
    try:
        response = openai.ChatCompletion.create(
            model=model,
            messages=[
                {"role": "system", "content": "You are a trusted legal assistant for BC land surveyors."},
                {"role": "user", "content": prompt}
            ],
            temperature=0.3,
            max_tokens=600
        )

        disclaimer = (
            "\n\n\n**Disclaimer:** This response is for informational and educational purposes only. "
            "It does not constitute legal advice and should not be used as a substitute for consulting the applicable legislation, "
            "Surveyor General’s office, or the Association of British Columbia Land Surveyors (ABCLS). "
            "Always refer to official sources for legal or professional decisions."
        )

        return response['choices'][0]['message']['content'].strip() + disclaimer

    except Exception as e:
        return f"[!] LLM Error: {e}"