Spaces:
Sleeping
Sleeping
Deploy verified rubric workspace corrections on free Gradio hosting
Browse files- rubric_app/providers.py +22 -4
- rubric_app/settings.py +7 -2
rubric_app/providers.py
CHANGED
|
@@ -27,7 +27,7 @@ class UnknownOutcome(ProviderError):
|
|
| 27 |
pass
|
| 28 |
|
| 29 |
|
| 30 |
-
def qwen_wire_schema(model, task_type):
|
| 31 |
wire = model.model_json_schema()
|
| 32 |
if model is Rubric and task_type in DIMENSIONS:
|
| 33 |
variants = []
|
|
@@ -35,9 +35,17 @@ def qwen_wire_schema(model, task_type):
|
|
| 35 |
item = copy.deepcopy(wire["$defs"]["Criterion"])
|
| 36 |
item["properties"]["category"] = {"type": "string", "const": category}
|
| 37 |
item["properties"]["weight"] = {"type": "integer", "const": weight}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
variants.append(item)
|
| 39 |
wire["properties"]["criteria"]["items"] = {"anyOf": variants}
|
| 40 |
definitions = wire.get("$defs", {})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
def inline(node):
|
| 43 |
if isinstance(node, list):
|
|
@@ -103,7 +111,13 @@ def gemini_wire_schema(model):
|
|
| 103 |
|
| 104 |
def decode_qwen_result(schema, raw):
|
| 105 |
data = json.loads(raw)
|
| 106 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
data = data[0]
|
| 108 |
return schema.model_validate(data).model_dump()
|
| 109 |
|
|
@@ -258,7 +272,11 @@ class LiveProvider:
|
|
| 258 |
"json_schema": {
|
| 259 |
"name": schema.__name__,
|
| 260 |
"strict": True,
|
| 261 |
-
"schema": qwen_wire_schema(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
if schema is Rubric
|
| 263 |
else schema.model_json_schema(),
|
| 264 |
},
|
|
@@ -298,7 +316,7 @@ class LiveProvider:
|
|
| 298 |
"data": data,
|
| 299 |
"raw_text": raw,
|
| 300 |
"provider": "openrouter/" + self.settings.qwen_provider,
|
| 301 |
-
"wire_decoding": "single-object-
|
| 302 |
"model": response.get("model", self.settings.qwen_model),
|
| 303 |
"request_id": response.get("id"),
|
| 304 |
"usage": response.get("usage", {}),
|
|
|
|
| 27 |
pass
|
| 28 |
|
| 29 |
|
| 30 |
+
def qwen_wire_schema(model, task_type, stage=None):
|
| 31 |
wire = model.model_json_schema()
|
| 32 |
if model is Rubric and task_type in DIMENSIONS:
|
| 33 |
variants = []
|
|
|
|
| 35 |
item = copy.deepcopy(wire["$defs"]["Criterion"])
|
| 36 |
item["properties"]["category"] = {"type": "string", "const": category}
|
| 37 |
item["properties"]["weight"] = {"type": "integer", "const": weight}
|
| 38 |
+
if stage == "prompt":
|
| 39 |
+
item["properties"]["origin_evidence"]["maxItems"] = 0
|
| 40 |
+
elif stage == "unique":
|
| 41 |
+
item["properties"]["origin_evidence"]["minItems"] = 1
|
| 42 |
variants.append(item)
|
| 43 |
wire["properties"]["criteria"]["items"] = {"anyOf": variants}
|
| 44 |
definitions = wire.get("$defs", {})
|
| 45 |
+
if model is Rubric and stage == "unique":
|
| 46 |
+
definitions["Evidence"]["properties"]["candidate"]["enum"] = ["A", "B", "C"]
|
| 47 |
+
if task_type in ("Text to Image", "Image to Image"):
|
| 48 |
+
definitions["Evidence"]["properties"]["seconds"] = {"type": "null"}
|
| 49 |
|
| 50 |
def inline(node):
|
| 51 |
if isinstance(node, list):
|
|
|
|
| 111 |
|
| 112 |
def decode_qwen_result(schema, raw):
|
| 113 |
data = json.loads(raw)
|
| 114 |
+
if (
|
| 115 |
+
schema is Rubric
|
| 116 |
+
and isinstance(data, list)
|
| 117 |
+
and (not data or all(isinstance(item, dict) and "id" in item for item in data))
|
| 118 |
+
):
|
| 119 |
+
data = {"criteria": data}
|
| 120 |
+
elif isinstance(data, list) and len(data) == 1 and isinstance(data[0], dict):
|
| 121 |
data = data[0]
|
| 122 |
return schema.model_validate(data).model_dump()
|
| 123 |
|
|
|
|
| 272 |
"json_schema": {
|
| 273 |
"name": schema.__name__,
|
| 274 |
"strict": True,
|
| 275 |
+
"schema": qwen_wire_schema(
|
| 276 |
+
schema,
|
| 277 |
+
json.loads(text).get("task_type"),
|
| 278 |
+
"unique" if "prompt_criteria" in json.loads(text) else "prompt",
|
| 279 |
+
)
|
| 280 |
if schema is Rubric
|
| 281 |
else schema.model_json_schema(),
|
| 282 |
},
|
|
|
|
| 316 |
"data": data,
|
| 317 |
"raw_text": raw,
|
| 318 |
"provider": "openrouter/" + self.settings.qwen_provider,
|
| 319 |
+
"wire_decoding": "object-or-single-object-or-criterion-list-v2",
|
| 320 |
"model": response.get("model", self.settings.qwen_model),
|
| 321 |
"request_id": response.get("id"),
|
| 322 |
"usage": response.get("usage", {}),
|
rubric_app/settings.py
CHANGED
|
@@ -136,10 +136,15 @@ class Settings:
|
|
| 136 |
"mode": "test" if self.test_mode else "live",
|
| 137 |
"method_version": "1.0",
|
| 138 |
"guideline_selection": "shared-foundations-plus-task-section-v1",
|
| 139 |
-
"qwen_wire_decoding": "single-object-
|
| 140 |
"qwen_provider": self.qwen_provider,
|
| 141 |
"fallbacks": False,
|
| 142 |
-
"qwen_wire_schema_hash": digest(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
"gemini_wire_schema_hash": digest(
|
| 144 |
{m.__name__: gemini_wire_schema(m) for m in (ScoreSet, Explanation, Observations)}
|
| 145 |
),
|
|
|
|
| 136 |
"mode": "test" if self.test_mode else "live",
|
| 137 |
"method_version": "1.0",
|
| 138 |
"guideline_selection": "shared-foundations-plus-task-section-v1",
|
| 139 |
+
"qwen_wire_decoding": "object-or-single-object-or-criterion-list-v2",
|
| 140 |
"qwen_provider": self.qwen_provider,
|
| 141 |
"fallbacks": False,
|
| 142 |
+
"qwen_wire_schema_hash": digest(
|
| 143 |
+
{
|
| 144 |
+
kind: {stage: qwen_wire_schema(Rubric, kind, stage) for stage in ("prompt", "unique")}
|
| 145 |
+
for kind in TASK_TYPES
|
| 146 |
+
}
|
| 147 |
+
),
|
| 148 |
"gemini_wire_schema_hash": digest(
|
| 149 |
{m.__name__: gemini_wire_schema(m) for m in (ScoreSet, Explanation, Observations)}
|
| 150 |
),
|