forked from williambrach/llm-plagiarism-check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
71 lines (57 loc) · 2.53 KB
/
models.py
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
import dspy
import requests
import json
class Signature(dspy.Signature):
"""Detect if two code samples are plagiarized. In plagiarized field answer only : Yes if the code samples are plagiarized, No otherwise. In explenation field add the reason why the code samples are/ are not plagiarized."""
code_sample_1 = dspy.InputField(desc="The first code sample to compare")
code_sample_2 = dspy.InputField(desc="The second code sample to compare")
explanation = dspy.OutputField(
desc="Explanation or reason why the code samples are/ are not plagiarized"
)
plagiarized = dspy.OutputField(
desc="Yes/No indicating if code samples are plagiarized"
)
class CoT(dspy.Module):
def __init__(self) -> None:
super().__init__()
self.prog = dspy.ChainOfThought(Signature)
def forward(self, code_sample_1: str, code_sample_2: str) -> Signature:
return self.prog(code_sample_1=code_sample_1, code_sample_2=code_sample_2)
def stop_model(
model: str,
url: str,
prompt: str = "STOP! Hammer time",
keep_alive: int = 0,
stream: bool = False,
) -> bool:
if "ollama" in model:
model = "-".join(model.split("-")[1:])
url = url + "/api/generate"
payload = {
"model": model,
"prompt": prompt,
"keep_alive": keep_alive,
"stream": stream,
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, data=json.dumps(payload), headers=headers)
if response.status_code == 200:
return True
else:
raise Exception(f"Failed to stop model: {response.text}")
class SignatureOld(dspy.Signature):
"""Detect if two code samples are plagiarized. In plagiarized field answer only : Yes if the code samples are plagiarized, No otherwise. In explenation field add the reason why the code samples are/ are not plagiarized."""
code_sample_1 = dspy.InputField(desc="The first code sample to compare")
code_sample_2 = dspy.InputField(desc="The second code sample to compare")
explanation = dspy.OutputField(
desc="Explanation or reason why the code samples are/ are not plagiarized"
)
plagiarized = dspy.OutputField(
desc="Yes/No indicating if code samples are plagiarized"
)
class CoT_Old(dspy.Module):
def __init__(self) -> None:
super().__init__()
self.prog = dspy.ChainOfThought(SignatureOld)
def forward(self, code_sample_1: str, code_sample_2: str) -> SignatureOld:
return self.prog(code_sample_1=code_sample_1, code_sample_2=code_sample_2)