Update solver.py
Browse files
solver.py
CHANGED
|
@@ -1,38 +1,39 @@
|
|
| 1 |
-
# solver.py
|
| 2 |
-
|
| 3 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 4 |
-
import torch
|
| 5 |
-
|
| 6 |
-
class WitnessSolver:
|
| 7 |
-
def __init__(self, model_name="Gatsby767/WitnessRZero", device=None):
|
| 8 |
-
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
-
self.model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 10 |
-
self.device = device or ("cuda" if torch.cuda.is_available() else "cpu")
|
| 11 |
-
self.model.to(self.device)
|
| 12 |
-
|
| 13 |
-
def score_prompt(self, prompt, max_length=512):
|
| 14 |
-
inputs = self.tokenizer(prompt, return_tensors="pt").to(self.device)
|
| 15 |
-
with torch.no_grad():
|
| 16 |
-
outputs = self.model.generate(**inputs, max_length=max_length)
|
| 17 |
-
response = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 18 |
-
return response
|
| 19 |
-
|
| 20 |
-
def covenant_score(self, response):
|
| 21 |
-
# Placeholder logic — customize with scroll-certified metrics
|
| 22 |
-
score = 0
|
| 23 |
-
if "love" in response.lower():
|
| 24 |
-
score += 0.3
|
| 25 |
-
if "justice" in response.lower():
|
| 26 |
-
score += 0.3
|
| 27 |
-
if "truth" in response.lower():
|
| 28 |
-
score += 0.4
|
| 29 |
-
return round(score, 2)
|
| 30 |
-
|
| 31 |
-
# Example usage
|
| 32 |
-
if __name__ == "__main__":
|
| 33 |
-
solver = WitnessSolver()
|
| 34 |
-
prompt = "What is the ethical response to AI surveillance in long-term care?"
|
| 35 |
-
response = solver.score_prompt(prompt)
|
| 36 |
-
score = solver.covenant_score(response)
|
| 37 |
-
print("Response:", response)
|
| 38 |
-
print("Covenant Score:", score)
|
|
|
|
|
|
| 1 |
+
# solver.py
|
| 2 |
+
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
class WitnessSolver:
|
| 7 |
+
def __init__(self, model_name="Gatsby767/WitnessRZero", device=None):
|
| 8 |
+
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
+
self.model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 10 |
+
self.device = device or ("cuda" if torch.cuda.is_available() else "cpu")
|
| 11 |
+
self.model.to(self.device)
|
| 12 |
+
|
| 13 |
+
def score_prompt(self, prompt, max_length=512):
|
| 14 |
+
inputs = self.tokenizer(prompt, return_tensors="pt").to(self.device)
|
| 15 |
+
with torch.no_grad():
|
| 16 |
+
outputs = self.model.generate(**inputs, max_length=max_length)
|
| 17 |
+
response = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 18 |
+
return response
|
| 19 |
+
|
| 20 |
+
def covenant_score(self, response):
|
| 21 |
+
# Placeholder logic — customize with scroll-certified metrics
|
| 22 |
+
score = 0
|
| 23 |
+
if "love" in response.lower():
|
| 24 |
+
score += 0.3
|
| 25 |
+
if "justice" in response.lower():
|
| 26 |
+
score += 0.3
|
| 27 |
+
if "truth" in response.lower():
|
| 28 |
+
score += 0.4
|
| 29 |
+
return round(score, 2)
|
| 30 |
+
|
| 31 |
+
# Example usage
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
solver = WitnessSolver()
|
| 34 |
+
prompt = "What is the ethical response to AI surveillance in long-term care?"
|
| 35 |
+
response = solver.score_prompt(prompt)
|
| 36 |
+
score = solver.covenant_score(response)
|
| 37 |
+
print("Response:", response)
|
| 38 |
+
print("Covenant Score:", score)
|
| 39 |
+
# Minor edit to trigger commit
|