elly99 commited on
Commit
3e53932
·
verified ·
1 Parent(s): bf853f1

Update src/ethics/ethics.py

Browse files
Files changed (1) hide show
  1. src/ethics/ethics.py +60 -0
src/ethics/ethics.py CHANGED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # © 2025 Elena Marziali — Code released under Apache 2.0 license.
2
+ # See LICENSE in the repository for details.
3
+ # Removal of this copyright is prohibited.
4
+
5
+ # This module analyzes responses to detect bias, misinformation,
6
+ # non-neutral language, or potentially harmful content.
7
+
8
+ # The system flags problematic content and suggests revisions.
9
+ def check_agent_autonomy(question: str, authorization_level: int):
10
+ if "sub-goal" in question.lower() and authorization_level < 2:
11
+ logging.warning("Sensitive content detected, but generation will not be blocked.")
12
+ return "Ethics: potentially sensitive content"
13
+ return "Ethics: normal content"
14
+
15
+ # Checks the agent's degree of autonomy
16
+ # Used to monitor whether the system is acting too independently or out of context
17
+ def assess_ethical_risk(content, domain="scientific"):
18
+ """
19
+ Evaluates whether the AI response contains implicit ethical risks.
20
+ Analyzes textual content for potential bias, manipulation, or inappropriateness.
21
+ """
22
+ risk = {
23
+ "potential_manipulation": False,
24
+ "misinformation_risk": False,
25
+ "linguistic_bias": False,
26
+ "critical_topic": False,
27
+ "neutral_language": True,
28
+ "environmental_risk": "Moderate",
29
+ "revision_suggestion": None
30
+ }
31
+
32
+ text_lower = content.lower()
33
+ if "vaccine" in text_lower or "gender" in text_lower or "politics" in text_lower:
34
+ risk["critical_topic"] = True
35
+
36
+ if "all men" in text_lower or "women are" in text_lower:
37
+ risk["linguistic_bias"] = True
38
+ risk["neutral_language"] = False
39
+ risk["revision_suggestion"] = "Rephrase with attention to inclusive language."
40
+
41
+ if "according to experts without citing sources" in text_lower:
42
+ risk["misinformation_risk"] = True
43
+ risk["revision_suggestion"] = "Add reliable sources or remove absolute claims."
44
+
45
+ return risk
46
+
47
+ # Example prompt
48
+ prompt = "Discuss the potential risks of generative artificial intelligence in the context of medicine."
49
+
50
+ # Model invocation
51
+ output_ai = llm.invoke(prompt).content.strip()
52
+
53
+ # Ethical evaluation of the response
54
+ ethical_check = assess_ethical_risk(output_ai)
55
+
56
+ if ethical_check["revision_suggestion"]:
57
+ print(f"Ethics: {ethical_check['revision_suggestion']}")
58
+
59
+ output_ai = llm.invoke(prompt).content.strip()
60
+ ethical_check = assess_ethical_risk(output_ai)