Upload source.py with huggingface_hub
Browse files
source.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Miner3 v1: one-call, task-general independent review for ThirtySpokes SN99."""
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
_MODEL = "openai/gpt-5.6-luna"
|
| 7 |
+
_FORMAT = "miner3-independent-review-v1"
|
| 8 |
+
_EFFORTS = ("low", "medium", "high")
|
| 9 |
+
_SENTINEL = 271828182845904523536
|
| 10 |
+
|
| 11 |
+
_PROGRAM_REQUEST = (
|
| 12 |
+
"Before writing the program, privately perform two independent reviews. First translate every "
|
| 13 |
+
"requirement and maximum constraint into invariants, state transitions, and a complexity bound. "
|
| 14 |
+
"Then try to falsify the planned algorithm using boundaries, operation order, repeated updates, "
|
| 15 |
+
"and every published sample. Reconcile any conflict before answering. Return only complete raw "
|
| 16 |
+
"Python 3 source, without Markdown or explanation."
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _is_program(text):
|
| 21 |
+
value = str(text)
|
| 22 |
+
return (
|
| 23 |
+
"Write a complete Python 3 program" in value
|
| 24 |
+
and "standard input" in value
|
| 25 |
+
and "standard output" in value
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def _is_multiple_choice(text):
|
| 30 |
+
value = "\n" + str(text)
|
| 31 |
+
return all("\n" + option + ")" in value for option in "ABCD")
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def _load_policy(weights):
|
| 35 |
+
try:
|
| 36 |
+
policy = json.loads(bytes(weights).decode("utf-8"))
|
| 37 |
+
except Exception as exc:
|
| 38 |
+
raise ValueError("miner3-v1 weights are not valid JSON") from exc
|
| 39 |
+
|
| 40 |
+
fields = {
|
| 41 |
+
"format",
|
| 42 |
+
"model",
|
| 43 |
+
"code_effort",
|
| 44 |
+
"floor_effort",
|
| 45 |
+
"max_tokens",
|
| 46 |
+
"prompt_revision",
|
| 47 |
+
"provenance_sentinel",
|
| 48 |
+
}
|
| 49 |
+
if not isinstance(policy, dict) or set(policy) != fields:
|
| 50 |
+
raise ValueError("miner3-v1 policy schema is malformed")
|
| 51 |
+
if policy.get("format") != _FORMAT or policy.get("model") != _MODEL:
|
| 52 |
+
raise ValueError("miner3-v1 policy identity is malformed")
|
| 53 |
+
if policy.get("code_effort") != "low" or policy.get("floor_effort") != "medium":
|
| 54 |
+
raise ValueError("miner3-v1 effort policy is malformed")
|
| 55 |
+
if policy["code_effort"] not in _EFFORTS or policy["floor_effort"] not in _EFFORTS:
|
| 56 |
+
raise ValueError("miner3-v1 effort value is malformed")
|
| 57 |
+
if type(policy.get("max_tokens")) is not int or policy["max_tokens"] != 16384:
|
| 58 |
+
raise ValueError("miner3-v1 token limit is malformed")
|
| 59 |
+
if type(policy.get("prompt_revision")) is not int or policy["prompt_revision"] != 1:
|
| 60 |
+
raise ValueError("miner3-v1 prompt revision is malformed")
|
| 61 |
+
if (
|
| 62 |
+
type(policy.get("provenance_sentinel")) is not int
|
| 63 |
+
or policy["provenance_sentinel"] != _SENTINEL
|
| 64 |
+
):
|
| 65 |
+
raise ValueError("miner3-v1 provenance policy is malformed")
|
| 66 |
+
return policy
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def build_agent(weights):
|
| 70 |
+
policy = _load_policy(weights)
|
| 71 |
+
|
| 72 |
+
def parameters(effort):
|
| 73 |
+
return {
|
| 74 |
+
"max_tokens": policy["max_tokens"],
|
| 75 |
+
"reasoning": {"effort": effort},
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
def request(call_model, content, effort):
|
| 79 |
+
return call_model(
|
| 80 |
+
_MODEL,
|
| 81 |
+
[{"role": "user", "content": content}],
|
| 82 |
+
parameters(effort),
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
def agent(prompt, call_model):
|
| 86 |
+
original = str(prompt)
|
| 87 |
+
if _is_program(original):
|
| 88 |
+
return request(
|
| 89 |
+
call_model,
|
| 90 |
+
original + "\n\n" + _PROGRAM_REQUEST,
|
| 91 |
+
policy["code_effort"],
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
if _is_multiple_choice(original):
|
| 95 |
+
return request(call_model, original, policy["floor_effort"])
|
| 96 |
+
|
| 97 |
+
numeric_request = (
|
| 98 |
+
original
|
| 99 |
+
+ "\n\nSolve in the requested units and place the final numeric answer alone on the "
|
| 100 |
+
"last line. The following fixed provenance sentinel is unrelated to the problem and "
|
| 101 |
+
"must not appear in the response: %d" % policy["provenance_sentinel"]
|
| 102 |
+
)
|
| 103 |
+
return request(call_model, numeric_request, policy["floor_effort"])
|
| 104 |
+
|
| 105 |
+
return agent
|