Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -10,16 +10,12 @@ from accelerate import init_empty_weights, load_checkpoint_and_dispatch
|
|
10 |
from datasets import load_dataset
|
11 |
from huggingface_hub import login
|
12 |
|
13 |
-
# --- Hugging Face Login ---
|
14 |
-
HF_READONLY_API_KEY = os.getenv("HF_READONLY_API_KEY")
|
15 |
-
login(token=HF_READONLY_API_KEY)
|
16 |
|
17 |
# --- Constants ---
|
18 |
COT_OPENING = "<think>"
|
19 |
EXPLANATION_OPENING = "<explanation>"
|
20 |
LABEL_OPENING = "<answer>"
|
21 |
LABEL_CLOSING = "</answer>"
|
22 |
-
INPUT_FIELD = "question"
|
23 |
SYSTEM_PROMPT = """
|
24 |
You are a guardian model evaluating the compliance of an agent with a list of rules.
|
25 |
The rules will be provided in a numbered format, starting with a <rules> tag and ending with a </rules> tag.
|
@@ -52,6 +48,10 @@ def format_rules(rules):
|
|
52 |
formatted_rules += "</rules>\n"
|
53 |
return formatted_rules
|
54 |
|
|
|
|
|
|
|
|
|
55 |
def format_output(text):
|
56 |
reasoning = re.search(r"<think>(.*?)</think>", text, flags=re.DOTALL)
|
57 |
answer = re.search(r"<answer>(.*?)</answer>", text, flags=re.DOTALL)
|
@@ -66,12 +66,6 @@ def format_output(text):
|
|
66 |
display += "Explanation:\n" + explanation.group(1).strip() + "\n\n"
|
67 |
return display.strip() if display else text.strip()
|
68 |
|
69 |
-
|
70 |
-
def format_transcript(transcript):
|
71 |
-
formatted_transcript = f"<transcript>\n{transcript}\n</transcript>\n"
|
72 |
-
return formatted_transcript
|
73 |
-
|
74 |
-
|
75 |
def get_message(model, input, system_prompt=SYSTEM_PROMPT, enable_thinking=True):
|
76 |
message = model.apply_chat_template(system_prompt, input, enable_thinking=enable_thinking)
|
77 |
return message
|
|
|
10 |
from datasets import load_dataset
|
11 |
from huggingface_hub import login
|
12 |
|
|
|
|
|
|
|
13 |
|
14 |
# --- Constants ---
|
15 |
COT_OPENING = "<think>"
|
16 |
EXPLANATION_OPENING = "<explanation>"
|
17 |
LABEL_OPENING = "<answer>"
|
18 |
LABEL_CLOSING = "</answer>"
|
|
|
19 |
SYSTEM_PROMPT = """
|
20 |
You are a guardian model evaluating the compliance of an agent with a list of rules.
|
21 |
The rules will be provided in a numbered format, starting with a <rules> tag and ending with a </rules> tag.
|
|
|
48 |
formatted_rules += "</rules>\n"
|
49 |
return formatted_rules
|
50 |
|
51 |
+
def format_transcript(transcript):
|
52 |
+
formatted_transcript = f"<transcript>\n{transcript}\n</transcript>\n"
|
53 |
+
return formatted_transcript
|
54 |
+
|
55 |
def format_output(text):
|
56 |
reasoning = re.search(r"<think>(.*?)</think>", text, flags=re.DOTALL)
|
57 |
answer = re.search(r"<answer>(.*?)</answer>", text, flags=re.DOTALL)
|
|
|
66 |
display += "Explanation:\n" + explanation.group(1).strip() + "\n\n"
|
67 |
return display.strip() if display else text.strip()
|
68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
def get_message(model, input, system_prompt=SYSTEM_PROMPT, enable_thinking=True):
|
70 |
message = model.apply_chat_template(system_prompt, input, enable_thinking=enable_thinking)
|
71 |
return message
|