JARVISXIRONMAN commited on
Commit
e4bb40c
·
verified ·
1 Parent(s): 1d71e84

Create agents/risk_agent.py

Browse files
Files changed (1) hide show
  1. agents/risk_agent.py +43 -0
agents/risk_agent.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # agents/risk_agent.py
2
+
3
+ import os
4
+ from openai import OpenAI
5
+ from dotenv import load_dotenv
6
+
7
+ # Load .env variables
8
+ load_dotenv()
9
+
10
+ # Initialize Groq LLM client
11
+ client = OpenAI(
12
+ base_url=os.getenv("GROQ_BASE_URL"),
13
+ api_key=os.getenv("GROQ_API_KEY")
14
+ )
15
+
16
+ def detect_risks(clause_text):
17
+ prompt = f"""
18
+ You are a legal assistant and compliance risk advisor.
19
+
20
+ Your task is to carefully review the following legal clause and identify any possible legal risks, ambiguities, or problematic conditions.
21
+
22
+ Clause:
23
+ {clause_text}
24
+
25
+ Respond in this format:
26
+
27
+ 1. ⚠ Risk(s) or ambiguity in English
28
+ 2. ⚠ اردو میں قانونی خطرے کی مختصر وضاحت
29
+ """
30
+
31
+ response = client.chat.completions.create(
32
+ model="llama3-70b-8192",
33
+ messages=[{"role": "user", "content": prompt}],
34
+ temperature=0.5,
35
+ )
36
+
37
+ return response.choices[0].message.content
38
+
39
+
40
+ # Run standalone for testing
41
+ if __name__ == "__main__":
42
+ clause = "شق 5: مالک مکان کرایہ بغیر اطلاع کے کسی بھی وقت بڑھا سکتا ہے۔"
43
+ print(detect_risks(clause))